|
|
@ -4,7 +4,7 @@ defmodule Explorer.EtherscanTest do |
|
|
|
import Explorer.Factory |
|
|
|
import Explorer.Factory |
|
|
|
|
|
|
|
|
|
|
|
alias Explorer.{Etherscan, Chain} |
|
|
|
alias Explorer.{Etherscan, Chain} |
|
|
|
alias Explorer.Chain.{Transaction, Wei} |
|
|
|
alias Explorer.Chain.Transaction |
|
|
|
|
|
|
|
|
|
|
|
describe "list_transactions/2" do |
|
|
|
describe "list_transactions/2" do |
|
|
|
test "with empty db" do |
|
|
|
test "with empty db" do |
|
|
@ -1170,7 +1170,7 @@ defmodule Explorer.EtherscanTest do |
|
|
|
|
|
|
|
|
|
|
|
describe "list_blocks/1" do |
|
|
|
describe "list_blocks/1" do |
|
|
|
test "it returns all required fields" do |
|
|
|
test "it returns all required fields" do |
|
|
|
%{block_range: range} = emission_reward = insert(:emission_reward) |
|
|
|
%{block_range: range} = insert(:emission_reward) |
|
|
|
|
|
|
|
|
|
|
|
block = insert(:block, number: Enum.random(Range.new(range.from, range.to))) |
|
|
|
block = insert(:block, number: Enum.random(Range.new(range.from, range.to))) |
|
|
|
|
|
|
|
|
|
|
@ -1181,17 +1181,10 @@ defmodule Explorer.EtherscanTest do |
|
|
|
|> insert(gas_price: 1) |
|
|
|
|> insert(gas_price: 1) |
|
|
|
|> with_block(block, gas_used: 1) |
|
|
|
|> with_block(block, gas_used: 1) |
|
|
|
|
|
|
|
|
|
|
|
expected_reward = |
|
|
|
|
|
|
|
emission_reward.reward |
|
|
|
|
|
|
|
|> Wei.to(:wei) |
|
|
|
|
|
|
|
|> Decimal.add(Decimal.new(1)) |
|
|
|
|
|
|
|
|> Wei.from(:wei) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expected = [ |
|
|
|
expected = [ |
|
|
|
%{ |
|
|
|
%{ |
|
|
|
number: block.number, |
|
|
|
number: block.number, |
|
|
|
timestamp: block.timestamp, |
|
|
|
timestamp: block.timestamp |
|
|
|
reward: expected_reward |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
@ -1199,32 +1192,14 @@ defmodule Explorer.EtherscanTest do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "with block containing multiple transactions" do |
|
|
|
test "with block containing multiple transactions" do |
|
|
|
%{block_range: range} = emission_reward = insert(:emission_reward) |
|
|
|
%{block_range: range} = insert(:emission_reward) |
|
|
|
|
|
|
|
|
|
|
|
block = insert(:block, number: Enum.random(Range.new(range.from, range.to))) |
|
|
|
block = insert(:block, number: Enum.random(Range.new(range.from, range.to))) |
|
|
|
|
|
|
|
|
|
|
|
# irrelevant transaction |
|
|
|
|
|
|
|
insert(:transaction) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:transaction |
|
|
|
|
|
|
|
|> insert(gas_price: 1) |
|
|
|
|
|
|
|
|> with_block(block, gas_used: 1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:transaction |
|
|
|
|
|
|
|
|> insert(gas_price: 1) |
|
|
|
|
|
|
|
|> with_block(block, gas_used: 2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expected_reward = |
|
|
|
|
|
|
|
emission_reward.reward |
|
|
|
|
|
|
|
|> Wei.to(:wei) |
|
|
|
|
|
|
|
|> Decimal.add(Decimal.new(3)) |
|
|
|
|
|
|
|
|> Wei.from(:wei) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expected = [ |
|
|
|
expected = [ |
|
|
|
%{ |
|
|
|
%{ |
|
|
|
number: block.number, |
|
|
|
number: block.number, |
|
|
|
timestamp: block.timestamp, |
|
|
|
timestamp: block.timestamp |
|
|
|
reward: expected_reward |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
@ -1232,7 +1207,7 @@ defmodule Explorer.EtherscanTest do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "with block without transactions" do |
|
|
|
test "with block without transactions" do |
|
|
|
%{block_range: range} = emission_reward = insert(:emission_reward) |
|
|
|
%{block_range: range} = insert(:emission_reward) |
|
|
|
|
|
|
|
|
|
|
|
block = insert(:block, number: Enum.random(Range.new(range.from, range.to))) |
|
|
|
block = insert(:block, number: Enum.random(Range.new(range.from, range.to))) |
|
|
|
|
|
|
|
|
|
|
@ -1242,8 +1217,7 @@ defmodule Explorer.EtherscanTest do |
|
|
|
expected = [ |
|
|
|
expected = [ |
|
|
|
%{ |
|
|
|
%{ |
|
|
|
number: block.number, |
|
|
|
number: block.number, |
|
|
|
timestamp: block.timestamp, |
|
|
|
timestamp: block.timestamp |
|
|
|
reward: emission_reward.reward |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
@ -1251,7 +1225,7 @@ defmodule Explorer.EtherscanTest do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "with multiple blocks" do |
|
|
|
test "with multiple blocks" do |
|
|
|
%{block_range: range} = emission_reward = insert(:emission_reward) |
|
|
|
%{block_range: range} = insert(:emission_reward) |
|
|
|
|
|
|
|
|
|
|
|
block_numbers = Range.new(range.from, range.to) |
|
|
|
block_numbers = Range.new(range.from, range.to) |
|
|
|
|
|
|
|
|
|
|
@ -1262,47 +1236,14 @@ defmodule Explorer.EtherscanTest do |
|
|
|
block1 = insert(:block, number: block_number1, miner: address) |
|
|
|
block1 = insert(:block, number: block_number1, miner: address) |
|
|
|
block2 = insert(:block, number: block_number2, miner: address) |
|
|
|
block2 = insert(:block, number: block_number2, miner: address) |
|
|
|
|
|
|
|
|
|
|
|
# irrelevant transaction |
|
|
|
|
|
|
|
insert(:transaction) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:transaction |
|
|
|
|
|
|
|
|> insert(gas_price: 2) |
|
|
|
|
|
|
|
|> with_block(block1, gas_used: 2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:transaction |
|
|
|
|
|
|
|
|> insert(gas_price: 2) |
|
|
|
|
|
|
|
|> with_block(block1, gas_used: 2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:transaction |
|
|
|
|
|
|
|
|> insert(gas_price: 3) |
|
|
|
|
|
|
|
|> with_block(block2, gas_used: 3) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:transaction |
|
|
|
|
|
|
|
|> insert(gas_price: 3) |
|
|
|
|
|
|
|
|> with_block(block2, gas_used: 3) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expected_reward_block1 = |
|
|
|
|
|
|
|
emission_reward.reward |
|
|
|
|
|
|
|
|> Wei.to(:wei) |
|
|
|
|
|
|
|
|> Decimal.add(Decimal.new(8)) |
|
|
|
|
|
|
|
|> Wei.from(:wei) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expected_reward_block2 = |
|
|
|
|
|
|
|
emission_reward.reward |
|
|
|
|
|
|
|
|> Wei.to(:wei) |
|
|
|
|
|
|
|
|> Decimal.add(Decimal.new(18)) |
|
|
|
|
|
|
|
|> Wei.from(:wei) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expected = [ |
|
|
|
expected = [ |
|
|
|
%{ |
|
|
|
%{ |
|
|
|
number: block2.number, |
|
|
|
number: block2.number, |
|
|
|
timestamp: block2.timestamp, |
|
|
|
timestamp: block2.timestamp |
|
|
|
reward: expected_reward_block2 |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
%{ |
|
|
|
%{ |
|
|
|
number: block1.number, |
|
|
|
number: block1.number, |
|
|
|
timestamp: block1.timestamp, |
|
|
|
timestamp: block1.timestamp |
|
|
|
reward: expected_reward_block1 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
@ -1310,7 +1251,7 @@ defmodule Explorer.EtherscanTest do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "with pagination options" do |
|
|
|
test "with pagination options" do |
|
|
|
%{block_range: range} = emission_reward = insert(:emission_reward) |
|
|
|
%{block_range: range} = insert(:emission_reward) |
|
|
|
|
|
|
|
|
|
|
|
block_numbers = Range.new(range.from, range.to) |
|
|
|
block_numbers = Range.new(range.from, range.to) |
|
|
|
|
|
|
|
|
|
|
@ -1321,29 +1262,17 @@ defmodule Explorer.EtherscanTest do |
|
|
|
block1 = insert(:block, number: block_number1, miner: address) |
|
|
|
block1 = insert(:block, number: block_number1, miner: address) |
|
|
|
block2 = insert(:block, number: block_number2, miner: address) |
|
|
|
block2 = insert(:block, number: block_number2, miner: address) |
|
|
|
|
|
|
|
|
|
|
|
:transaction |
|
|
|
|
|
|
|
|> insert(gas_price: 2) |
|
|
|
|
|
|
|
|> with_block(block1, gas_used: 2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expected_reward = |
|
|
|
|
|
|
|
emission_reward.reward |
|
|
|
|
|
|
|
|> Wei.to(:wei) |
|
|
|
|
|
|
|
|> Decimal.add(Decimal.new(4)) |
|
|
|
|
|
|
|
|> Wei.from(:wei) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expected1 = [ |
|
|
|
expected1 = [ |
|
|
|
%{ |
|
|
|
%{ |
|
|
|
number: block2.number, |
|
|
|
number: block2.number, |
|
|
|
timestamp: block2.timestamp, |
|
|
|
timestamp: block2.timestamp |
|
|
|
reward: emission_reward.reward |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
expected2 = [ |
|
|
|
expected2 = [ |
|
|
|
%{ |
|
|
|
%{ |
|
|
|
number: block1.number, |
|
|
|
number: block1.number, |
|
|
|
timestamp: block1.timestamp, |
|
|
|
timestamp: block1.timestamp |
|
|
|
reward: expected_reward |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|