@ -18,6 +18,7 @@ defmodule Explorer.ChainTest do
Hash ,
InternalTransaction ,
Log ,
PendingBlockOperation ,
Token ,
TokenTransfer ,
Transaction ,
@ -35,6 +36,38 @@ defmodule Explorer.ChainTest do
setup :verify_on_exit!
describe " remove_nonconsensus_blocks_from_pending_ops/0 " do
test " removes pending ops for nonconsensus blocks " do
block = insert ( :block )
insert ( :pending_block_operation , block : block , fetch_internal_transactions : true )
nonconsensus_block = insert ( :block , consensus : false )
insert ( :pending_block_operation , block : nonconsensus_block , fetch_internal_transactions : true )
:ok = Chain . remove_nonconsensus_blocks_from_pending_ops ( )
assert Repo . get ( PendingBlockOperation , block . hash )
assert is_nil ( Repo . get ( PendingBlockOperation , nonconsensus_block . hash ) )
end
test " removes pending ops for nonconsensus blocks by block hashes " do
block = insert ( :block )
insert ( :pending_block_operation , block : block , fetch_internal_transactions : true )
nonconsensus_block = insert ( :block , consensus : false )
insert ( :pending_block_operation , block : nonconsensus_block , fetch_internal_transactions : true )
nonconsensus_block1 = insert ( :block , consensus : false )
insert ( :pending_block_operation , block : nonconsensus_block1 , fetch_internal_transactions : true )
:ok = Chain . remove_nonconsensus_blocks_from_pending_ops ( [ nonconsensus_block1 . hash ] )
assert Repo . get ( PendingBlockOperation , block . hash )
assert Repo . get ( PendingBlockOperation , nonconsensus_block . hash )
assert is_nil ( Repo . get ( PendingBlockOperation , nonconsensus_block1 . hash ) )
end
end
describe " count_addresses_with_balance_from_cache/0 " do
test " returns the number of addresses with fetched_coin_balance > 0 " do
insert ( :address , fetched_coin_balance : 0 )
@ -220,14 +253,26 @@ defmodule Explorer.ChainTest do
|> insert ( to_address : address )
|> with_block ( )
insert ( :log , transaction : transaction1 , index : 1 , address : address )
insert ( :log ,
block : transaction1 . block ,
block_number : transaction1 . block_number ,
transaction : transaction1 ,
index : 1 ,
address : address
)
transaction2 =
:transaction
|> insert ( from_address : address )
|> with_block ( )
insert ( :log , transaction : transaction2 , index : 2 , address : address )
insert ( :log ,
block : transaction2 . block ,
block_number : transaction2 . block_number ,
transaction : transaction2 ,
index : 2 ,
address : address
)
assert Enum . count ( Chain . address_to_logs ( address_hash ) ) == 2
end
@ -240,10 +285,18 @@ defmodule Explorer.ChainTest do
|> insert ( to_address : address )
|> with_block ( )
log1 = insert ( :log , transaction : transaction , index : 1 , address : address )
log1 = insert ( :log , transaction : transaction , index : 1 , address : address , block_number : transaction . block_number )
2 . . 51
|> Enum . map ( fn index -> insert ( :log , transaction : transaction , index : index , address : address ) end )
|> Enum . map ( fn index ->
insert ( :log ,
block : transaction . block ,
transaction : transaction ,
index : index ,
address : address ,
block_number : transaction . block_number
)
end )
|> Enum . map ( & &1 . index )
paging_options1 = % PagingOptions { page_size : 1 }
@ -263,14 +316,27 @@ defmodule Explorer.ChainTest do
|> insert ( to_address : address )
|> with_block ( )
insert ( :log , transaction : transaction1 , index : 1 , address : address )
insert ( :log ,
block : transaction1 . block ,
transaction : transaction1 ,
index : 1 ,
address : address ,
block_number : transaction1 . block_number
)
transaction2 =
:transaction
|> insert ( from_address : address )
|> with_block ( )
insert ( :log , transaction : transaction2 , index : 2 , address : address , first_topic : " test " )
insert ( :log ,
block : transaction2 . block ,
transaction : transaction2 ,
index : 2 ,
address : address ,
first_topic : " test " ,
block_number : transaction2 . block_number
)
[ found_log ] = Chain . address_to_logs ( address_hash , topic : " test " )
@ -285,14 +351,27 @@ defmodule Explorer.ChainTest do
|> insert ( to_address : address )
|> with_block ( )
insert ( :log , transaction : transaction1 , index : 1 , address : address , fourth_topic : " test " )
insert ( :log ,
block : transaction1 . block ,
block_number : transaction1 . block_number ,
transaction : transaction1 ,
index : 1 ,
address : address ,
fourth_topic : " test "
)
transaction2 =
:transaction
|> insert ( from_address : address )
|> with_block ( )
insert ( :log , transaction : transaction2 , index : 2 , address : address )
insert ( :log ,
block : transaction2 . block ,
block_number : transaction2 . block . number ,
transaction : transaction2 ,
index : 2 ,
address : address
)
[ found_log ] = Chain . address_to_logs ( address_hash , topic : " test " )
@ -393,6 +472,8 @@ defmodule Explorer.ChainTest do
transaction : transaction ,
index : 0 ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 0 ,
transaction_index : transaction . index
)
@ -835,7 +916,7 @@ defmodule Explorer.ChainTest do
:transaction
|> insert ( )
|> with_block ( block , internal_transactions_indexed_at : DateTime . utc_now ( ) )
|> with_block ( block )
assert Chain . finished_indexing? ( )
end
@ -851,6 +932,8 @@ defmodule Explorer.ChainTest do
|> insert ( )
|> with_block ( block )
insert ( :pending_block_operation , block : block , fetch_internal_transactions : true )
refute Chain . finished_indexing? ( )
end
end
@ -948,6 +1031,8 @@ defmodule Explorer.ChainTest do
transaction : transaction ,
index : 0 ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 0 ,
transaction_index : transaction . index
)
@ -956,6 +1041,8 @@ defmodule Explorer.ChainTest do
transaction : transaction ,
index : index ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : index ,
transaction_index : transaction . index
)
end )
@ -1310,11 +1397,13 @@ defmodule Explorer.ChainTest do
output : " 0x " ,
value : 0
}
]
] ,
with : :blockless_changeset
} ,
logs : %{
params : [
%{
block_hash : " 0xf6b4b8c88df3ebd252ec476328334dc026cf66606a84fb769b3d3cbccc8471bd " ,
address_hash : " 0x8bf38d4764929064f2d4d3a56520a76ab3df415b " ,
data : " 0x0000000000000000000000000000000000000000000000000de0b6b3a7640000 " ,
first_topic : " 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef " ,
@ -1372,6 +1461,7 @@ defmodule Explorer.ChainTest do
token_transfers : %{
params : [
%{
block_hash : " 0xf6b4b8c88df3ebd252ec476328334dc026cf66606a84fb769b3d3cbccc8471bd " ,
amount : Decimal . new ( 1_000_000_000_000_000_000 ) ,
block_number : 37 ,
log_index : 0 ,
@ -1521,9 +1611,7 @@ defmodule Explorer.ChainTest do
bytes :
<< 83 , 189 , 136 , 72 , 114 , 222 , 62 , 72 , 134 , 146 , 136 , 27 , 174 , 236 , 38 , 46 , 123 , 149 , 35 , 77 , 57 ,
101 , 36 , 140 , 57 , 254 , 153 , 47 , 255 , 212 , 51 , 229 >>
} ,
# because there are successful, non-contract-creation token transfer
internal_transactions_indexed_at : % DateTime { }
}
}
] ,
tokens : [
@ -1797,6 +1885,8 @@ defmodule Explorer.ChainTest do
transaction : transaction ,
to_address : address ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 1 ,
transaction_index : transaction . index
)
@ -1806,6 +1896,8 @@ defmodule Explorer.ChainTest do
transaction : transaction ,
to_address : address ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 2 ,
transaction_index : transaction . index
)
@ -1832,6 +1924,8 @@ defmodule Explorer.ChainTest do
to_address : address ,
index : 0 ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 0 ,
transaction_index : transaction . index
)
@ -1840,6 +1934,8 @@ defmodule Explorer.ChainTest do
to_address : address ,
index : 1 ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 1 ,
transaction_index : transaction . index
)
@ -1887,6 +1983,8 @@ defmodule Explorer.ChainTest do
to_address : address ,
index : 1 ,
block_number : pending_transaction . block_number ,
block_hash : pending_transaction . block_hash ,
block_index : 1 ,
transaction_index : pending_transaction . index
)
@ -1897,6 +1995,8 @@ defmodule Explorer.ChainTest do
to_address : address ,
index : 2 ,
block_number : pending_transaction . block_number ,
block_hash : pending_transaction . block_hash ,
block_index : 2 ,
transaction_index : pending_transaction . index
)
@ -1914,6 +2014,8 @@ defmodule Explorer.ChainTest do
to_address : address ,
index : 1 ,
block_number : first_a_transaction . block_number ,
block_hash : a_block . hash ,
block_index : 1 ,
transaction_index : first_a_transaction . index
)
@ -1924,6 +2026,8 @@ defmodule Explorer.ChainTest do
to_address : address ,
index : 2 ,
block_number : first_a_transaction . block_number ,
block_hash : a_block . hash ,
block_index : 2 ,
transaction_index : first_a_transaction . index
)
@ -1939,6 +2043,8 @@ defmodule Explorer.ChainTest do
to_address : address ,
index : 1 ,
block_number : second_a_transaction . block_number ,
block_hash : a_block . hash ,
block_index : 4 ,
transaction_index : second_a_transaction . index
)
@ -1949,6 +2055,8 @@ defmodule Explorer.ChainTest do
to_address : address ,
index : 2 ,
block_number : second_a_transaction . block_number ,
block_hash : a_block . hash ,
block_index : 5 ,
transaction_index : second_a_transaction . index
)
@ -1966,6 +2074,8 @@ defmodule Explorer.ChainTest do
to_address : address ,
index : 1 ,
block_number : first_b_transaction . block_number ,
block_hash : b_block . hash ,
block_index : 1 ,
transaction_index : first_b_transaction . index
)
@ -1976,6 +2086,8 @@ defmodule Explorer.ChainTest do
to_address : address ,
index : 2 ,
block_number : first_b_transaction . block_number ,
block_hash : b_block . hash ,
block_index : 2 ,
transaction_index : first_b_transaction . index
)
@ -2001,10 +2113,14 @@ defmodule Explorer.ChainTest do
pending_transaction = insert ( :transaction )
old_block = insert ( :block , consensus : false )
insert (
:internal_transaction ,
transaction : pending_transaction ,
to_address : address ,
block_hash : old_block . hash ,
block_index : 1 ,
index : 1
)
@ -2012,6 +2128,8 @@ defmodule Explorer.ChainTest do
:internal_transaction ,
transaction : pending_transaction ,
to_address : address ,
block_hash : old_block . hash ,
block_index : 2 ,
index : 2
)
@ -2029,6 +2147,8 @@ defmodule Explorer.ChainTest do
to_address : address ,
index : 1 ,
block_number : first_a_transaction . block_number ,
block_hash : a_block . hash ,
block_index : 1 ,
transaction_index : first_a_transaction . index
)
@ -2039,6 +2159,8 @@ defmodule Explorer.ChainTest do
to_address : address ,
index : 2 ,
block_number : first_a_transaction . block_number ,
block_hash : a_block . hash ,
block_index : 2 ,
transaction_index : first_a_transaction . index
)
@ -2054,6 +2176,8 @@ defmodule Explorer.ChainTest do
to_address : address ,
index : 1 ,
block_number : second_a_transaction . block_number ,
block_hash : a_block . hash ,
block_index : 4 ,
transaction_index : second_a_transaction . index
)
@ -2064,6 +2188,8 @@ defmodule Explorer.ChainTest do
to_address : address ,
index : 2 ,
block_number : second_a_transaction . block_number ,
block_hash : a_block . hash ,
block_index : 5 ,
transaction_index : second_a_transaction . index
)
@ -2081,6 +2207,8 @@ defmodule Explorer.ChainTest do
to_address : address ,
index : 1 ,
block_number : first_b_transaction . block_number ,
block_hash : b_block . hash ,
block_index : 1 ,
transaction_index : first_b_transaction . index
)
@ -2091,6 +2219,8 @@ defmodule Explorer.ChainTest do
to_address : address ,
index : 2 ,
block_number : first_b_transaction . block_number ,
block_hash : b_block . hash ,
block_index : 2 ,
transaction_index : first_b_transaction . index
)
@ -2158,6 +2288,8 @@ defmodule Explorer.ChainTest do
to_address : address ,
transaction : transaction ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 0 ,
transaction_index : transaction . index
)
@ -2178,6 +2310,8 @@ defmodule Explorer.ChainTest do
index : 0 ,
from_address : address ,
transaction : transaction ,
block_hash : transaction . block_hash ,
block_index : 0 ,
block_number : transaction . block_number ,
transaction_index : transaction . index
)
@ -2241,6 +2375,8 @@ defmodule Explorer.ChainTest do
transaction : transaction ,
index : 0 ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 0 ,
transaction_index : transaction . index
)
@ -2248,6 +2384,8 @@ defmodule Explorer.ChainTest do
insert ( :internal_transaction ,
transaction : transaction ,
index : 1 ,
block_hash : transaction . block_hash ,
block_index : 1 ,
block_number : transaction . block_number ,
transaction_index : transaction . index
)
@ -2277,6 +2415,8 @@ defmodule Explorer.ChainTest do
transaction : transaction ,
index : 0 ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 0 ,
transaction_index : transaction . index
)
@ -2315,6 +2455,8 @@ defmodule Explorer.ChainTest do
transaction : transaction ,
index : 0 ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 0 ,
transaction_index : transaction . index
)
@ -2334,6 +2476,8 @@ defmodule Explorer.ChainTest do
index : 0 ,
transaction : transaction ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 0 ,
transaction_index : transaction . index
)
@ -2354,6 +2498,8 @@ defmodule Explorer.ChainTest do
transaction : transaction ,
type : :reward ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 0 ,
transaction_index : transaction . index
)
@ -2375,6 +2521,8 @@ defmodule Explorer.ChainTest do
gas : nil ,
type : :selfdestruct ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 0 ,
transaction_index : transaction . index
)
@ -2394,6 +2542,8 @@ defmodule Explorer.ChainTest do
transaction : transaction ,
index : 0 ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 0 ,
transaction_index : transaction . index
)
@ -2402,6 +2552,8 @@ defmodule Explorer.ChainTest do
transaction : transaction ,
index : 1 ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 1 ,
transaction_index : transaction . index
)
@ -2424,6 +2576,8 @@ defmodule Explorer.ChainTest do
transaction : transaction ,
index : 0 ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 0 ,
transaction_index : transaction . index
)
@ -2432,6 +2586,8 @@ defmodule Explorer.ChainTest do
transaction : transaction ,
index : 1 ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 1 ,
transaction_index : transaction . index
)
@ -2465,7 +2621,8 @@ defmodule Explorer.ChainTest do
|> insert ( )
|> with_block ( )
% Log { transaction_hash : transaction_hash , index : index } = insert ( :log , transaction : transaction )
% Log { transaction_hash : transaction_hash , index : index } =
insert ( :log , transaction : transaction , block : transaction . block , block_number : transaction . block_number )
assert [ % Log { transaction_hash : ^ transaction_hash , index : ^ index } ] = Chain . transaction_to_logs ( transaction . hash )
end
@ -2476,11 +2633,24 @@ defmodule Explorer.ChainTest do
|> insert ( )
|> with_block ( )
log = insert ( :log , transaction : transaction , index : 1 )
log =
insert ( :log ,
transaction : transaction ,
index : 1 ,
block : transaction . block ,
block_number : transaction . block_number
)
second_page_indexes =
2 . . 51
|> Enum . map ( fn index -> insert ( :log , transaction : transaction , index : index ) end )
|> Enum . map ( fn index ->
insert ( :log ,
transaction : transaction ,
index : index ,
block : transaction . block ,
block_number : transaction . block_number
)
end )
|> Enum . map ( & &1 . index )
assert second_page_indexes ==
@ -2495,7 +2665,7 @@ defmodule Explorer.ChainTest do
|> insert ( )
|> with_block ( )
insert ( :log , transaction : transaction )
insert ( :log , transaction : transaction , block : transaction . block , block_number : transaction . block_number )
assert [ % Log { address : % Address { } , transaction : % Transaction { } } ] =
Chain . transaction_to_logs (
@ -2529,7 +2699,11 @@ defmodule Explorer.ChainTest do
|> with_block ( )
% TokenTransfer { transaction_hash : transaction_hash , log_index : log_index } =
insert ( :token_transfer , transaction : transaction )
insert ( :token_transfer ,
transaction : transaction ,
block : transaction . block ,
block_number : transaction . block_number
)
assert [ % TokenTransfer { transaction_hash : ^ transaction_hash , log_index : ^ log_index } ] =
Chain . transaction_to_token_transfers ( transaction . hash )
@ -2541,7 +2715,7 @@ defmodule Explorer.ChainTest do
|> insert ( )
|> with_block ( )
insert ( :token_transfer , transaction : transaction )
insert ( :token_transfer , transaction : transaction , block : transaction . block , block_number : transaction . block_number )
assert [ % TokenTransfer { token : % Token { } , transaction : % Transaction { } } ] =
Chain . transaction_to_token_transfers (
@ -2902,6 +3076,8 @@ defmodule Explorer.ChainTest do
created_contract_address : created_contract_address ,
created_contract_code : smart_contract_bytecode ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 0 ,
transaction_index : transaction . index
)
@ -3002,6 +3178,8 @@ defmodule Explorer.ChainTest do
created_contract_address : created_contract_address ,
created_contract_code : smart_contract_bytecode ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 0 ,
transaction_index : transaction . index
)
@ -3208,6 +3386,8 @@ defmodule Explorer.ChainTest do
index : 0 ,
transaction : transaction ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 0 ,
transaction_index : transaction . index
)
@ -3254,6 +3434,8 @@ defmodule Explorer.ChainTest do
index : 0 ,
transaction : transaction ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 0 ,
transaction_index : transaction . index
)
@ -3294,6 +3476,8 @@ defmodule Explorer.ChainTest do
index : 0 ,
transaction : transaction ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 0 ,
transaction_index : transaction . index
)
@ -3363,6 +3547,8 @@ defmodule Explorer.ChainTest do
index : 0 ,
transaction : from_internal_transaction_transaction ,
block_number : from_internal_transaction_transaction . block_number ,
block_hash : from_internal_transaction_transaction . block_hash ,
block_index : 0 ,
transaction_index : from_internal_transaction_transaction . index
)
@ -3381,6 +3567,8 @@ defmodule Explorer.ChainTest do
to_address : miner ,
transaction : to_internal_transaction_transaction ,
block_number : to_internal_transaction_transaction . block_number ,
block_hash : to_internal_transaction_transaction . block_hash ,
block_index : 0 ,
transaction_index : to_internal_transaction_transaction . index
)
@ -3437,6 +3625,8 @@ defmodule Explorer.ChainTest do
index : 0 ,
transaction : from_internal_transaction_transaction ,
block_number : from_internal_transaction_transaction . block_number ,
block_hash : from_internal_transaction_transaction . block_hash ,
block_index : 0 ,
transaction_index : from_internal_transaction_transaction . index
)
@ -3451,6 +3641,8 @@ defmodule Explorer.ChainTest do
index : 0 ,
transaction : to_internal_transaction_transaction ,
block_number : to_internal_transaction_transaction . block_number ,
block_hash : to_internal_transaction_transaction . block_hash ,
block_index : 1 ,
transaction_index : to_internal_transaction_transaction . index
)
@ -4190,6 +4382,8 @@ defmodule Explorer.ChainTest do
index : 0 ,
created_contract_address : created_contract_address ,
block_number : transaction . block_number ,
block_hash : transaction . block_hash ,
block_index : 0 ,
transaction_index : transaction . index ,
input : input
)