@ -383,13 +383,13 @@ defmodule Explorer.ChainTest do
end
end
end
end
describe " address_to_transactions_with_rewards/2 " do
describe " address_to_mined_ transactions_with_rewards/2 " do
test " without transactions " do
test " without transactions " do
% Address { hash : address_hash } = insert ( :address )
% Address { hash : address_hash } = insert ( :address )
assert Repo . aggregate ( Transaction , :count , :hash ) == 0
assert Repo . aggregate ( Transaction , :count , :hash ) == 0
assert [ ] == Chain . address_to_transactions_with_rewards ( address_hash )
assert [ ] == Chain . address_to_mined_ transactions_with_rewards ( address_hash )
end
end
test " with from transactions " do
test " with from transactions " do
@ -401,7 +401,7 @@ defmodule Explorer.ChainTest do
|> with_block ( )
|> with_block ( )
assert [ transaction ] ==
assert [ transaction ] ==
Chain . address_to_transactions_with_rewards ( address_hash , direction : :from )
Chain . address_to_mined_ transactions_with_rewards ( address_hash , direction : :from )
|> Repo . preload ( [ :block , :to_address , :from_address ] )
|> Repo . preload ( [ :block , :to_address , :from_address ] )
end
end
@ -414,7 +414,7 @@ defmodule Explorer.ChainTest do
|> with_block ( )
|> with_block ( )
assert [ transaction ] ==
assert [ transaction ] ==
Chain . address_to_transactions_with_rewards ( address_hash , direction : :to )
Chain . address_to_mined_ transactions_with_rewards ( address_hash , direction : :to )
|> Repo . preload ( [ :block , :to_address , :from_address ] )
|> Repo . preload ( [ :block , :to_address , :from_address ] )
end
end
@ -428,7 +428,7 @@ defmodule Explorer.ChainTest do
# only contains "from" transaction
# only contains "from" transaction
assert [ transaction ] ==
assert [ transaction ] ==
Chain . address_to_transactions_with_rewards ( address_hash , direction : :from )
Chain . address_to_mined_ transactions_with_rewards ( address_hash , direction : :from )
|> Repo . preload ( [ :block , :to_address , :from_address ] )
|> Repo . preload ( [ :block , :to_address , :from_address ] )
end
end
@ -441,7 +441,7 @@ defmodule Explorer.ChainTest do
|> with_block ( )
|> with_block ( )
assert [ transaction ] ==
assert [ transaction ] ==
Chain . address_to_transactions_with_rewards ( address_hash , direction : :to )
Chain . address_to_mined_ transactions_with_rewards ( address_hash , direction : :to )
|> Repo . preload ( [ :block , :to_address , :from_address ] )
|> Repo . preload ( [ :block , :to_address , :from_address ] )
end
end
@ -460,7 +460,7 @@ defmodule Explorer.ChainTest do
|> with_block ( block )
|> with_block ( block )
assert [ transaction2 , transaction1 ] ==
assert [ transaction2 , transaction1 ] ==
Chain . address_to_transactions_with_rewards ( address_hash )
Chain . address_to_mined_ transactions_with_rewards ( address_hash )
|> Repo . preload ( [ :block , :to_address , :from_address ] )
|> Repo . preload ( [ :block , :to_address , :from_address ] )
end
end
@ -481,7 +481,7 @@ defmodule Explorer.ChainTest do
transaction_index : transaction . index
transaction_index : transaction . index
)
)
assert [ ] == Chain . address_to_transactions_with_rewards ( address . hash )
assert [ ] == Chain . address_to_mined_ transactions_with_rewards ( address . hash )
end
end
test " returns transactions that have token transfers for the given to_address " do
test " returns transactions that have token transfers for the given to_address " do
@ -499,7 +499,7 @@ defmodule Explorer.ChainTest do
)
)
assert [ transaction . hash ] ==
assert [ transaction . hash ] ==
Chain . address_to_transactions_with_rewards ( address_hash )
Chain . address_to_mined_ transactions_with_rewards ( address_hash )
|> Enum . map ( & &1 . hash )
|> Enum . map ( & &1 . hash )
end
end
@ -519,7 +519,7 @@ defmodule Explorer.ChainTest do
assert second_page_hashes ==
assert second_page_hashes ==
address_hash
address_hash
|> Chain . address_to_transactions_with_rewards (
|> Chain . address_to_mined_ transactions_with_rewards (
paging_options : % PagingOptions {
paging_options : % PagingOptions {
key : { block_number , index } ,
key : { block_number , index } ,
page_size : 2
page_size : 2
@ -568,7 +568,7 @@ defmodule Explorer.ChainTest do
result =
result =
address_hash
address_hash
|> Chain . address_to_transactions_with_rewards ( )
|> Chain . address_to_mined_ transactions_with_rewards ( )
|> Enum . map ( & &1 . hash )
|> Enum . map ( & &1 . hash )
assert [ fourth , third , second , first , sixth , fifth ] == result
assert [ fourth , third , second , first , sixth , fifth ] == result
@ -577,8 +577,15 @@ defmodule Explorer.ChainTest do
test " with emission rewards " do
test " with emission rewards " do
Application . put_env ( :block_scout_web , BlockScoutWeb.Chain , has_emission_funds : true )
Application . put_env ( :block_scout_web , BlockScoutWeb.Chain , has_emission_funds : true )
Application . put_env ( :explorer , Explorer.Chain.Block.Reward ,
validators_contract_address : " 0x0000000000000000000000000000000000000005 " ,
keys_manager_contract_address : " 0x0000000000000000000000000000000000000006 "
)
block = insert ( :block )
block = insert ( :block )
block_miner_hash_string = Base . encode16 ( block . miner_hash . bytes , case : :lower )
insert (
insert (
:reward ,
:reward ,
address_hash : block . miner_hash ,
address_hash : block . miner_hash ,
@ -593,16 +600,51 @@ defmodule Explorer.ChainTest do
address_type : :emission_funds
address_type : :emission_funds
)
)
assert [ { _ , _ } ] = Chain . address_to_transactions_with_rewards ( block . miner . hash )
# isValidator => true
expect (
EthereumJSONRPC.Mox ,
:json_rpc ,
fn [ %{ id : id , method : _ , params : [ %{ data : _ , to : _ } , _ ] } ] , _options ->
{ :ok ,
[ %{ id : id , jsonrpc : " 2.0 " , result : " 0x0000000000000000000000000000000000000000000000000000000000000001 " } ] }
end
)
Application . put_env ( :block_scout_web , BlockScoutWeb.Chain , has_emission_funds : false )
# getPayoutByMining => 0x0000000000000000000000000000000000000001
expect (
EthereumJSONRPC.Mox ,
:json_rpc ,
fn [ %{ id : id , method : _ , params : [ %{ data : _ , to : _ } , _ ] } ] , _options ->
{ :ok , [ %{ id : id , result : " 0x000000000000000000000000 " <> block_miner_hash_string } ] }
end
)
res = Chain . address_to_mined_transactions_with_rewards ( block . miner . hash )
assert [ { _ , _ } ] = res
on_exit ( fn ->
Application . put_env ( :block_scout_web , BlockScoutWeb.Chain , has_emission_funds : false )
Application . put_env ( :explorer , Explorer.Chain.Block.Reward ,
validators_contract_address : nil ,
keys_manager_contract_address : nil
)
end )
end
end
test " with emission rewards and transactions " do
test " with emission rewards and transactions " do
Application . put_env ( :block_scout_web , BlockScoutWeb.Chain , has_emission_funds : true )
Application . put_env ( :block_scout_web , BlockScoutWeb.Chain , has_emission_funds : true )
Application . put_env ( :explorer , Explorer.Chain.Block.Reward ,
validators_contract_address : " 0x0000000000000000000000000000000000000005 " ,
keys_manager_contract_address : " 0x0000000000000000000000000000000000000006 "
)
block = insert ( :block )
block = insert ( :block )
block_miner_hash_string = Base . encode16 ( block . miner_hash . bytes , case : :lower )
insert (
insert (
:reward ,
:reward ,
address_hash : block . miner_hash ,
address_hash : block . miner_hash ,
@ -618,13 +660,39 @@ defmodule Explorer.ChainTest do
)
)
:transaction
:transaction
|> insert ( from _address: block . miner )
|> insert ( to _address: block . miner )
|> with_block ( block )
|> with_block ( block )
|> Repo . preload ( :token_transfers )
|> Repo . preload ( :token_transfers )
assert [ _ , { _ , _ } ] = Chain . address_to_transactions_with_rewards ( block . miner . hash , direction : :from )
# isValidator => true
expect (
EthereumJSONRPC.Mox ,
:json_rpc ,
fn [ %{ id : id , method : _ , params : [ %{ data : _ , to : _ } , _ ] } ] , _options ->
{ :ok ,
[ %{ id : id , jsonrpc : " 2.0 " , result : " 0x0000000000000000000000000000000000000000000000000000000000000001 " } ] }
end
)
Application . put_env ( :block_scout_web , BlockScoutWeb.Chain , has_emission_funds : false )
# getPayoutByMining => 0x0000000000000000000000000000000000000001
expect (
EthereumJSONRPC.Mox ,
:json_rpc ,
fn [ %{ id : id , method : _ , params : [ %{ data : _ , to : _ } , _ ] } ] , _options ->
{ :ok , [ %{ id : id , result : " 0x000000000000000000000000 " <> block_miner_hash_string } ] }
end
)
assert [ _ , { _ , _ } ] = Chain . address_to_mined_transactions_with_rewards ( block . miner . hash , direction : :to )
on_exit ( fn ->
Application . put_env ( :block_scout_web , BlockScoutWeb.Chain , has_emission_funds : false )
Application . put_env ( :explorer , Explorer.Chain.Block.Reward ,
validators_contract_address : nil ,
keys_manager_contract_address : nil
)
end )
end
end
test " with transactions if rewards are not in the range of blocks " do
test " with transactions if rewards are not in the range of blocks " do
@ -651,7 +719,7 @@ defmodule Explorer.ChainTest do
|> with_block ( )
|> with_block ( )
|> Repo . preload ( :token_transfers )
|> Repo . preload ( :token_transfers )
assert [ _ ] = Chain . address_to_transactions_with_rewards ( block . miner . hash , direction : :from )
assert [ _ ] = Chain . address_to_mined_ transactions_with_rewards ( block . miner . hash , direction : :from )
Application . put_env ( :block_scout_web , BlockScoutWeb.Chain , has_emission_funds : false )
Application . put_env ( :block_scout_web , BlockScoutWeb.Chain , has_emission_funds : false )
end
end
@ -675,7 +743,104 @@ defmodule Explorer.ChainTest do
address_type : :emission_funds
address_type : :emission_funds
)
)
assert [ ] == Chain . address_to_transactions_with_rewards ( block . miner . hash )
assert [ ] == Chain . address_to_mined_transactions_with_rewards ( block . miner . hash )
end
end
describe " address_to_transactions_tasks_range_of_blocks/2 " do
test " returns empty extremums if no transactions " do
address = insert ( :address )
extremums = Chain . address_to_transactions_tasks_range_of_blocks ( address . hash , [ ] )
assert extremums == %{
:min_block_number = > nil ,
:max_block_number = > 0
}
end
test " returns correct extremums for from_address " do
address = insert ( :address )
:transaction
|> insert ( from_address : address )
|> with_block ( insert ( :block , number : 1000 ) )
extremums = Chain . address_to_transactions_tasks_range_of_blocks ( address . hash , [ ] )
assert extremums == %{
:min_block_number = > 1000 ,
:max_block_number = > 1000
}
end
test " returns correct extremums for to_address " do
address = insert ( :address )
:transaction
|> insert ( to_address : address )
|> with_block ( insert ( :block , number : 1000 ) )
extremums = Chain . address_to_transactions_tasks_range_of_blocks ( address . hash , [ ] )
assert extremums == %{
:min_block_number = > 1000 ,
:max_block_number = > 1000
}
end
test " returns correct extremums for created_contract_address " do
address = insert ( :address )
:transaction
|> insert ( created_contract_address : address )
|> with_block ( insert ( :block , number : 1000 ) )
extremums = Chain . address_to_transactions_tasks_range_of_blocks ( address . hash , [ ] )
assert extremums == %{
:min_block_number = > 1000 ,
:max_block_number = > 1000
}
end
test " returns correct extremums for multiple number of transactions " do
address = insert ( :address )
:transaction
|> insert ( created_contract_address : address )
|> with_block ( insert ( :block , number : 1000 ) )
:transaction
|> insert ( created_contract_address : address )
|> with_block ( insert ( :block , number : 999 ) )
:transaction
|> insert ( created_contract_address : address )
|> with_block ( insert ( :block , number : 1003 ) )
:transaction
|> insert ( from_address : address )
|> with_block ( insert ( :block , number : 1001 ) )
:transaction
|> insert ( from_address : address )
|> with_block ( insert ( :block , number : 1004 ) )
:transaction
|> insert ( to_address : address )
|> with_block ( insert ( :block , number : 1002 ) )
:transaction
|> insert ( to_address : address )
|> with_block ( insert ( :block , number : 998 ) )
extremums = Chain . address_to_transactions_tasks_range_of_blocks ( address . hash , [ ] )
assert extremums == %{
:min_block_number = > 998 ,
:max_block_number = > 1004
}
end
end
end
end