pull/3902/head
Ayrat Badykov 5 years ago committed by Viktor Baranov
parent 307538af2c
commit 9386adfb0b
  1. 8
      apps/explorer/test/explorer/chain/import/runner/address/token_balances_test.exs
  2. 16
      apps/explorer/test/explorer/chain/import_test.exs
  3. 6
      apps/explorer/test/explorer/token/balance_reader_test.exs
  4. 3
      apps/explorer/test/support/factory.ex
  5. 2
      apps/indexer/lib/indexer/token_balances.ex
  6. 24
      apps/indexer/test/indexer/fetcher/token_balance_test.exs
  7. 8
      apps/indexer/test/indexer/token_balances_test.exs
  8. 11
      apps/indexer/test/indexer/transform/address_token_balances_test.exs
  9. 8
      apps/indexer/test/indexer/transform/token_transfers_test.exs

@ -29,7 +29,9 @@ defmodule Explorer.Chain.Import.Runner.Address.TokenBalancesTest do
block_number: block_number, block_number: block_number,
token_contract_address_hash: token_contract_address_hash, token_contract_address_hash: token_contract_address_hash,
value: value, value: value,
value_fetched_at: value_fetched_at value_fetched_at: value_fetched_at,
token_id: 11,
token_type: "ERC-20"
} }
assert {:ok, assert {:ok,
@ -69,7 +71,9 @@ defmodule Explorer.Chain.Import.Runner.Address.TokenBalancesTest do
block_number: block_number, block_number: block_number,
token_contract_address_hash: token_contract_address_hash, token_contract_address_hash: token_contract_address_hash,
value: nil, value: nil,
value_fetched_at: value_fetched_at value_fetched_at: value_fetched_at,
token_id: 11,
token_type: "ERC-20"
} }
assert {:ok, assert {:ok,

@ -375,17 +375,20 @@ defmodule Explorer.Chain.ImportTest do
%{ %{
address_hash: "0xe8ddc5c7a2d2f0d7a9798459c0104fdf5e987aca", address_hash: "0xe8ddc5c7a2d2f0d7a9798459c0104fdf5e987aca",
token_contract_address_hash: "0x8bf38d4764929064f2d4d3a56520a76ab3df415b", token_contract_address_hash: "0x8bf38d4764929064f2d4d3a56520a76ab3df415b",
block_number: "37" block_number: "37",
token_type: "ERC-20"
}, },
%{ %{
address_hash: "0x515c09c5bba1ed566b02a5b0599ec5d5d0aee73d", address_hash: "0x515c09c5bba1ed566b02a5b0599ec5d5d0aee73d",
token_contract_address_hash: "0x8bf38d4764929064f2d4d3a56520a76ab3df415b", token_contract_address_hash: "0x8bf38d4764929064f2d4d3a56520a76ab3df415b",
block_number: "37" block_number: "37",
token_type: "ERC-20"
}, },
%{ %{
address_hash: "0x8bf38d4764929064f2d4d3a56520a76ab3df415b", address_hash: "0x8bf38d4764929064f2d4d3a56520a76ab3df415b",
token_contract_address_hash: "0x8bf38d4764929064f2d4d3a56520a76ab3df415b", token_contract_address_hash: "0x8bf38d4764929064f2d4d3a56520a76ab3df415b",
block_number: "37" block_number: "37",
token_type: "ERC-20"
} }
], ],
timeout: 5 timeout: 5
@ -1564,8 +1567,8 @@ defmodule Explorer.Chain.ImportTest do
}, },
address_coin_balances: %{ address_coin_balances: %{
params: [ params: [
%{address_hash: miner_hash, block_number: block_number, value: nil}, %{address_hash: miner_hash, block_number: block_number, value: nil, token_type: "ERC-20"},
%{address_hash: uncle_miner_hash, block_number: block_number, value: nil} %{address_hash: uncle_miner_hash, block_number: block_number, value: nil, token_type: "ERC-20"}
], ],
timeout: 1 timeout: 1
}, },
@ -2250,7 +2253,8 @@ defmodule Explorer.Chain.ImportTest do
address_hash: address_hash, address_hash: address_hash,
token_contract_address_hash: token_contract_address_hash, token_contract_address_hash: token_contract_address_hash,
block_number: block_number, block_number: block_number,
value: value_after value: value_after,
token_type: "ERC-20"
} }
] ]
}, },

@ -32,7 +32,8 @@ defmodule Explorer.Token.BalanceReaderTest do
%{ %{
token_contract_address_hash: token_contract_address_hash, token_contract_address_hash: token_contract_address_hash,
address_hash: address_hash, address_hash: address_hash,
block_number: block_number block_number: block_number,
token_type: "ERC-20"
} }
]) ])
@ -51,7 +52,8 @@ defmodule Explorer.Token.BalanceReaderTest do
%{ %{
token_contract_address_hash: token_contract_address_hash, token_contract_address_hash: token_contract_address_hash,
address_hash: address_hash, address_hash: address_hash,
block_number: block_number block_number: block_number,
token_type: "ERC-20"
} }
]) ])

