|
|
@ -1598,59 +1598,11 @@ defmodule Explorer.EtherscanTest do |
|
|
|
address = insert(:address) |
|
|
|
address = insert(:address) |
|
|
|
|
|
|
|
|
|
|
|
token_balance = |
|
|
|
token_balance = |
|
|
|
:token_balance |
|
|
|
:address_current_token_balance |
|
|
|
|> insert(address: address) |
|
|
|
|> insert(address: address) |
|
|
|
|> Repo.preload(:token) |
|
|
|
|> Repo.preload(:token) |
|
|
|
|
|
|
|
|
|
|
|
insert(:token_balance, address: build(:address)) |
|
|
|
insert(:address_current_token_balance, address: build(:address)) |
|
|
|
|
|
|
|
|
|
|
|
token_list = Etherscan.list_tokens(address.hash) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expected_tokens = [ |
|
|
|
|
|
|
|
%{ |
|
|
|
|
|
|
|
balance: token_balance.value, |
|
|
|
|
|
|
|
contract_address_hash: token_balance.token_contract_address_hash, |
|
|
|
|
|
|
|
name: token_balance.token.name, |
|
|
|
|
|
|
|
decimals: token_balance.token.decimals, |
|
|
|
|
|
|
|
symbol: token_balance.token.symbol, |
|
|
|
|
|
|
|
type: token_balance.token.type |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert token_list == expected_tokens |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test "returns the latest known balance per token" do |
|
|
|
|
|
|
|
# The latest balance is the one with the latest block number |
|
|
|
|
|
|
|
address = insert(:address) |
|
|
|
|
|
|
|
token = insert(:token) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
token_balance_details1 = %{ |
|
|
|
|
|
|
|
address: address, |
|
|
|
|
|
|
|
token_contract_address_hash: token.contract_address.hash, |
|
|
|
|
|
|
|
block_number: 1 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
token_balance_details2 = %{ |
|
|
|
|
|
|
|
address: address, |
|
|
|
|
|
|
|
token_contract_address_hash: token.contract_address.hash, |
|
|
|
|
|
|
|
block_number: 2 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
token_balance_details3 = %{ |
|
|
|
|
|
|
|
address: address, |
|
|
|
|
|
|
|
token_contract_address_hash: token.contract_address.hash, |
|
|
|
|
|
|
|
block_number: 3 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
insert(:token_balance, token_balance_details1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
token_balance = |
|
|
|
|
|
|
|
:token_balance |
|
|
|
|
|
|
|
|> insert(token_balance_details3) |
|
|
|
|
|
|
|
|> Repo.preload(:token) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
insert(:token_balance, token_balance_details2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
token_list = Etherscan.list_tokens(address.hash) |
|
|
|
token_list = Etherscan.list_tokens(address.hash) |
|
|
|
|
|
|
|
|
|
|
|