|
|
@ -65,6 +65,129 @@ defmodule Explorer.Chain.Import.Runner.Address.CurrentTokenBalancesTest do |
|
|
|
assert current_token_balances == 1 |
|
|
|
assert current_token_balances == 1 |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test "inserts values for multiple token IDs in the current token balances", %{ |
|
|
|
|
|
|
|
address: %Address{hash: address_hash}, |
|
|
|
|
|
|
|
token: %Token{contract_address_hash: token_contract_address_hash}, |
|
|
|
|
|
|
|
options: options |
|
|
|
|
|
|
|
} do |
|
|
|
|
|
|
|
value_1 = Decimal.new(111) |
|
|
|
|
|
|
|
token_id_1 = Decimal.new(1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
value_2 = Decimal.new(222) |
|
|
|
|
|
|
|
token_id_2 = Decimal.new(2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
token_erc_20 = insert(:token, holder_count: 0) |
|
|
|
|
|
|
|
token_erc_20_contract_address_hash = token_erc_20.contract_address_hash |
|
|
|
|
|
|
|
value_3 = Decimal.new(333) |
|
|
|
|
|
|
|
token_id_3 = nil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
token_erc_721 = insert(:token, holder_count: 0) |
|
|
|
|
|
|
|
token_erc_721_contract_address_hash = token_erc_721.contract_address_hash |
|
|
|
|
|
|
|
value_4 = Decimal.new(1) |
|
|
|
|
|
|
|
token_id_4 = Decimal.new(1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
block_number = 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, |
|
|
|
|
|
|
|
%{ |
|
|
|
|
|
|
|
address_current_token_balances: [ |
|
|
|
|
|
|
|
%Explorer.Chain.Address.CurrentTokenBalance{ |
|
|
|
|
|
|
|
address_hash: ^address_hash, |
|
|
|
|
|
|
|
block_number: ^block_number, |
|
|
|
|
|
|
|
token_contract_address_hash: ^token_erc_20_contract_address_hash, |
|
|
|
|
|
|
|
value: ^value_3, |
|
|
|
|
|
|
|
token_id: ^token_id_3 |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
%Explorer.Chain.Address.CurrentTokenBalance{ |
|
|
|
|
|
|
|
address_hash: ^address_hash, |
|
|
|
|
|
|
|
block_number: ^block_number, |
|
|
|
|
|
|
|
token_contract_address_hash: ^token_contract_address_hash, |
|
|
|
|
|
|
|
value: ^value_2, |
|
|
|
|
|
|
|
token_id: ^token_id_2 |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
%Explorer.Chain.Address.CurrentTokenBalance{ |
|
|
|
|
|
|
|
address_hash: ^address_hash, |
|
|
|
|
|
|
|
block_number: ^block_number, |
|
|
|
|
|
|
|
token_contract_address_hash: ^token_contract_address_hash, |
|
|
|
|
|
|
|
value: ^value_1, |
|
|
|
|
|
|
|
token_id: ^token_id_1 |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
%Explorer.Chain.Address.CurrentTokenBalance{ |
|
|
|
|
|
|
|
address_hash: ^address_hash, |
|
|
|
|
|
|
|
block_number: ^block_number, |
|
|
|
|
|
|
|
token_contract_address_hash: ^token_erc_721_contract_address_hash, |
|
|
|
|
|
|
|
value: ^value_4, |
|
|
|
|
|
|
|
token_id: ^token_id_4 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
address_current_token_balances_update_token_holder_counts: [ |
|
|
|
|
|
|
|
%{ |
|
|
|
|
|
|
|
contract_address_hash: ^token_contract_address_hash, |
|
|
|
|
|
|
|
holder_count: 2 |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
%{ |
|
|
|
|
|
|
|
contract_address_hash: ^token_erc_20_contract_address_hash, |
|
|
|
|
|
|
|
holder_count: 1 |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
%{ |
|
|
|
|
|
|
|
contract_address_hash: ^token_erc_721_contract_address_hash, |
|
|
|
|
|
|
|
holder_count: 1 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}} = |
|
|
|
|
|
|
|
run_changes_list( |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
%{ |
|
|
|
|
|
|
|
address_hash: address_hash, |
|
|
|
|
|
|
|
block_number: block_number, |
|
|
|
|
|
|
|
token_contract_address_hash: token_contract_address_hash, |
|
|
|
|
|
|
|
value: value_1, |
|
|
|
|
|
|
|
value_fetched_at: DateTime.utc_now(), |
|
|
|
|
|
|
|
token_id: token_id_1, |
|
|
|
|
|
|
|
token_type: "ERC-1155" |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
%{ |
|
|
|
|
|
|
|
address_hash: address_hash, |
|
|
|
|
|
|
|
block_number: block_number, |
|
|
|
|
|
|
|
token_contract_address_hash: token_contract_address_hash, |
|
|
|
|
|
|
|
value: value_2, |
|
|
|
|
|
|
|
value_fetched_at: DateTime.utc_now(), |
|
|
|
|
|
|
|
token_id: token_id_2, |
|
|
|
|
|
|
|
token_type: "ERC-1155" |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
%{ |
|
|
|
|
|
|
|
address_hash: address_hash, |
|
|
|
|
|
|
|
block_number: block_number, |
|
|
|
|
|
|
|
token_contract_address_hash: token_erc_20.contract_address_hash, |
|
|
|
|
|
|
|
value: value_3, |
|
|
|
|
|
|
|
value_fetched_at: DateTime.utc_now(), |
|
|
|
|
|
|
|
token_id: token_id_3, |
|
|
|
|
|
|
|
token_type: "ERC-20" |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
%{ |
|
|
|
|
|
|
|
address_hash: address_hash, |
|
|
|
|
|
|
|
block_number: block_number, |
|
|
|
|
|
|
|
token_contract_address_hash: token_erc_721.contract_address_hash, |
|
|
|
|
|
|
|
value: value_4, |
|
|
|
|
|
|
|
value_fetched_at: DateTime.utc_now(), |
|
|
|
|
|
|
|
token_id: token_id_4, |
|
|
|
|
|
|
|
token_type: "ERC-721" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
options |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
current_token_balances = |
|
|
|
|
|
|
|
CurrentTokenBalance |
|
|
|
|
|
|
|
|> Repo.all() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
current_token_balances_count = |
|
|
|
|
|
|
|
current_token_balances |
|
|
|
|
|
|
|
|> Enum.count() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert current_token_balances_count == 4 |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "updates when the new block number is greater", %{ |
|
|
|
test "updates when the new block number is greater", %{ |
|
|
|
address: address, |
|
|
|
address: address, |
|
|
|
token: token, |
|
|
|
token: token, |
|
|
|