@ -586,7 +586,8 @@ defmodule Explorer.Factory do
token_contract_address_hash: insert(:token).contract_address_hash, token_contract_address_hash: insert(:token).contract_address_hash,
block_number: block_number(), block_number: block_number(),
value: Enum.random(1..100_000), value: Enum.random(1..100_000),
value_fetched_at: DateTime.utc_now() value_fetched_at: DateTime.utc_now(),
token_type: "ERC-20"
} }
end end

@ -26,6 +26,8 @@ defmodule Indexer.TokenBalances do
* `token_contract_address_hash` - The contract address that represents the Token in the blockchain. * `token_contract_address_hash` - The contract address that represents the Token in the blockchain.
* `address_hash` - The address_hash that we want to know the balance. * `address_hash` - The address_hash that we want to know the balance.
* `block_number` - The block number that the address_hash has the balance. * `block_number` - The block number that the address_hash has the balance.
* `token_type` - type of the token that balance belongs to
* `token_id` - token id for ERC-1155 tokens
""" """
def fetch_token_balances_from_blockchain([]), do: {:ok, []} def fetch_token_balances_from_blockchain([]), do: {:ok, []}

@ -23,7 +23,7 @@ defmodule Indexer.Fetcher.TokenBalanceTest do
insert(:token_balance, value_fetched_at: DateTime.utc_now()) insert(:token_balance, value_fetched_at: DateTime.utc_now())
assert TokenBalance.init([], &[&1 | &2], nil) == [ assert TokenBalance.init([], &[&1 | &2], nil) == [
{address_hash_bytes, token_contract_address_hash_bytes, block_number, 0} {address_hash_bytes, token_contract_address_hash_bytes, 1000, "ERC-20", nil, 0}
] ]
end end
end end
@ -58,7 +58,7 @@ defmodule Indexer.Fetcher.TokenBalanceTest do
) )
assert TokenBalance.run( assert TokenBalance.run(
[{address_hash_bytes, token_contract_address_hash_bytes, block_number, 0}], [{address_hash_bytes, token_contract_address_hash_bytes, block_number, "ERC-20", nil, 0}],
nil nil
) == :ok ) == :ok
@ -96,6 +96,8 @@ defmodule Indexer.Fetcher.TokenBalanceTest do
{ {
token_balance_a.address_hash.bytes, token_balance_a.address_hash.bytes,
token_balance_a.token_contract_address_hash.bytes, token_balance_a.token_contract_address_hash.bytes,
"ERC-20",
nil,
token_balance_a.block_number, token_balance_a.block_number,
# this token balance must be ignored # this token balance must be ignored
max_retries max_retries
@ -103,6 +105,8 @@ defmodule Indexer.Fetcher.TokenBalanceTest do
{ {
token_balance_b.address_hash.bytes, token_balance_b.address_hash.bytes,
token_balance_b.token_contract_address_hash.bytes, token_balance_b.token_contract_address_hash.bytes,
"ERC-20",
nil,
token_balance_b.block_number, token_balance_b.block_number,
# this token balance still have to be retried # this token balance still have to be retried
max_retries - 2 max_retries - 2
@ -136,8 +140,8 @@ defmodule Indexer.Fetcher.TokenBalanceTest do
assert TokenBalance.run( assert TokenBalance.run(
[ [
{address_hash_bytes, token_contract_address_hash_bytes, block_number, 0}, {address_hash_bytes, token_contract_address_hash_bytes, block_number, "ERC-20", nil, 0},
{address_hash_bytes, token_contract_address_hash_bytes, block_number, 0} {address_hash_bytes, token_contract_address_hash_bytes, block_number, "ERC-20", nil, 0}
], ],
nil nil
) == :ok ) == :ok
@ -177,7 +181,9 @@ defmodule Indexer.Fetcher.TokenBalanceTest do
%{ %{
address_hash: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", address_hash: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
block_number: 19999, block_number: 19999,
token_contract_address_hash: to_string(contract.contract_address_hash) token_contract_address_hash: to_string(contract.contract_address_hash),
token_type: "ERC-20",
token_id: nil
} }
] ]
@ -195,12 +201,16 @@ defmodule Indexer.Fetcher.TokenBalanceTest do
%{ %{
address_hash: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", address_hash: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
block_number: 19999, block_number: 19999,
token_contract_address_hash: to_string(contract.contract_address_hash) token_contract_address_hash: to_string(contract.contract_address_hash),
token_id: 11,
token_type: "ERC-20"
}, },
%{ %{
address_hash: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", address_hash: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
block_number: 19999, block_number: 19999,
token_contract_address_hash: to_string(contract2.contract_address_hash) token_contract_address_hash: to_string(contract2.contract_address_hash),
token_id: 11,
token_type: "ERC-20"
} }
] ]

