@ -70,7 +70,7 @@ defmodule Explorer.ChainTest do
describe " address_to_logs/2 " do
test " fetches logs " do
address = insert ( :address )
% Address { hash : address_hash } = address = insert ( :address )
transaction1 =
:transaction
@ -86,11 +86,11 @@ defmodule Explorer.ChainTest do
insert ( :log , transaction : transaction2 , index : 2 , address : address )
assert Enum . count ( Chain . address_to_logs ( address ) ) == 2
assert Enum . count ( Chain . address_to_logs ( address_hash ) ) == 2
end
test " paginates logs " do
address = insert ( :address )
% Address { hash : address_hash } = address = insert ( :address )
transaction =
:transaction
@ -105,15 +105,15 @@ defmodule Explorer.ChainTest do
paging_options1 = % PagingOptions { page_size : 1 }
[ _log ] = Chain . address_to_logs ( address , paging_options : paging_options1 )
[ _log ] = Chain . address_to_logs ( address_hash , paging_options : paging_options1 )
paging_options2 = % PagingOptions { page_size : 60 , key : { transaction . block_number , transaction . index , log1 . index } }
assert Enum . count ( Chain . address_to_logs ( address , paging_options : paging_options2 ) ) == 50
assert Enum . count ( Chain . address_to_logs ( address_hash , paging_options : paging_options2 ) ) == 50
end
test " searches logs by topic when the first topic matches " do
address = insert ( :address )
% Address { hash : address_hash } = address = insert ( :address )
transaction1 =
:transaction
@ -129,13 +129,13 @@ defmodule Explorer.ChainTest do
insert ( :log , transaction : transaction2 , index : 2 , address : address , first_topic : " test " )
[ found_log ] = Chain . address_to_logs ( address , topic : " test " )
[ found_log ] = Chain . address_to_logs ( address_hash , topic : " test " )
assert found_log . transaction . hash == transaction2 . hash
end
test " searches logs by topic when the fourth topic matches " do
address = insert ( :address )
% Address { hash : address_hash } = address = insert ( :address )
transaction1 =
:transaction
@ -151,7 +151,7 @@ defmodule Explorer.ChainTest do
insert ( :log , transaction : transaction2 , index : 2 , address : address )
[ found_log ] = Chain . address_to_logs ( address , topic : " test " )
[ found_log ] = Chain . address_to_logs ( address_hash , topic : " test " )
assert found_log . transaction . hash == transaction1 . hash
end
@ -159,15 +159,15 @@ defmodule Explorer.ChainTest do
describe " address_to_transactions_with_rewards/2 " do
test " without transactions " do
address = insert ( :address )
% Address { hash : address_hash } = insert ( :address )
assert Repo . aggregate ( Transaction , :count , :hash ) == 0
assert [ ] == Chain . address_to_transactions_with_rewards ( address )
assert [ ] == Chain . address_to_transactions_with_rewards ( address_hash )
end
test " with from transactions " do
address = insert ( :address )
% Address { hash : address_hash } = address = insert ( :address )
transaction =
:transaction
@ -176,12 +176,12 @@ defmodule Explorer.ChainTest do
|> Repo . preload ( :token_transfers )
assert [ transaction ] ==
Chain . address_to_transactions_with_rewards ( address , direction : :from )
Chain . address_to_transactions_with_rewards ( address_hash , direction : :from )
|> Repo . preload ( [ :block , :to_address , :from_address ] )
end
test " with to transactions " do
address = insert ( :address )
% Address { hash : address_hash } = address = insert ( :address )
transaction =
:transaction
@ -190,12 +190,12 @@ defmodule Explorer.ChainTest do
|> Repo . preload ( :token_transfers )
assert [ transaction ] ==
Chain . address_to_transactions_with_rewards ( address , direction : :to )
Chain . address_to_transactions_with_rewards ( address_hash , direction : :to )
|> Repo . preload ( [ :block , :to_address , :from_address ] )
end
test " with to and from transactions and direction: :from " do
address = insert ( :address )
% Address { hash : address_hash } = address = insert ( :address )
transaction =
:transaction
@ -205,12 +205,12 @@ defmodule Explorer.ChainTest do
# only contains "from" transaction
assert [ transaction ] ==
Chain . address_to_transactions_with_rewards ( address , direction : :from )
Chain . address_to_transactions_with_rewards ( address_hash , direction : :from )
|> Repo . preload ( [ :block , :to_address , :from_address ] )
end
test " with to and from transactions and direction: :to " do
address = insert ( :address )
% Address { hash : address_hash } = address = insert ( :address )
transaction =
:transaction
@ -219,12 +219,12 @@ defmodule Explorer.ChainTest do
|> Repo . preload ( :token_transfers )
assert [ transaction ] ==
Chain . address_to_transactions_with_rewards ( address , direction : :to )
Chain . address_to_transactions_with_rewards ( address_hash , direction : :to )
|> Repo . preload ( [ :block , :to_address , :from_address ] )
end
test " with to and from transactions and no :direction option " do
address = insert ( :address )
% Address { hash : address_hash } = address = insert ( :address )
block = insert ( :block )
transaction1 =
@ -240,7 +240,7 @@ defmodule Explorer.ChainTest do
|> Repo . preload ( :token_transfers )
assert [ transaction2 , transaction1 ] ==
Chain . address_to_transactions_with_rewards ( address )
Chain . address_to_transactions_with_rewards ( address_hash )
|> Repo . preload ( [ :block , :to_address , :from_address ] )
end
@ -259,11 +259,11 @@ defmodule Explorer.ChainTest do
transaction_index : transaction . index
)
assert [ ] == Chain . address_to_transactions_with_rewards ( address )
assert [ ] == Chain . address_to_transactions_with_rewards ( address . hash )
end
test " returns transactions that have token transfers for the given to_address " do
address = insert ( :address )
% Address { hash : address_hash } = address = insert ( :address )
transaction =
:transaction
@ -277,12 +277,12 @@ defmodule Explorer.ChainTest do
)
assert [ transaction . hash ] ==
Chain . address_to_transactions_with_rewards ( address )
Chain . address_to_transactions_with_rewards ( address_hash )
|> Enum . map ( & &1 . hash )
end
test " returns just the token transfers related to the given address " do
address = insert ( :address )
% Address { hash : address_hash } = address = insert ( :address )
transaction =
:transaction
@ -303,7 +303,7 @@ defmodule Explorer.ChainTest do
)
transaction =
address
address_hash
|> Chain . address_to_transactions_with_rewards ( )
|> List . first ( )
@ -344,7 +344,7 @@ defmodule Explorer.ChainTest do
)
transaction =
contract_address
contract_address . hash
|> Chain . address_to_transactions_with_rewards ( )
|> List . first ( )
@ -360,7 +360,8 @@ defmodule Explorer.ChainTest do
end
test " returns all token transfers when the given address is the token contract address " do
contract_address = insert ( :address , contract_code : Factory . data ( " contract_code " ) )
% Address { hash : contract_address_hash } =
contract_address = insert ( :address , contract_code : Factory . data ( " contract_code " ) )
transaction =
:transaction
@ -381,7 +382,7 @@ defmodule Explorer.ChainTest do
transaction : transaction
)
transaction = Chain . address_to_transactions_with_rewards ( contract_address ) |> List . first ( )
transaction = Chain . address_to_transactions_with_rewards ( contract_address_hash ) |> List . first ( )
assert Enum . count ( transaction . token_transfers ) == 2
end
@ -427,7 +428,7 @@ defmodule Explorer.ChainTest do
)
transactions_hashes =
paul
paul . hash
|> Chain . address_to_transactions_with_rewards ( )
|> Enum . map ( & &1 . hash )
@ -436,7 +437,7 @@ defmodule Explorer.ChainTest do
end
test " with transactions can be paginated " do
address = insert ( :address )
% Address { hash : address_hash } = address = insert ( :address )
second_page_hashes =
2
@ -450,7 +451,7 @@ defmodule Explorer.ChainTest do
|> with_block ( )
assert second_page_hashes ==
address
address_hash
|> Chain . address_to_transactions_with_rewards (
paging_options : % PagingOptions {
key : { block_number , index } ,
@ -462,7 +463,7 @@ defmodule Explorer.ChainTest do
end
test " returns results in reverse chronological order by block number and transaction index " do
address = insert ( :address )
% Address { hash : address_hash } = address = insert ( :address )
a_block = insert ( :block , number : 6000 )
@ -499,7 +500,7 @@ defmodule Explorer.ChainTest do
|> with_block ( b_block )
result =
address
address_hash
|> Chain . address_to_transactions_with_rewards ( )
|> Enum . map ( & &1 . hash )
@ -525,7 +526,7 @@ defmodule Explorer.ChainTest do
address_type : :emission_funds
)
assert [ { _ , _ } ] = Chain . address_to_transactions_with_rewards ( block . miner )
assert [ { _ , _ } ] = Chain . address_to_transactions_with_rewards ( block . miner . hash )
Application . put_env ( :block_scout_web , BlockScoutWeb.Chain , has_emission_funds : false )
end
@ -554,7 +555,7 @@ defmodule Explorer.ChainTest do
|> with_block ( )
|> Repo . preload ( :token_transfers )
assert [ _ , { _ , _ } ] = Chain . address_to_transactions_with_rewards ( block . miner , direction : :from )
assert [ _ , { _ , _ } ] = Chain . address_to_transactions_with_rewards ( block . miner . hash , direction : :from )
Application . put_env ( :block_scout_web , BlockScoutWeb.Chain , has_emission_funds : false )
end
@ -578,7 +579,7 @@ defmodule Explorer.ChainTest do
address_type : :emission_funds
)
assert [ ] == Chain . address_to_transactions_with_rewards ( block . miner )
assert [ ] == Chain . address_to_transactions_with_rewards ( block . miner . hash )
end
end
@ -590,7 +591,7 @@ defmodule Explorer.ChainTest do
|> insert ( nonce : 100 , from_address : address )
|> with_block ( insert ( :block , number : 1000 ) )
assert Chain . total_transactions_sent_by_address ( address ) == 101
assert Chain . total_transactions_sent_by_address ( address . hash ) == 101
end
test " returns 0 when the address did not send transactions " do
@ -600,7 +601,7 @@ defmodule Explorer.ChainTest do
|> insert ( nonce : 100 , to_address : address )
|> with_block ( insert ( :block , number : 1000 ) )
assert Chain . total_transactions_sent_by_address ( address ) == 0
assert Chain . total_transactions_sent_by_address ( address . hash ) == 0
end
end
@ -707,15 +708,15 @@ defmodule Explorer.ChainTest do
describe " address_to_incoming_transaction_count/1 " do
test " without transactions " do
address = insert ( :address )
% Address { hash : address_hash } = insert ( :address )
assert Chain . address_to_incoming_transaction_count ( address ) == 0
assert Chain . address_to_incoming_transaction_count ( address_hash ) == 0
end
test " with transactions " do
% Transaction { to_address : to_address } = insert ( :transaction )
assert Chain . address_to_incoming_transaction_count ( to_address ) == 1
assert Chain . address_to_incoming_transaction_count ( to_address . hash ) == 1
end
end
@ -1575,20 +1576,20 @@ defmodule Explorer.ChainTest do
describe " get_blocks_validated_by_address/2 " do
test " returns nothing when there are no blocks " do
address = insert ( :address )
% Address { hash : address_hash } = insert ( :address )
assert [ ] = Chain . get_blocks_validated_by_address ( address )
assert [ ] = Chain . get_blocks_validated_by_address ( address_hash )
end
test " returns the blocks validated by a specified address " do
address = insert ( :address )
% Address { hash : address_hash } = address = insert ( :address )
another_address = insert ( :address )
block = insert ( :block , miner : address , miner_hash : address . hash )
insert ( :block , miner : another_address , miner_hash : another_address . hash )
results =
address
address_hash
|> Chain . get_blocks_validated_by_address ( )
|> Enum . map ( & &1 . hash )
@ -1596,20 +1597,20 @@ defmodule Explorer.ChainTest do
end
test " with blocks can be paginated " do
address = insert ( :address )
% Address { hash : address_hash } = address = insert ( :address )
first_page_block = insert ( :block , miner : address , miner_hash : address . hash , number : 0 )
second_page_block = insert ( :block , miner : address , miner_hash : address . hash , number : 2 )
assert [ first_page_block . number ] ==
[ paging_options : % PagingOptions { key : { 1 } , page_size : 1 } ]
|> Chain . get_blocks_validated_by_address ( address )
|> Chain . get_blocks_validated_by_address ( address_hash )
|> Enum . map ( & &1 . number )
|> Enum . reverse ( )
assert [ second_page_block . number ] ==
[ paging_options : % PagingOptions { key : { 3 } , page_size : 1 } ]
|> Chain . get_blocks_validated_by_address ( address )
|> Chain . get_blocks_validated_by_address ( address_hash )
|> Enum . map ( & &1 . number )
|> Enum . reverse ( )
end
@ -1674,7 +1675,7 @@ defmodule Explorer.ChainTest do
)
result =
address
address . hash
|> Chain . address_to_internal_transactions ( )
|> Enum . map ( & { &1 . transaction_hash , &1 . index } )
@ -1683,7 +1684,7 @@ defmodule Explorer.ChainTest do
end
test " loads associations in necessity_by_association " do
address = insert ( :address )
% Address { hash : address_hash } = address = insert ( :address )
block = insert ( :block , number : 2000 )
transaction =
@ -1714,7 +1715,7 @@ defmodule Explorer.ChainTest do
transaction : % Transaction { }
}
| _
] = Chain . address_to_internal_transactions ( address )
] = Chain . address_to_internal_transactions ( address_hash )
assert [
% InternalTransaction {
@ -1725,7 +1726,7 @@ defmodule Explorer.ChainTest do
| _
] =
Chain . address_to_internal_transactions (
address ,
address_hash ,
necessity_by_association : %{
[ from_address : :names ] = > :optional ,
[ to_address : :names ] = > :optional ,
@ -1844,7 +1845,7 @@ defmodule Explorer.ChainTest do
)
result =
address
address . hash
|> Chain . address_to_internal_transactions ( )
|> Enum . map ( & { &1 . transaction_hash , &1 . index } )
@ -1968,7 +1969,7 @@ defmodule Explorer.ChainTest do
{ second_transaction_hash , second_index } ,
{ first_transaction_hash , first_index }
] ==
address
address . hash
|> Chain . address_to_internal_transactions (
paging_options : % PagingOptions { key : { 6001 , 3 , 2 } , page_size : 8 }
)
@ -1981,7 +1982,7 @@ defmodule Explorer.ChainTest do
{ second_transaction_hash , second_index } ,
{ first_transaction_hash , first_index }
] ==
address
address . hash
|> Chain . address_to_internal_transactions (
paging_options : % PagingOptions { key : { 6000 , 0 , 1 } , page_size : 8 }
)
@ -1994,7 +1995,7 @@ defmodule Explorer.ChainTest do
{ second_transaction_hash , second_index } ,
{ first_transaction_hash , first_index }
] ==
address
address . hash
|> Chain . address_to_internal_transactions (
paging_options : % PagingOptions { key : { 6000 , - 1 , - 1 } , page_size : 8 }
)
@ -2002,7 +2003,7 @@ defmodule Explorer.ChainTest do
# block number <
assert [ ] ==
address
address . hash
|> Chain . address_to_internal_transactions (
paging_options : % PagingOptions { key : { 2000 , - 1 , - 1 } , page_size : 8 }
)
@ -2010,7 +2011,7 @@ defmodule Explorer.ChainTest do
end
test " excludes internal transactions of type `call` when they are alone in the parent transaction " do
address = insert ( :address )
% Address { hash : address_hash } = address = insert ( :address )
transaction =
:transaction
@ -2025,11 +2026,11 @@ defmodule Explorer.ChainTest do
transaction_index : transaction . index
)
assert Enum . empty? ( Chain . address_to_internal_transactions ( address ) )
assert Enum . empty? ( Chain . address_to_internal_transactions ( address_hash ) )
end
test " includes internal transactions of type `create` even when they are alone in the parent transaction " do
address = insert ( :address )
% Address { hash : address_hash } = address = insert ( :address )
transaction =
:transaction
@ -2046,7 +2047,7 @@ defmodule Explorer.ChainTest do
transaction_index : transaction . index
)
actual = Enum . at ( Chain . address_to_internal_transactions ( address ) , 0 )
actual = Enum . at ( Chain . address_to_internal_transactions ( address_hash ) , 0 )
assert { actual . transaction_hash , actual . index } == { expected . transaction_hash , expected . index }
end