|
|
|
@ -68,7 +68,12 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|
|
|
|
|
test "with from transactions" do |
|
|
|
|
address = insert(:address) |
|
|
|
|
transaction = :transaction |> insert(from_address: address) |> with_block() |
|
|
|
|
|
|
|
|
|
transaction = |
|
|
|
|
:transaction |
|
|
|
|
|> insert(from_address: address) |
|
|
|
|
|> with_block() |
|
|
|
|
|> Repo.preload(:token_transfers) |
|
|
|
|
|
|
|
|
|
assert [transaction] == |
|
|
|
|
Chain.address_to_transactions(address, direction: :from) |
|
|
|
@ -77,7 +82,12 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|
|
|
|
|
test "with to transactions" do |
|
|
|
|
address = insert(:address) |
|
|
|
|
transaction = :transaction |> insert(to_address: address) |> with_block() |
|
|
|
|
|
|
|
|
|
transaction = |
|
|
|
|
:transaction |
|
|
|
|
|> insert(to_address: address) |
|
|
|
|
|> with_block() |
|
|
|
|
|> Repo.preload(:token_transfers) |
|
|
|
|
|
|
|
|
|
assert [transaction] == |
|
|
|
|
Chain.address_to_transactions(address, direction: :to) |
|
|
|
@ -86,8 +96,12 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|
|
|
|
|
test "with to and from transactions and direction: :from" do |
|
|
|
|
address = insert(:address) |
|
|
|
|
transaction = :transaction |> insert(from_address: address) |> with_block() |
|
|
|
|
:transaction |> insert(to_address: address) |> with_block() |
|
|
|
|
|
|
|
|
|
transaction = |
|
|
|
|
:transaction |
|
|
|
|
|> insert(from_address: address) |
|
|
|
|
|> with_block() |
|
|
|
|
|> Repo.preload(:token_transfers) |
|
|
|
|
|
|
|
|
|
# only contains "from" transaction |
|
|
|
|
assert [transaction] == |
|
|
|
@ -97,10 +111,13 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|
|
|
|
|
test "with to and from transactions and direction: :to" do |
|
|
|
|
address = insert(:address) |
|
|
|
|
transaction = :transaction |> insert(to_address: address) |> with_block() |
|
|
|
|
:transaction |> insert(from_address: address) |> with_block() |
|
|
|
|
|
|
|
|
|
# only contains "to" transaction |
|
|
|
|
transaction = |
|
|
|
|
:transaction |
|
|
|
|
|> insert(to_address: address) |
|
|
|
|
|> with_block() |
|
|
|
|
|> Repo.preload(:token_transfers) |
|
|
|
|
|
|
|
|
|
assert [transaction] == |
|
|
|
|
Chain.address_to_transactions(address, direction: :to) |
|
|
|
|
|> Repo.preload([:block, :to_address, :from_address]) |
|
|
|
@ -109,11 +126,22 @@ defmodule Explorer.ChainTest do |
|
|
|
|
test "with to and from transactions and no :direction option" do |
|
|
|
|
address = insert(:address) |
|
|
|
|
block = insert(:block) |
|
|
|
|
transaction1 = :transaction |> insert(to_address: address) |> with_block(block) |
|
|
|
|
transaction2 = :transaction |> insert(from_address: address) |> with_block(block) |
|
|
|
|
|
|
|
|
|
transaction1 = |
|
|
|
|
:transaction |
|
|
|
|
|> insert(to_address: address) |
|
|
|
|
|> with_block(block) |
|
|
|
|
|> Repo.preload(:token_transfers) |
|
|
|
|
|
|
|
|
|
transaction2 = |
|
|
|
|
:transaction |
|
|
|
|
|> insert(from_address: address) |
|
|
|
|
|> with_block(block) |
|
|
|
|
|> Repo.preload(:token_transfers) |
|
|
|
|
|
|
|
|
|
assert [transaction2, transaction1] == |
|
|
|
|
Chain.address_to_transactions(address) |> Repo.preload([:block, :to_address, :from_address]) |
|
|
|
|
Chain.address_to_transactions(address) |
|
|
|
|
|> Repo.preload([:block, :to_address, :from_address]) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "does not include non-contract-creation parent transactions" do |
|
|
|
@ -129,6 +157,82 @@ defmodule Explorer.ChainTest do |
|
|
|
|
assert [] == Chain.address_to_transactions(address) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "returns transactions that have token transfers for the given to_address" do |
|
|
|
|
address = insert(:address) |
|
|
|
|
|
|
|
|
|
transaction = |
|
|
|
|
:transaction |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block() |
|
|
|
|
|
|
|
|
|
insert(:token_transfer, to_address: address, transaction: transaction) |
|
|
|
|
|
|
|
|
|
transaction = |
|
|
|
|
Transaction |
|
|
|
|
|> Repo.get!(transaction.hash) |
|
|
|
|
|> Repo.preload([:block, :to_address, :from_address, token_transfers: :token]) |
|
|
|
|
|
|
|
|
|
assert [transaction.hash] == |
|
|
|
|
Chain.address_to_transactions(address) |
|
|
|
|
|> Enum.map(& &1.hash) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "returns just the token transfers related to the given address" do |
|
|
|
|
address = insert(:address) |
|
|
|
|
|
|
|
|
|
transaction = |
|
|
|
|
:transaction |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block() |
|
|
|
|
|
|
|
|
|
token_transfer = insert(:token_transfer, to_address: address, transaction: transaction) |
|
|
|
|
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] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "returns just the token transfers related to the given contract address" do |
|
|
|
|
contract_address = insert(:address, contract_code: Factory.data("contract_code")) |
|
|
|
|
|
|
|
|
|
transaction = |
|
|
|
|
:transaction |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block() |
|
|
|
|
|
|
|
|
|
token_transfer = insert(:token_transfer, to_address: contract_address, transaction: transaction) |
|
|
|
|
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] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "returns all token transfers when the given address is the token contract address" do |
|
|
|
|
contract_address = insert(:address, contract_code: Factory.data("contract_code")) |
|
|
|
|
|
|
|
|
|
transaction = |
|
|
|
|
:transaction |
|
|
|
|
|> insert(to_address: contract_address) |
|
|
|
|
|> with_block() |
|
|
|
|
|
|
|
|
|
insert( |
|
|
|
|
:token_transfer, |
|
|
|
|
to_address: build(:address), |
|
|
|
|
token_contract_address: contract_address, |
|
|
|
|
transaction: transaction |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
insert( |
|
|
|
|
:token_transfer, |
|
|
|
|
to_address: build(:address), |
|
|
|
|
token_contract_address: contract_address, |
|
|
|
|
transaction: transaction |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
transaction = Chain.address_to_transactions(contract_address) |> List.first() |
|
|
|
|
assert Enum.count(transaction.token_transfers) == 2 |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "with transactions can be paginated" do |
|
|
|
|
address = insert(:address) |
|
|
|
|
|
|
|
|
|