@ -222,4 +222,278 @@ defmodule EthereumJSONRPC.ParityTest do
] }
] }
end
end
end
end
describe " fetch_beneficiaries/1 " do
test " with valid block range, returns {:ok, addresses} " , %{
json_rpc_named_arguments : json_rpc_named_arguments
} do
block_number = 5_080_887
block_quantity = EthereumJSONRPC . integer_to_quantity ( block_number )
hash1 = " 0xef481b4e2c3ed62265617f2e9dfcdf3cf3efc11a "
hash2 = " 0x523b6539ff08d72a6c8bb598af95bf50c1ea839c "
if json_rpc_named_arguments [ :transport ] == EthereumJSONRPC.Mox do
expect ( EthereumJSONRPC.Mox , :json_rpc , fn %{ params : [ ^ block_quantity ] } , _options ->
{ :ok ,
[
%{
" action " = > %{
" author " = > hash1 ,
" rewardType " = > " block " ,
" value " = > " 0xde0b6b3a7640000 "
} ,
" blockHash " = > " 0x52a8d2185282506ce681364d2aa0c085ba45fdeb5d6c0ddec1131617a71ee2ca " ,
" blockNumber " = > block_number ,
" result " = > nil ,
" subtraces " = > 0 ,
" traceAddress " = > [ ] ,
" transactionHash " = > nil ,
" transactionPosition " = > nil ,
" type " = > " reward "
} ,
%{
" action " = > %{
" author " = > hash2 ,
" rewardType " = > " block " ,
" value " = > " 0xde0b6b3a7640000 "
} ,
" blockHash " = > " 0x52a8d2185282506ce681364d2aa0c085ba45fdeb5d6c0ddec1131617a71ee2ca " ,
" blockNumber " = > block_number ,
" result " = > nil ,
" subtraces " = > 0 ,
" traceAddress " = > [ ] ,
" transactionHash " = > nil ,
" transactionPosition " = > nil ,
" type " = > " reward "
}
] }
end )
end
expected_beneficiaries =
MapSet . new ( [
%{ block_number : block_number , address_hash : hash2 } ,
%{ block_number : block_number , address_hash : hash1 }
] )
{ :ok , fetched_beneficiaries } =
EthereumJSONRPC.Parity . fetch_beneficiaries ( 5_080_887 . . 5_080_887 , json_rpc_named_arguments )
assert fetched_beneficiaries == expected_beneficiaries
end
test " with no rewards, returns {:ok, []} " , %{
json_rpc_named_arguments : json_rpc_named_arguments
} do
if json_rpc_named_arguments [ :transport ] == EthereumJSONRPC.Mox do
expect ( EthereumJSONRPC.Mox , :json_rpc , fn _json , _options ->
{ :ok , [ ] }
end )
{ :ok , fetched_beneficiaries } =
EthereumJSONRPC.Parity . fetch_beneficiaries ( 5_080_887 . . 5_080_887 , json_rpc_named_arguments )
assert fetched_beneficiaries == MapSet . new ( )
end
end
test " with nil rewards, returns {:error, } " , %{
json_rpc_named_arguments : json_rpc_named_arguments
} do
if json_rpc_named_arguments [ :transport ] == EthereumJSONRPC.Mox do
expect ( EthereumJSONRPC.Mox , :json_rpc , fn _json , _options ->
{ :ok , nil }
end )
result = EthereumJSONRPC.Parity . fetch_beneficiaries ( 5_080_887 . . 5_080_887 , json_rpc_named_arguments )
assert result == { :error , " Error fetching block reward contract beneficiaries " }
end
end
test " ignores non-reward traces " , %{
json_rpc_named_arguments : json_rpc_named_arguments
} do
block_number = 5_077_429
block_quantity = EthereumJSONRPC . integer_to_quantity ( block_number )
hash1 = " 0xcfa53498686e00d3b4b41f3bea61604038eebb58 "
hash2 = " 0x523b6539ff08d72a6c8bb598af95bf50c1ea839c "
if json_rpc_named_arguments [ :transport ] == EthereumJSONRPC.Mox do
expect ( EthereumJSONRPC.Mox , :json_rpc , fn %{ params : [ ^ block_quantity ] } , _options ->
{ :ok ,
[
%{
" action " = > %{
" callType " = > " call " ,
" from " = > " 0x95426f2bc716022fcf1def006dbc4bb81f5b5164 " ,
" gas " = > " 0x0 " ,
" input " = > " 0x " ,
" to " = > " 0xe797a1da01eb0f951e0e400f9343de9d17a06bac " ,
" value " = > " 0x4a817c800 "
} ,
" blockHash " = > " 0x6659a4926d833a7eab74379fa647ec74c9f5e65f8029552a35264126560f300a " ,
" blockNumber " = > block_number ,
" result " = > %{ " gasUsed " = > " 0x0 " , " output " = > " 0x " } ,
" subtraces " = > 0 ,
" traceAddress " = > [ ] ,
" transactionHash " = > " 0x5acf90f846b8216bdbc309cf4eb24adc69d730bf29304dc0e740cf6df850666e " ,
" transactionPosition " = > 0 ,
" type " = > " call "
} ,
%{
" action " = > %{
" author " = > hash1 ,
" rewardType " = > " block " ,
" value " = > " 0xde0b6b3a7640000 "
} ,
" blockHash " = > " 0x6659a4926d833a7eab74379fa647ec74c9f5e65f8029552a35264126560f300a " ,
" blockNumber " = > block_number ,
" result " = > nil ,
" subtraces " = > 0 ,
" traceAddress " = > [ ] ,
" transactionHash " = > nil ,
" transactionPosition " = > nil ,
" type " = > " reward "
} ,
%{
" action " = > %{
" author " = > hash2 ,
" rewardType " = > " block " ,
" value " = > " 0xde0b6b3a7640000 "
} ,
" blockHash " = > " 0x6659a4926d833a7eab74379fa647ec74c9f5e65f8029552a35264126560f300a " ,
" blockNumber " = > block_number ,
" result " = > nil ,
" subtraces " = > 0 ,
" traceAddress " = > [ ] ,
" transactionHash " = > nil ,
" transactionPosition " = > nil ,
" type " = > " reward "
}
] }
end )
end
expected_beneficiaries =
MapSet . new ( [
%{ block_number : block_number , address_hash : hash2 } ,
%{ block_number : block_number , address_hash : hash1 }
] )
{ :ok , fetched_beneficiaries } =
EthereumJSONRPC.Parity . fetch_beneficiaries ( 5_077_429 . . 5_077_429 , json_rpc_named_arguments )
assert fetched_beneficiaries == expected_beneficiaries
end
test " with multiple blocks with repeat beneficiaries " , %{
json_rpc_named_arguments : json_rpc_named_arguments
} do
block_number1 = 5_080_886
block_quantity1 = EthereumJSONRPC . integer_to_quantity ( block_number1 )
block_number2 = 5_080_887
block_quantity2 = EthereumJSONRPC . integer_to_quantity ( block_number2 )
hash1 = " 0xadc702c4bb09fbc502dd951856b9c7a1528a88de "
hash2 = " 0xef481b4e2c3ed62265617f2e9dfcdf3cf3efc11a "
hash3 = " 0x523b6539ff08d72a6c8bb598af95bf50c1ea839c "
if json_rpc_named_arguments [ :transport ] == EthereumJSONRPC.Mox do
expect ( EthereumJSONRPC.Mox , :json_rpc , 2 , fn
%{ params : [ ^ block_quantity1 ] } = _json , _options ->
{ :ok ,
[
%{
" action " = > %{
" author " = > hash1 ,
" rewardType " = > " block " ,
" value " = > " 0xde0b6b3a7640000 "
} ,
" blockNumber " = > block_number1 ,
" result " = > nil ,
" subtraces " = > 0 ,
" traceAddress " = > [ ] ,
" transactionHash " = > nil ,
" transactionPosition " = > nil ,
" type " = > " reward "
} ,
%{
" action " = > %{
" author " = > hash3 ,
" rewardType " = > " block " ,
" value " = > " 0xde0b6b3a7640000 "
} ,
" blockNumber " = > block_number1 ,
" result " = > nil ,
" subtraces " = > 0 ,
" traceAddress " = > [ ] ,
" transactionHash " = > nil ,
" transactionPosition " = > nil ,
" type " = > " reward "
}
] }
%{ params : [ ^ block_quantity2 ] } = _json , _options ->
{ :ok ,
[
%{
" action " = > %{
" author " = > hash2 ,
" rewardType " = > " block " ,
" value " = > " 0xde0b6b3a7640000 "
} ,
" blockNumber " = > block_number2 ,
" result " = > nil ,
" subtraces " = > 0 ,
" traceAddress " = > [ ] ,
" transactionHash " = > nil ,
" transactionPosition " = > nil ,
" type " = > " reward "
} ,
%{
" action " = > %{
" author " = > hash3 ,
" rewardType " = > " block " ,
" value " = > " 0xde0b6b3a7640000 "
} ,
" blockNumber " = > block_number2 ,
" result " = > nil ,
" subtraces " = > 0 ,
" traceAddress " = > [ ] ,
" transactionHash " = > nil ,
" transactionPosition " = > nil ,
" type " = > " reward "
}
] }
end )
end
expected_beneficiaries =
MapSet . new ( [
%{ block_number : block_number1 , address_hash : hash3 } ,
%{ block_number : block_number2 , address_hash : hash3 } ,
%{ block_number : block_number2 , address_hash : hash2 } ,
%{ block_number : block_number1 , address_hash : hash1 }
] )
{ :ok , fetched_beneficiaries } =
EthereumJSONRPC.Parity . fetch_beneficiaries ( 5_080_886 . . 5_080_887 , json_rpc_named_arguments )
assert fetched_beneficiaries == expected_beneficiaries
end
test " with error, returns {:error, reason} " , %{
json_rpc_named_arguments : json_rpc_named_arguments
} do
if json_rpc_named_arguments [ :transport ] == EthereumJSONRPC.Mox do
expect ( EthereumJSONRPC.Mox , :json_rpc , fn _json , _options ->
{ :error , " oops " }
end )
result = EthereumJSONRPC.Parity . fetch_beneficiaries ( 5_080_887 . . 5_080_887 , json_rpc_named_arguments )
assert result == { :error , " Error fetching block reward contract beneficiaries " }
end
end
end
end
end