diff --git a/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex b/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex index 6b6301b2f9..beb8dcc824 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex @@ -299,13 +299,21 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do ) do with {:ok, valid_internal_txs} <- valid_internal_transactions(transactions, internal_transactions_params, invalid_block_numbers) do - valid_internal_txs_without_first_trace = - valid_internal_txs - |> Enum.reject(fn trace -> - trace[:index] == 0 && trace[:input] == %Explorer.Chain.Data{bytes: ""} - end) - - {:ok, valid_internal_txs_without_first_trace} + json_rpc_named_arguments = Application.fetch_env!(:indexer, :json_rpc_named_arguments) + variant = Keyword.fetch!(json_rpc_named_arguments, :variant) + + # we exclude first traces from storing in the DB only in case of Parity variant (Parity/Nethermind). todo: to the same for Geth + if variant == EthereumJSONRPC.Parity do + valid_internal_txs_without_first_trace = + valid_internal_txs + |> Enum.reject(fn trace -> + trace[:index] == 0 + end) + + {:ok, valid_internal_txs_without_first_trace} + else + {:ok, valid_internal_txs} + end end end diff --git a/apps/explorer/test/explorer/chain/import/runner/internal_transactions_test.exs b/apps/explorer/test/explorer/chain/import/runner/internal_transactions_test.exs index f2c890850d..c58a0cef05 100644 --- a/apps/explorer/test/explorer/chain/import/runner/internal_transactions_test.exs +++ b/apps/explorer/test/explorer/chain/import/runner/internal_transactions_test.exs @@ -102,22 +102,35 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactionsTest do index = 0 internal_transaction_changes_0 = make_internal_transaction_changes(transaction0, index, nil) + internal_transaction_changes_0_1 = make_internal_transaction_changes(transaction0, 1, nil) internal_transaction_changes_1 = make_internal_transaction_changes_for_simple_coin_transfers(transaction1, index, nil) internal_transaction_changes_2 = make_internal_transaction_changes(transaction2, index, nil) + internal_transaction_changes_2_1 = make_internal_transaction_changes(transaction2, 1, nil) assert {:ok, _} = run_internal_transactions([ internal_transaction_changes_0, + internal_transaction_changes_0_1, internal_transaction_changes_1, - internal_transaction_changes_2 + internal_transaction_changes_2, + internal_transaction_changes_2_1 ]) - assert 0 == Repo.get_by!(InternalTransaction, transaction_hash: transaction0.hash).block_index + assert from(i in InternalTransaction, where: i.transaction_hash == ^transaction0.hash, where: i.index == 0) + |> Repo.one() + |> is_nil() + + assert 1 == Repo.get_by!(InternalTransaction, transaction_hash: transaction0.hash, index: 1).block_index assert from(i in InternalTransaction, where: i.transaction_hash == ^transaction1.hash) |> Repo.one() |> is_nil() - assert 2 == Repo.get_by!(InternalTransaction, transaction_hash: transaction2.hash).block_index + + assert from(i in InternalTransaction, where: i.transaction_hash == ^transaction2.hash, where: i.index == 0) + |> Repo.one() + |> is_nil() + + assert 4 == Repo.get_by!(InternalTransaction, transaction_hash: transaction2.hash, index: 1).block_index end test "simple coin transfer has no internal transaction inserted" do @@ -145,7 +158,7 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactionsTest do assert :ok == transaction.status assert is_nil(pending.block_hash) - index = 0 + index = 1 transaction_changes = make_internal_transaction_changes(transaction, index, nil) pending_changes = make_internal_transaction_changes(pending, index, nil) @@ -176,7 +189,7 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactionsTest do assert full_block.hash == inserted.block_hash - index = 0 + index = 1 pending_transaction_changes = pending @@ -256,17 +269,23 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactionsTest do assert full_block.hash == inserted.block_hash - index = 0 - - transaction_changes = make_internal_transaction_changes(inserted, index, nil) + transaction_changes = make_internal_transaction_changes(inserted, 0, nil) + transaction_changes_2 = make_internal_transaction_changes(inserted, 1, nil) empty_changes = make_empty_block_changes(empty_block.number) - assert {:ok, _} = run_internal_transactions([empty_changes, transaction_changes]) + assert {:ok, _} = run_internal_transactions([empty_changes, transaction_changes, transaction_changes_2]) assert %{consensus: true} = Repo.get(Block, empty_block.hash) assert PendingBlockOperation |> Repo.get(empty_block.hash) |> is_nil() - assert from(i in InternalTransaction, where: i.transaction_hash == ^inserted.hash) |> Repo.one() |> is_nil() == + assert from(i in InternalTransaction, where: i.transaction_hash == ^inserted.hash, where: i.index == 0) + |> Repo.one() + |> is_nil() == + true + + assert from(i in InternalTransaction, where: i.transaction_hash == ^inserted.hash, where: i.index == 1) + |> Repo.one() + |> is_nil() == false assert %{consensus: true} = Repo.get(Block, full_block.hash) diff --git a/apps/explorer/test/explorer/chain/import_test.exs b/apps/explorer/test/explorer/chain/import_test.exs index 30e8a08e57..f96a536526 100644 --- a/apps/explorer/test/explorer/chain/import_test.exs +++ b/apps/explorer/test/explorer/chain/import_test.exs @@ -252,15 +252,6 @@ defmodule Explorer.Chain.ImportTest do } ], internal_transactions: [ - %{ - index: 0, - transaction_hash: %Hash{ - byte_count: 32, - bytes: - <<83, 189, 136, 72, 114, 222, 62, 72, 134, 146, 136, 27, 174, 236, 38, 46, 123, 149, 35, 77, 57, - 101, 36, 140, 57, 254, 153, 47, 255, 212, 51, 229>> - } - }, %{ index: 1, transaction_hash: %Hash{ @@ -485,8 +476,7 @@ defmodule Explorer.Chain.ImportTest do Subscriber.to(:internal_transactions, :realtime) Import.all(@import_data) - assert_receive {:chain_event, :internal_transactions, :realtime, - [%{transaction_hash: _, index: _}, %{transaction_hash: _, index: _}]} + assert_receive {:chain_event, :internal_transactions, :realtime, [%{transaction_hash: _, index: _}]} end test "publishes transactions data to subscribers on insert" do diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index 81a7fd35d8..c131bacc92 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -1562,17 +1562,7 @@ defmodule Explorer.ChainTest do updated_at: %{} } ], - internal_transactions: [ - %{ - index: 0, - transaction_hash: %Hash{ - byte_count: 32, - bytes: - <<83, 189, 136, 72, 114, 222, 62, 72, 134, 146, 136, 27, 174, 236, 38, 46, 123, 149, 35, 77, 57, - 101, 36, 140, 57, 254, 153, 47, 255, 212, 51, 229>> - } - } - ], + internal_transactions: [], logs: [ %Log{ address_hash: %Hash{ diff --git a/apps/indexer/config/test.exs b/apps/indexer/config/test.exs index fb54d51ab2..e74b5e1abf 100644 --- a/apps/indexer/config/test.exs +++ b/apps/indexer/config/test.exs @@ -20,3 +20,17 @@ config :logger, :addresses_without_code, level: :debug, path: Path.absname("logs/test/indexer/addresses_without_code.log"), metadata_filter: [fetcher: :addresses_without_code] + +variant = + if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do + "parity" + else + System.get_env("ETHEREUM_JSONRPC_VARIANT") + |> String.split(".") + |> List.last() + |> String.downcase() + end + +# Import variant specific config. This must remain at the bottom +# of this file so it overrides the configuration defined above. +import_config "test/#{variant}.exs" diff --git a/apps/indexer/config/test/ganache.exs b/apps/indexer/config/test/ganache.exs new file mode 100644 index 0000000000..b421779152 --- /dev/null +++ b/apps/indexer/config/test/ganache.exs @@ -0,0 +1,8 @@ +use Mix.Config + +config :indexer, + json_rpc_named_arguments: [ + transport: EthereumJSONRPC.Mox, + transport_options: [], + variant: EthereumJSONRPC.Ganache + ] diff --git a/apps/indexer/config/test/geth.exs b/apps/indexer/config/test/geth.exs new file mode 100644 index 0000000000..7c4b58b31a --- /dev/null +++ b/apps/indexer/config/test/geth.exs @@ -0,0 +1,8 @@ +use Mix.Config + +config :indexer, + json_rpc_named_arguments: [ + transport: EthereumJSONRPC.Mox, + transport_options: [], + variant: EthereumJSONRPC.Geth + ] diff --git a/apps/indexer/config/test/parity.exs b/apps/indexer/config/test/parity.exs new file mode 100644 index 0000000000..af3c396e9a --- /dev/null +++ b/apps/indexer/config/test/parity.exs @@ -0,0 +1,8 @@ +use Mix.Config + +config :indexer, + json_rpc_named_arguments: [ + transport: EthereumJSONRPC.Mox, + transport_options: [], + variant: EthereumJSONRPC.Parity + ] diff --git a/apps/indexer/config/test/rsk.exs b/apps/indexer/config/test/rsk.exs new file mode 100644 index 0000000000..15e2768fc7 --- /dev/null +++ b/apps/indexer/config/test/rsk.exs @@ -0,0 +1,8 @@ +use Mix.Config + +config :indexer, + json_rpc_named_arguments: [ + transport: EthereumJSONRPC.Mox, + transport_options: [], + variant: EthereumJSONRPC.RSK + ] diff --git a/apps/indexer/test/indexer/fetcher/internal_transaction_test.exs b/apps/indexer/test/indexer/fetcher/internal_transaction_test.exs index 0486f7c8eb..770c208269 100644 --- a/apps/indexer/test/indexer/fetcher/internal_transaction_test.exs +++ b/apps/indexer/test/indexer/fetcher/internal_transaction_test.exs @@ -210,9 +210,26 @@ defmodule Indexer.Fetcher.InternalTransactionTest do "value" => "0x174876e800" }, "result" => %{"gasUsed" => "0x7d37", "output" => "0x"}, - "subtraces" => 0, + "subtraces" => 1, "traceAddress" => [], "type" => "call" + }, + %{ + "action" => %{ + "callType" => "call", + "from" => "0xb37b428a7ddee91f39b26d79d23dc1c89e3e12a7", + "gas" => "0x32dcf", + "input" => "0x42dad49e", + "to" => "0xee4019030fb5c2b68c42105552c6268d56c6cbfe", + "value" => "0x0" + }, + "result" => %{ + "gasUsed" => "0xb08", + "output" => "0x" + }, + "subtraces" => 0, + "traceAddress" => [0], + "type" => "call" } ], "transactionHash" => transaction.hash,