|
|
|
@ -235,7 +235,10 @@ defmodule Explorer.ChainTest do |
|
|
|
|
insert(:token_transfer, to_address: build(:address), transaction: transaction) |
|
|
|
|
|
|
|
|
|
transaction = Chain.address_to_transactions(address) |> List.first() |
|
|
|
|
assert transaction.token_transfers |> Enum.map(& &1.id) == [token_transfer.id] |
|
|
|
|
|
|
|
|
|
assert transaction.token_transfers |> Enum.map(&{&1.transaction_hash, &1.log_index}) == [ |
|
|
|
|
{token_transfer.transaction_hash, token_transfer.log_index} |
|
|
|
|
] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "returns just the token transfers related to the given contract address" do |
|
|
|
@ -250,7 +253,10 @@ defmodule Explorer.ChainTest do |
|
|
|
|
insert(:token_transfer, to_address: build(:address), transaction: transaction) |
|
|
|
|
|
|
|
|
|
transaction = Chain.address_to_transactions(contract_address) |> List.first() |
|
|
|
|
assert Enum.map(transaction.token_transfers, & &1.id) == [token_transfer.id] |
|
|
|
|
|
|
|
|
|
assert Enum.map(transaction.token_transfers, &{&1.transaction_hash, &1.log_index}) == [ |
|
|
|
|
{token_transfer.transaction_hash, token_transfer.log_index} |
|
|
|
|
] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "returns all token transfers when the given address is the token contract address" do |
|
|
|
@ -572,12 +578,17 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block() |
|
|
|
|
|
|
|
|
|
%TokenTransfer{id: token_transfer_id, token_contract_address_hash: token_contract_address_hash} = |
|
|
|
|
insert(:token_transfer, to_address: address, transaction: transaction) |
|
|
|
|
%TokenTransfer{ |
|
|
|
|
transaction_hash: token_transfer_transaction_hash, |
|
|
|
|
log_index: token_transfer_log_index, |
|
|
|
|
token_contract_address_hash: token_contract_address_hash |
|
|
|
|
} = insert(:token_transfer, to_address: address, transaction: transaction) |
|
|
|
|
|
|
|
|
|
assert token_contract_address_hash |
|
|
|
|
|> Chain.fetch_token_transfers_from_token_hash() |
|
|
|
|
|> Enum.map(& &1.id) == [token_transfer_id] |
|
|
|
|
|> Enum.map(&{&1.transaction_hash, &1.log_index}) == [ |
|
|
|
|
{token_transfer_transaction_hash, token_transfer_log_index} |
|
|
|
|
] |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -778,7 +789,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|> insert_list(:transaction) |
|
|
|
|
|> with_block() |
|
|
|
|
|
|
|
|
|
%TokenTransfer{id: id1} = |
|
|
|
|
%TokenTransfer{transaction_hash: transaction_hash1, log_index: log_index1} = |
|
|
|
|
insert( |
|
|
|
|
:token_transfer, |
|
|
|
|
to_address: address, |
|
|
|
@ -787,7 +798,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
token: token |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
%TokenTransfer{id: id2} = |
|
|
|
|
%TokenTransfer{transaction_hash: transaction_hash2, log_index: log_index2} = |
|
|
|
|
insert( |
|
|
|
|
:token_transfer, |
|
|
|
|
to_address: address, |
|
|
|
@ -799,14 +810,17 @@ defmodule Explorer.ChainTest do |
|
|
|
|
fetched_transactions = Explorer.Chain.hashes_to_transactions([transaction1.hash, transaction2.hash]) |
|
|
|
|
|
|
|
|
|
assert Enum.all?(fetched_transactions, fn transaction -> |
|
|
|
|
hd(transaction.token_transfers).id in [id1, id2] |
|
|
|
|
%TokenTransfer{transaction_hash: transaction_hash, log_index: log_index} = |
|
|
|
|
hd(transaction.token_transfers) |
|
|
|
|
|
|
|
|
|
{transaction_hash, log_index} in [{transaction_hash1, log_index1}, {transaction_hash2, log_index2}] |
|
|
|
|
end) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "indexed_ratio/0" do |
|
|
|
|
test "returns indexed ratio" do |
|
|
|
|
for index <- 6..10 do |
|
|
|
|
for index <- 5..9 do |
|
|
|
|
insert(:block, number: index) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -818,7 +832,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "returns 1.0 if fully indexed blocks" do |
|
|
|
|
for index <- 1..10 do |
|
|
|
|
for index <- 0..9 do |
|
|
|
|
insert(:block, number: index) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -889,7 +903,6 @@ defmodule Explorer.ChainTest do |
|
|
|
|
] |
|
|
|
|
}, |
|
|
|
|
transactions: %{ |
|
|
|
|
on_conflict: :replace_all, |
|
|
|
|
params: [ |
|
|
|
|
%{ |
|
|
|
|
block_hash: "0xf6b4b8c88df3ebd252ec476328334dc026cf66606a84fb769b3d3cbccc8471bd", |
|
|
|
@ -1270,7 +1283,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block(block) |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: first_id} = |
|
|
|
|
%InternalTransaction{transaction_hash: first_transaction_hash, index: first_index} = |
|
|
|
|
insert(:internal_transaction, |
|
|
|
|
index: 1, |
|
|
|
|
transaction: transaction, |
|
|
|
@ -1279,7 +1292,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
transaction_index: transaction.index |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: second_id} = |
|
|
|
|
%InternalTransaction{transaction_hash: second_transaction_hash, index: second_index} = |
|
|
|
|
insert(:internal_transaction, |
|
|
|
|
index: 2, |
|
|
|
|
transaction: transaction, |
|
|
|
@ -1291,10 +1304,10 @@ defmodule Explorer.ChainTest do |
|
|
|
|
result = |
|
|
|
|
address |
|
|
|
|
|> Chain.address_to_internal_transactions() |
|
|
|
|
|> Enum.map(& &1.id) |
|
|
|
|
|> Enum.map(&{&1.transaction_hash, &1.index}) |
|
|
|
|
|
|
|
|
|
assert Enum.member?(result, first_id) |
|
|
|
|
assert Enum.member?(result, second_id) |
|
|
|
|
assert Enum.member?(result, {first_transaction_hash, first_index}) |
|
|
|
|
assert Enum.member?(result, {second_transaction_hash, second_index}) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "loads associations in necessity_by_association" do |
|
|
|
@ -1359,7 +1372,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block(block) |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: first_pending} = |
|
|
|
|
%InternalTransaction{transaction_hash: first_pending_transaction_hash, index: first_pending_index} = |
|
|
|
|
insert( |
|
|
|
|
:internal_transaction, |
|
|
|
|
transaction: pending_transaction, |
|
|
|
@ -1369,7 +1382,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
transaction_index: pending_transaction.index |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: second_pending} = |
|
|
|
|
%InternalTransaction{transaction_hash: second_pending_transaction_hash, index: second_pending_index} = |
|
|
|
|
insert( |
|
|
|
|
:internal_transaction, |
|
|
|
|
transaction: pending_transaction, |
|
|
|
@ -1386,7 +1399,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block(a_block) |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: first} = |
|
|
|
|
%InternalTransaction{transaction_hash: first_transaction_hash, index: first_index} = |
|
|
|
|
insert( |
|
|
|
|
:internal_transaction, |
|
|
|
|
transaction: first_a_transaction, |
|
|
|
@ -1396,7 +1409,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
transaction_index: first_a_transaction.index |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: second} = |
|
|
|
|
%InternalTransaction{transaction_hash: second_transaction_hash, index: second_index} = |
|
|
|
|
insert( |
|
|
|
|
:internal_transaction, |
|
|
|
|
transaction: first_a_transaction, |
|
|
|
@ -1411,7 +1424,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block(a_block) |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: third} = |
|
|
|
|
%InternalTransaction{transaction_hash: third_transaction_hash, index: third_index} = |
|
|
|
|
insert( |
|
|
|
|
:internal_transaction, |
|
|
|
|
transaction: second_a_transaction, |
|
|
|
@ -1421,7 +1434,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
transaction_index: second_a_transaction.index |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: fourth} = |
|
|
|
|
%InternalTransaction{transaction_hash: fourth_transaction_hash, index: fourth_index} = |
|
|
|
|
insert( |
|
|
|
|
:internal_transaction, |
|
|
|
|
transaction: second_a_transaction, |
|
|
|
@ -1438,7 +1451,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block(b_block) |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: fifth} = |
|
|
|
|
%InternalTransaction{transaction_hash: fifth_transaction_hash, index: fifth_index} = |
|
|
|
|
insert( |
|
|
|
|
:internal_transaction, |
|
|
|
|
transaction: first_b_transaction, |
|
|
|
@ -1448,7 +1461,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
transaction_index: first_b_transaction.index |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: sixth} = |
|
|
|
|
%InternalTransaction{transaction_hash: sixth_transaction_hash, index: sixth_index} = |
|
|
|
|
insert( |
|
|
|
|
:internal_transaction, |
|
|
|
|
transaction: first_b_transaction, |
|
|
|
@ -1461,9 +1474,18 @@ defmodule Explorer.ChainTest do |
|
|
|
|
result = |
|
|
|
|
address |
|
|
|
|
|> Chain.address_to_internal_transactions() |
|
|
|
|
|> Enum.map(& &1.id) |
|
|
|
|
|> Enum.map(&{&1.transaction_hash, &1.index}) |
|
|
|
|
|
|
|
|
|
assert [second_pending, first_pending, sixth, fifth, fourth, third, second, first] == result |
|
|
|
|
assert [ |
|
|
|
|
{second_pending_transaction_hash, second_pending_index}, |
|
|
|
|
{first_pending_transaction_hash, first_pending_index}, |
|
|
|
|
{sixth_transaction_hash, sixth_index}, |
|
|
|
|
{fifth_transaction_hash, fifth_index}, |
|
|
|
|
{fourth_transaction_hash, fourth_index}, |
|
|
|
|
{third_transaction_hash, third_index}, |
|
|
|
|
{second_transaction_hash, second_index}, |
|
|
|
|
{first_transaction_hash, first_index} |
|
|
|
|
] == result |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "pages by {block_number, transaction_index, index}" do |
|
|
|
@ -1492,7 +1514,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block(a_block) |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: first} = |
|
|
|
|
%InternalTransaction{transaction_hash: first_transaction_hash, index: first_index} = |
|
|
|
|
insert( |
|
|
|
|
:internal_transaction, |
|
|
|
|
transaction: first_a_transaction, |
|
|
|
@ -1502,7 +1524,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
transaction_index: first_a_transaction.index |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: second} = |
|
|
|
|
%InternalTransaction{transaction_hash: second_transaction_hash, index: second_index} = |
|
|
|
|
insert( |
|
|
|
|
:internal_transaction, |
|
|
|
|
transaction: first_a_transaction, |
|
|
|
@ -1517,7 +1539,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block(a_block) |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: third} = |
|
|
|
|
%InternalTransaction{transaction_hash: third_transaction_hash, index: third_index} = |
|
|
|
|
insert( |
|
|
|
|
:internal_transaction, |
|
|
|
|
transaction: second_a_transaction, |
|
|
|
@ -1527,7 +1549,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
transaction_index: second_a_transaction.index |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: fourth} = |
|
|
|
|
%InternalTransaction{transaction_hash: fourth_transaction_hash, index: fourth_index} = |
|
|
|
|
insert( |
|
|
|
|
:internal_transaction, |
|
|
|
|
transaction: second_a_transaction, |
|
|
|
@ -1544,7 +1566,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block(b_block) |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: fifth} = |
|
|
|
|
%InternalTransaction{transaction_hash: fifth_transaction_hash, index: fifth_index} = |
|
|
|
|
insert( |
|
|
|
|
:internal_transaction, |
|
|
|
|
transaction: first_b_transaction, |
|
|
|
@ -1554,7 +1576,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
transaction_index: first_b_transaction.index |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: sixth} = |
|
|
|
|
%InternalTransaction{transaction_hash: sixth_transaction_hash, index: sixth_index} = |
|
|
|
|
insert( |
|
|
|
|
:internal_transaction, |
|
|
|
|
transaction: first_b_transaction, |
|
|
|
@ -1566,28 +1588,45 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|
|
|
|
|
# When paged, internal transactions need an associated block number, so `second_pending` and `first_pending` are |
|
|
|
|
# excluded. |
|
|
|
|
assert [sixth, fifth, fourth, third, second, first] == |
|
|
|
|
assert [ |
|
|
|
|
{sixth_transaction_hash, sixth_index}, |
|
|
|
|
{fifth_transaction_hash, fifth_index}, |
|
|
|
|
{fourth_transaction_hash, fourth_index}, |
|
|
|
|
{third_transaction_hash, third_index}, |
|
|
|
|
{second_transaction_hash, second_index}, |
|
|
|
|
{first_transaction_hash, first_index} |
|
|
|
|
] == |
|
|
|
|
address |
|
|
|
|
|> Chain.address_to_internal_transactions( |
|
|
|
|
paging_options: %PagingOptions{key: {6001, 3, 2}, page_size: 8} |
|
|
|
|
) |
|
|
|
|
|> Enum.map(& &1.id) |
|
|
|
|
|> Enum.map(&{&1.transaction_hash, &1.index}) |
|
|
|
|
|
|
|
|
|
# block number ==, transaction index ==, internal transaction index < |
|
|
|
|
assert [fourth, third, second, first] == |
|
|
|
|
assert [ |
|
|
|
|
{fourth_transaction_hash, fourth_index}, |
|
|
|
|
{third_transaction_hash, third_index}, |
|
|
|
|
{second_transaction_hash, second_index}, |
|
|
|
|
{first_transaction_hash, first_index} |
|
|
|
|
] == |
|
|
|
|
address |
|
|
|
|
|> Chain.address_to_internal_transactions( |
|
|
|
|
paging_options: %PagingOptions{key: {6000, 0, 1}, page_size: 8} |
|
|
|
|
) |
|
|
|
|
|> Enum.map(& &1.id) |
|
|
|
|
|> Enum.map(&{&1.transaction_hash, &1.index}) |
|
|
|
|
|
|
|
|
|
# block number ==, transaction index < |
|
|
|
|
assert [fourth, third, second, first] == |
|
|
|
|
assert [ |
|
|
|
|
{fourth_transaction_hash, fourth_index}, |
|
|
|
|
{third_transaction_hash, third_index}, |
|
|
|
|
{second_transaction_hash, second_index}, |
|
|
|
|
{first_transaction_hash, first_index} |
|
|
|
|
] == |
|
|
|
|
address |
|
|
|
|
|> Chain.address_to_internal_transactions( |
|
|
|
|
paging_options: %PagingOptions{key: {6000, -1, -1}, page_size: 8} |
|
|
|
|
) |
|
|
|
|
|> Enum.map(& &1.id) |
|
|
|
|
|> Enum.map(&{&1.transaction_hash, &1.index}) |
|
|
|
|
|
|
|
|
|
# block number < |
|
|
|
|
assert [] == |
|
|
|
@ -1595,7 +1634,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|> Chain.address_to_internal_transactions( |
|
|
|
|
paging_options: %PagingOptions{key: {2000, -1, -1}, page_size: 8} |
|
|
|
|
) |
|
|
|
|
|> Enum.map(& &1.id) |
|
|
|
|
|> Enum.map(&{&1.transaction_hash, &1.index}) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "excludes internal transactions of type `call` when they are alone in the parent transaction" do |
|
|
|
@ -1637,7 +1676,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|
|
|
|
|
actual = Enum.at(Chain.address_to_internal_transactions(address), 0) |
|
|
|
|
|
|
|
|
|
assert actual.id == expected.id |
|
|
|
|
assert {actual.transaction_hash, actual.index} == {expected.transaction_hash, expected.index} |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -1708,7 +1747,15 @@ defmodule Explorer.ChainTest do |
|
|
|
|
results = [internal_transaction | _] = Chain.transaction_to_internal_transactions(transaction) |
|
|
|
|
|
|
|
|
|
assert 2 == length(results) |
|
|
|
|
assert Enum.all?(results, &(&1.id in [first.id, second.id])) |
|
|
|
|
|
|
|
|
|
assert Enum.all?( |
|
|
|
|
results, |
|
|
|
|
&({&1.transaction_hash, &1.index} in [ |
|
|
|
|
{first.transaction_hash, first.index}, |
|
|
|
|
{second.transaction_hash, second.index} |
|
|
|
|
]) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
assert internal_transaction.transaction.block.number == block.number |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -1781,7 +1828,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|
|
|
|
|
actual = Enum.at(Chain.transaction_to_internal_transactions(transaction), 0) |
|
|
|
|
|
|
|
|
|
assert actual.id == expected.id |
|
|
|
|
assert {actual.transaction_hash, actual.index} == {expected.transaction_hash, expected.index} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "includes internal transactions of type `reward` even when they are alone in the parent transaction" do |
|
|
|
@ -1801,7 +1848,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|
|
|
|
|
actual = Enum.at(Chain.transaction_to_internal_transactions(transaction), 0) |
|
|
|
|
|
|
|
|
|
assert actual.id == expected.id |
|
|
|
|
assert {actual.transaction_hash, actual.index} == {expected.transaction_hash, expected.index} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "includes internal transactions of type `suicide` even when they are alone in the parent transaction" do |
|
|
|
@ -1822,7 +1869,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|
|
|
|
|
actual = Enum.at(Chain.transaction_to_internal_transactions(transaction), 0) |
|
|
|
|
|
|
|
|
|
assert actual.id == expected.id |
|
|
|
|
assert {actual.transaction_hash, actual.index} == {expected.transaction_hash, expected.index} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "returns the internal transactions in ascending index order" do |
|
|
|
@ -1831,7 +1878,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block() |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: first_id} = |
|
|
|
|
%InternalTransaction{transaction_hash: first_transaction_hash, index: first_index} = |
|
|
|
|
insert(:internal_transaction, |
|
|
|
|
transaction: transaction, |
|
|
|
|
index: 0, |
|
|
|
@ -1839,7 +1886,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
transaction_index: transaction.index |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: second_id} = |
|
|
|
|
%InternalTransaction{transaction_hash: second_transaction_hash, index: second_index} = |
|
|
|
|
insert(:internal_transaction, |
|
|
|
|
transaction: transaction, |
|
|
|
|
index: 1, |
|
|
|
@ -1850,9 +1897,9 @@ defmodule Explorer.ChainTest do |
|
|
|
|
result = |
|
|
|
|
transaction |
|
|
|
|
|> Chain.transaction_to_internal_transactions() |
|
|
|
|
|> Enum.map(& &1.id) |
|
|
|
|
|> Enum.map(&{&1.transaction_hash, &1.index}) |
|
|
|
|
|
|
|
|
|
assert [first_id, second_id] == result |
|
|
|
|
assert [{first_transaction_hash, first_index}, {second_transaction_hash, second_index}] == result |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "pages by index" do |
|
|
|
@ -1861,7 +1908,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block() |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: first_id} = |
|
|
|
|
%InternalTransaction{transaction_hash: first_transaction_hash, index: first_index} = |
|
|
|
|
insert(:internal_transaction, |
|
|
|
|
transaction: transaction, |
|
|
|
|
index: 0, |
|
|
|
@ -1869,7 +1916,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
transaction_index: transaction.index |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
%InternalTransaction{id: second_id} = |
|
|
|
|
%InternalTransaction{transaction_hash: second_transaction_hash, index: second_index} = |
|
|
|
|
insert(:internal_transaction, |
|
|
|
|
transaction: transaction, |
|
|
|
|
index: 1, |
|
|
|
@ -1877,20 +1924,20 @@ defmodule Explorer.ChainTest do |
|
|
|
|
transaction_index: transaction.index |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
assert [^first_id, ^second_id] = |
|
|
|
|
assert [{first_transaction_hash, first_index}, {second_transaction_hash, second_index}] == |
|
|
|
|
transaction |
|
|
|
|
|> Chain.transaction_to_internal_transactions(paging_options: %PagingOptions{key: {-1}, page_size: 2}) |
|
|
|
|
|> Enum.map(& &1.id) |
|
|
|
|
|> Enum.map(&{&1.transaction_hash, &1.index}) |
|
|
|
|
|
|
|
|
|
assert [^first_id] = |
|
|
|
|
assert [{first_transaction_hash, first_index}] == |
|
|
|
|
transaction |
|
|
|
|
|> Chain.transaction_to_internal_transactions(paging_options: %PagingOptions{key: {-1}, page_size: 1}) |
|
|
|
|
|> Enum.map(& &1.id) |
|
|
|
|
|> Enum.map(&{&1.transaction_hash, &1.index}) |
|
|
|
|
|
|
|
|
|
assert [^second_id] = |
|
|
|
|
assert [{second_transaction_hash, second_index}] == |
|
|
|
|
transaction |
|
|
|
|
|> Chain.transaction_to_internal_transactions(paging_options: %PagingOptions{key: {0}, page_size: 2}) |
|
|
|
|
|> Enum.map(& &1.id) |
|
|
|
|
|> Enum.map(&{&1.transaction_hash, &1.index}) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -1907,9 +1954,9 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block() |
|
|
|
|
|
|
|
|
|
%Log{id: id} = insert(:log, transaction: transaction) |
|
|
|
|
%Log{transaction_hash: transaction_hash, index: index} = insert(:log, transaction: transaction) |
|
|
|
|
|
|
|
|
|
assert [%Log{id: ^id}] = Chain.transaction_to_logs(transaction) |
|
|
|
|
assert [%Log{transaction_hash: ^transaction_hash, index: ^index}] = Chain.transaction_to_logs(transaction) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "with logs can be paginated" do |
|
|
|
@ -1970,9 +2017,11 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block() |
|
|
|
|
|
|
|
|
|
%TokenTransfer{id: id} = insert(:token_transfer, transaction: transaction) |
|
|
|
|
%TokenTransfer{transaction_hash: transaction_hash, log_index: log_index} = |
|
|
|
|
insert(:token_transfer, transaction: transaction) |
|
|
|
|
|
|
|
|
|
assert [%TokenTransfer{id: ^id}] = Chain.transaction_to_token_transfers(transaction) |
|
|
|
|
assert [%TokenTransfer{transaction_hash: ^transaction_hash, log_index: ^log_index}] = |
|
|
|
|
Chain.transaction_to_token_transfers(transaction) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "token transfers necessity_by_association loads associations" do |
|
|
|
|