|
|
|
@ -3,7 +3,7 @@ defmodule Explorer.Chain.TokenTransferTest do |
|
|
|
|
|
|
|
|
|
import Explorer.Factory |
|
|
|
|
|
|
|
|
|
alias Explorer.PagingOptions |
|
|
|
|
alias Explorer.{PagingOptions, Repo} |
|
|
|
|
alias Explorer.Chain.TokenTransfer |
|
|
|
|
|
|
|
|
|
doctest Explorer.Chain.TokenTransfer |
|
|
|
@ -142,4 +142,73 @@ defmodule Explorer.Chain.TokenTransferTest do |
|
|
|
|
assert TokenTransfer.count_token_transfers_from_token_hash(token_contract_address.hash) == 2 |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "address_to_unique_tokens/2" do |
|
|
|
|
test "returns list of unique tokens for a token contract" do |
|
|
|
|
token_contract_address = insert(:contract_address) |
|
|
|
|
token = insert(:token, contract_address: token_contract_address, type: "ERC-721") |
|
|
|
|
|
|
|
|
|
transaction = |
|
|
|
|
:transaction |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block(insert(:block, number: 1)) |
|
|
|
|
|
|
|
|
|
insert( |
|
|
|
|
:token_transfer, |
|
|
|
|
to_address: build(:address), |
|
|
|
|
transaction: transaction, |
|
|
|
|
token_contract_address: token_contract_address, |
|
|
|
|
token: token, |
|
|
|
|
token_id: 42 |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
another_transaction = |
|
|
|
|
:transaction |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block(insert(:block, number: 2)) |
|
|
|
|
|
|
|
|
|
last_owner = |
|
|
|
|
insert( |
|
|
|
|
:token_transfer, |
|
|
|
|
to_address: build(:address), |
|
|
|
|
transaction: another_transaction, |
|
|
|
|
token_contract_address: token_contract_address, |
|
|
|
|
token: token, |
|
|
|
|
token_id: 42 |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
results = |
|
|
|
|
token_contract_address.hash |
|
|
|
|
|> TokenTransfer.address_to_unique_tokens() |
|
|
|
|
|> Repo.all() |
|
|
|
|
|
|
|
|
|
assert Enum.map(results, & &1.token_id) == [last_owner.token_id] |
|
|
|
|
assert Enum.map(results, & &1.to_address_hash) == [last_owner.to_address_hash] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "won't return tokens that aren't uniques" do |
|
|
|
|
token_contract_address = insert(:contract_address) |
|
|
|
|
token = insert(:token, contract_address: token_contract_address, type: "ERC-20") |
|
|
|
|
|
|
|
|
|
transaction = |
|
|
|
|
:transaction |
|
|
|
|
|> insert() |
|
|
|
|
|> with_block(insert(:block, number: 1)) |
|
|
|
|
|
|
|
|
|
insert( |
|
|
|
|
:token_transfer, |
|
|
|
|
to_address: build(:address), |
|
|
|
|
transaction: transaction, |
|
|
|
|
token_contract_address: token_contract_address, |
|
|
|
|
token: token |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
results = |
|
|
|
|
token_contract_address.hash |
|
|
|
|
|> TokenTransfer.address_to_unique_tokens() |
|
|
|
|
|> Repo.all() |
|
|
|
|
|
|
|
|
|
assert results == [] |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|