|
|
@ -16,7 +16,7 @@ defmodule Explorer.Chain.Transaction.History.HistorianTest do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
describe "compile_records/1" do |
|
|
|
describe "compile_records/1" do |
|
|
|
test "fetches transactions from blocks mined in the past num_days" do |
|
|
|
test "fetches transactions, total gas, total fee from blocks mined in the past num_days" do |
|
|
|
blocks = [ |
|
|
|
blocks = [ |
|
|
|
# 1970-01-03 00:00:60 |
|
|
|
# 1970-01-03 00:00:60 |
|
|
|
insert(:block, timestamp: DateTime.from_unix!(days_to_secs(2) + 60)), |
|
|
|
insert(:block, timestamp: DateTime.from_unix!(days_to_secs(2) + 60)), |
|
|
@ -28,29 +28,41 @@ defmodule Explorer.Chain.Transaction.History.HistorianTest do |
|
|
|
insert(:block, timestamp: DateTime.from_unix!(days_to_secs(1))) |
|
|
|
insert(:block, timestamp: DateTime.from_unix!(days_to_secs(1))) |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
transaction_1 = insert(:transaction) |> with_block(Enum.at(blocks, 0)) |
|
|
|
transaction_1 = insert(:transaction) |> with_block(Enum.at(blocks, 0), status: :ok) |
|
|
|
transaction_2 = insert(:transaction) |> with_block(Enum.at(blocks, 1)) |
|
|
|
transaction_2 = insert(:transaction) |> with_block(Enum.at(blocks, 1), status: :ok) |
|
|
|
transaction_3 = insert(:transaction) |> with_block(Enum.at(blocks, 2)) |
|
|
|
transaction_3 = insert(:transaction) |> with_block(Enum.at(blocks, 2), status: :ok) |
|
|
|
|
|
|
|
|
|
|
|
expected = [ |
|
|
|
expected = [ |
|
|
|
%{date: ~D[1970-01-04], number_of_transactions: 0} |
|
|
|
%{date: ~D[1970-01-04], number_of_transactions: 0, gas_used: 0, total_fee: 0} |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, ^expected} = Historian.compile_records(1) |
|
|
|
assert {:ok, ^expected} = Historian.compile_records(1) |
|
|
|
|
|
|
|
|
|
|
|
total_gas_used_1 = Decimal.add(transaction_1.gas_used, transaction_2.gas_used) |
|
|
|
total_gas_used_1 = Decimal.add(transaction_1.gas_used, transaction_2.gas_used) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%Explorer.Chain.Wei{value: transaction_1_gas_price_value} = transaction_1.gas_price |
|
|
|
|
|
|
|
%Explorer.Chain.Wei{value: transaction_2_gas_price_value} = transaction_2.gas_price |
|
|
|
|
|
|
|
%Explorer.Chain.Wei{value: transaction_3_gas_price_value} = transaction_3.gas_price |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
total_fee_1 = |
|
|
|
|
|
|
|
Decimal.add( |
|
|
|
|
|
|
|
Decimal.mult(transaction_1.gas_used, transaction_1_gas_price_value), |
|
|
|
|
|
|
|
Decimal.mult(transaction_2.gas_used, transaction_2_gas_price_value) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
total_fee_3 = Decimal.mult(transaction_3.gas_used, transaction_3_gas_price_value) |
|
|
|
|
|
|
|
|
|
|
|
expected = [ |
|
|
|
expected = [ |
|
|
|
%{date: ~D[1970-01-04], number_of_transactions: 0}, |
|
|
|
%{date: ~D[1970-01-04], number_of_transactions: 0, gas_used: 0, total_fee: 0}, |
|
|
|
%{date: ~D[1970-01-03], gas_used: total_gas_used_1, number_of_transactions: 2} |
|
|
|
%{date: ~D[1970-01-03], gas_used: total_gas_used_1, number_of_transactions: 2, total_fee: total_fee_1} |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, ^expected} = Historian.compile_records(2) |
|
|
|
assert {:ok, ^expected} = Historian.compile_records(2) |
|
|
|
|
|
|
|
|
|
|
|
expected = [ |
|
|
|
expected = [ |
|
|
|
%{date: ~D[1970-01-04], number_of_transactions: 0}, |
|
|
|
%{date: ~D[1970-01-04], number_of_transactions: 0, gas_used: 0, total_fee: 0}, |
|
|
|
%{date: ~D[1970-01-03], gas_used: total_gas_used_1, number_of_transactions: 2}, |
|
|
|
%{date: ~D[1970-01-03], gas_used: total_gas_used_1, number_of_transactions: 2, total_fee: total_fee_1}, |
|
|
|
%{date: ~D[1970-01-02], gas_used: transaction_3.gas_used, number_of_transactions: 1} |
|
|
|
%{date: ~D[1970-01-02], gas_used: transaction_3.gas_used, number_of_transactions: 1, total_fee: total_fee_3} |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, ^expected} = Historian.compile_records(3) |
|
|
|
assert {:ok, ^expected} = Historian.compile_records(3) |
|
|
|