From 35c4aed09e41d0f9a1f8028e1c75fee66881460b Mon Sep 17 00:00:00 2001 From: Tim Mecklem Date: Wed, 23 May 2018 15:30:12 -0400 Subject: [PATCH] Make index a required argument for internal transaction factory This removes the possibility of accidentally creating an invalid `InternalTransaction` record with a duplicate index at the cost of requiring test writers to think about the index of each internal transaction they create. --- apps/explorer/test/explorer/chain_test.exs | 4 ++-- apps/explorer/test/explorer/indexer/block_fetcher_test.exs | 2 +- apps/explorer/test/support/factory.ex | 1 - .../test/explorer_web/features/viewing_transactions_test.exs | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index 2a0b86fa12..d0769ee2d2 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -615,7 +615,7 @@ defmodule Explorer.ChainTest do address = insert(:address) block = insert(:block) transaction = insert(:transaction, block_hash: block.hash, index: 0, to_address_hash: address.hash) - insert(:internal_transaction, transaction_hash: transaction.hash, to_address_hash: address.hash) + insert(:internal_transaction, index: 0, to_address_hash: address.hash, transaction_hash: transaction.hash) assert %{entries: []} = Chain.address_to_internal_transactions(address) end @@ -686,7 +686,7 @@ defmodule Explorer.ChainTest do test "excludes internal transaction with no siblings in the transaction" do block = insert(:block) %Transaction{hash: hash} = insert(:transaction, block_hash: block.hash, index: 0) - insert(:internal_transaction, transaction_hash: hash) + insert(:internal_transaction, transaction_hash: hash, index: 0) result = hash diff --git a/apps/explorer/test/explorer/indexer/block_fetcher_test.exs b/apps/explorer/test/explorer/indexer/block_fetcher_test.exs index 39f1e74eab..545018f505 100644 --- a/apps/explorer/test/explorer/indexer/block_fetcher_test.exs +++ b/apps/explorer/test/explorer/indexer/block_fetcher_test.exs @@ -52,7 +52,7 @@ defmodule Explorer.Indexer.BlockFetcherTest do transaction = insert(:transaction, block_hash: block.hash, index: index) receipt = insert(:receipt, transaction_hash: transaction.hash, transaction_index: transaction.index) insert(:log, transaction_hash: receipt.transaction_hash) - insert(:internal_transaction, transaction_hash: transaction.hash) + insert(:internal_transaction, transaction_hash: transaction.hash, index: 0) end) :ok diff --git a/apps/explorer/test/support/factory.ex b/apps/explorer/test/support/factory.ex index 989ae2ccc9..4c92eb5dff 100644 --- a/apps/explorer/test/support/factory.ex +++ b/apps/explorer/test/support/factory.ex @@ -178,7 +178,6 @@ defmodule Explorer.Factory do from_address_hash: insert(:address).hash, gas: gas, gas_used: gas_used, - index: 0, # caller MUST suppy `index` init: data(:internal_transaction_init), trace_address: [], diff --git a/apps/explorer_web/test/explorer_web/features/viewing_transactions_test.exs b/apps/explorer_web/test/explorer_web/features/viewing_transactions_test.exs index bbec730ab1..0a16ae704f 100644 --- a/apps/explorer_web/test/explorer_web/features/viewing_transactions_test.exs +++ b/apps/explorer_web/test/explorer_web/features/viewing_transactions_test.exs @@ -52,7 +52,7 @@ defmodule ExplorerWeb.ViewingTransactionsTest do internal_receipt = insert(:receipt, transaction_hash: txn_from_lincoln.hash, transaction_index: txn_from_lincoln.index) - internal = insert(:internal_transaction, transaction_hash: internal_receipt.transaction_hash) + internal = insert(:internal_transaction, index: 0, transaction_hash: internal_receipt.transaction_hash) Credit.refresh() Debit.refresh()