Update address extraction testcases

pull/1140/head
svenski123 6 years ago committed by Amanda Sposito
parent 29199eb54e
commit 3b45474e36
  1. 21
      apps/indexer/lib/indexer/address_extraction.ex
  2. 16
      apps/indexer/test/indexer/address_extraction_test.exs

@ -285,11 +285,13 @@ defmodule Indexer.AddressExtraction do
...> transactions: [
...> %{
...> block_number: 3,
...> to_address_hash: "0x0000000000000000000000000000000000000001"
...> to_address_hash: "0x0000000000000000000000000000000000000001",
...> nonce: 5
...> },
...> %{
...> block_number: 2,
...> from_address_hash: "0x0000000000000000000000000000000000000001"
...> from_address_hash: "0x0000000000000000000000000000000000000001",
...> nonce: 4
...> }
...> ],
...> logs: [
@ -303,7 +305,8 @@ defmodule Indexer.AddressExtraction do
[
%{
fetched_coin_balance_block_number: 7,
hash: "0x0000000000000000000000000000000000000001"
hash: "0x0000000000000000000000000000000000000001",
nonce: 4
}
]
@ -322,11 +325,13 @@ defmodule Indexer.AddressExtraction do
...> transactions: [
...> %{
...> block_number: 2,
...> from_address_hash: "0x0000000000000000000000000000000000000001"
...> from_address_hash: "0x0000000000000000000000000000000000000001",
...> nonce: 4
...> },
...> %{
...> block_number: 3,
...> to_address_hash: "0x0000000000000000000000000000000000000001"
...> to_address_hash: "0x0000000000000000000000000000000000000001",
...> nonce: 5
...> }
...> ]
...> }
@ -335,7 +340,8 @@ defmodule Indexer.AddressExtraction do
%{
contract_code: "0x",
fetched_coin_balance_block_number: 3,
hash: "0x0000000000000000000000000000000000000001"
hash: "0x0000000000000000000000000000000000000001",
nonce: 4
}
]
@ -452,6 +458,7 @@ defmodule Indexer.AddressExtraction do
# Ensure that when `:addresses` or `:address_coin_balances` are present, their :fetched_coin_balance will win
defp merge_addresses(%{hash: hash} = first, %{hash: hash} = second) do
merged_addresses =
case {first[:fetched_coin_balance], second[:fetched_coin_balance]} do
{nil, nil} ->
first
@ -484,6 +491,8 @@ defmodule Indexer.AddressExtraction do
Map.merge(first, second)
end
end
merged_addresses
|> Map.put(:nonce, max_nil_last(first[:nonce], second[:nonce]))
end

@ -76,7 +76,8 @@ defmodule Indexer.AddressExtractionTest do
%{
fetched_coin_balance_block_number: 2,
contract_code: "0x1",
hash: "0x0000000000000000000000000000000000000001"
hash: "0x0000000000000000000000000000000000000001",
nonce: nil
}
]
end
@ -95,7 +96,8 @@ defmodule Indexer.AddressExtractionTest do
transaction = %{
block_number: 3,
from_address_hash: gen_hash(),
to_address_hash: gen_hash()
to_address_hash: gen_hash(),
nonce: 7
}
log = %{address_hash: gen_hash(), block_number: 4}
@ -136,7 +138,11 @@ defmodule Indexer.AddressExtractionTest do
contract_code: internal_transaction.created_contract_code,
fetched_coin_balance_block_number: internal_transaction.block_number
},
%{hash: transaction.from_address_hash, fetched_coin_balance_block_number: transaction.block_number},
%{
hash: transaction.from_address_hash,
fetched_coin_balance_block_number: transaction.block_number,
nonce: 7
},
%{hash: transaction.to_address_hash, fetched_coin_balance_block_number: transaction.block_number},
%{hash: log.address_hash, fetched_coin_balance_block_number: log.block_number},
%{
@ -176,7 +182,7 @@ defmodule Indexer.AddressExtractionTest do
blockchain_data = %{
blocks: [%{miner_hash: hash, number: 34}],
transactions: [%{block_number: 34, from_address_hash: hash}],
transactions: [%{block_number: 34, from_address_hash: hash, nonce: 12}],
internal_transactions: [
%{
block_number: 34,
@ -188,7 +194,7 @@ defmodule Indexer.AddressExtractionTest do
assert AddressExtraction.extract_addresses(blockchain_data) ==
[
%{hash: hash, fetched_coin_balance_block_number: 34, contract_code: "code"}
%{hash: hash, fetched_coin_balance_block_number: 34, contract_code: "code", nonce: 12}
]
end

Loading…
Cancel
Save