@ -29,7 +29,9 @@ defmodule Indexer.TokenBalancesTest do
data = %{ data = %{
token_contract_address_hash: Hash.to_string(token.contract_address_hash), token_contract_address_hash: Hash.to_string(token.contract_address_hash),
address_hash: address_hash_string, address_hash: address_hash_string,
block_number: 1_000 block_number: 1_000,
token_id: 11,
token_type: "ERC-20"
} }
get_balance_from_blockchain() get_balance_from_blockchain()
@ -54,7 +56,9 @@ defmodule Indexer.TokenBalancesTest do
address_hash: to_string(address.hash), address_hash: to_string(address.hash),
block_number: 1_000, block_number: 1_000,
token_contract_address_hash: to_string(token.contract_address_hash), token_contract_address_hash: to_string(token.contract_address_hash),
retries_count: 1 retries_count: 1,
token_id: 11,
token_type: "ERC-20"
} }
] ]

@ -24,7 +24,9 @@ defmodule Indexer.Transform.AddressTokenBalancesTest do
block_number: block_number, block_number: block_number,
from_address_hash: from_address_hash, from_address_hash: from_address_hash,
to_address_hash: to_address_hash, to_address_hash: to_address_hash,
token_contract_address_hash: token_contract_address_hash token_contract_address_hash: token_contract_address_hash,
token_id: nil,
token_type: "ERC-20"
} }
params_set = AddressTokenBalances.params_set(%{token_transfers_params: [token_transfer_params]}) params_set = AddressTokenBalances.params_set(%{token_transfers_params: [token_transfer_params]})
@ -46,7 +48,8 @@ defmodule Indexer.Transform.AddressTokenBalancesTest do
from_address_hash: from_address_hash, from_address_hash: from_address_hash,
to_address_hash: to_address_hash, to_address_hash: to_address_hash,
token_contract_address_hash: token_contract_address_hash, token_contract_address_hash: token_contract_address_hash,
token_type: "ERC-721" token_type: "ERC-721",
token_id: nil
} }
params_set = AddressTokenBalances.params_set(%{token_transfers_params: [token_transfer_params]}) params_set = AddressTokenBalances.params_set(%{token_transfers_params: [token_transfer_params]})
@ -56,7 +59,9 @@ defmodule Indexer.Transform.AddressTokenBalancesTest do
%{ %{
address_hash: "0x5b8410f67eb8040bb1cd1e8a4ff9d5f6ce678a15", address_hash: "0x5b8410f67eb8040bb1cd1e8a4ff9d5f6ce678a15",
block_number: 1, block_number: 1,
token_contract_address_hash: "0xe18035bf8712672935fdb4e5e431b1a0183d2dfc" token_contract_address_hash: "0xe18035bf8712672935fdb4e5e431b1a0183d2dfc",
token_id: nil,
token_type: "ERC-721"
} }
]) ])
end end

@ -198,18 +198,14 @@ defmodule Indexer.Transform.TokenTransfersTest do
log_index: 2, log_index: 2,
to_address_hash: "0x6c943470780461b00783ad530a53913bd2c104d3", to_address_hash: "0x6c943470780461b00783ad530a53913bd2c104d3",
token_contract_address_hash: "0x58Ab73CB79c8275628E0213742a85B163fE0A9Fb", token_contract_address_hash: "0x58Ab73CB79c8275628E0213742a85B163fE0A9Fb",
token_id: nil,
token_ids: [680_564_733_841_876_926_926_749_214_863_536_422_912], token_ids: [680_564_733_841_876_926_926_749_214_863_536_422_912],
token_type: "ERC-1155", token_type: "ERC-1155",
transaction_hash: "0x6d2dd62c178e55a13b65601f227c4ffdd8aa4e3bcb1f24731363b4f7619e92c8", transaction_hash: "0x6d2dd62c178e55a13b65601f227c4ffdd8aa4e3bcb1f24731363b4f7619e92c8",
values: [5000] values: [5000]
} }
], ],
tokens: [ tokens: [%{contract_address_hash: "0x58Ab73CB79c8275628E0213742a85B163fE0A9Fb", type: "ERC-1155"}]
%{
contract_address_hash: "0x58Ab73CB79c8275628E0213742a85B163fE0A9Fb",
type: "ERC-1155"
}
]
} }
end end

Loading…
Cancel
Save