diff --git a/apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex index 40d0e981c0..4d88f14ceb 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex @@ -19,8 +19,8 @@
<%= link( - gettext("Block #%{number}", number: to_string(@internal_transaction.transaction.block_number)), - to: block_path(BlockScoutWeb.Endpoint, :show, @internal_transaction.transaction.block) + gettext("Block #%{number}", number: to_string(@internal_transaction.block_number)), + to: block_path(BlockScoutWeb.Endpoint, :show, @internal_transaction.block_number) ) %> diff --git a/apps/block_scout_web/test/block_scout_web/controllers/address_internal_transaction_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/address_internal_transaction_controller_test.exs index 6d1626d554..6d2588ad5f 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/address_internal_transaction_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/address_internal_transaction_controller_test.exs @@ -27,12 +27,25 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do transaction = :transaction |> insert() - |> with_block() + |> with_block(insert(:block, number: 1)) from_internal_transaction = - insert(:internal_transaction, transaction: transaction, from_address: address, index: 1) + insert(:internal_transaction, + transaction: transaction, + from_address: address, + index: 1, + block_number: transaction.block_number, + transaction_index: transaction.index + ) - to_internal_transaction = insert(:internal_transaction, transaction: transaction, to_address: address, index: 2) + to_internal_transaction = + insert(:internal_transaction, + transaction: transaction, + to_address: address, + index: 2, + block_number: transaction.block_number, + transaction_index: transaction.index + ) path = address_internal_transaction_path(conn, :index, address) conn = get(conn, path) @@ -145,7 +158,7 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do test "next_page_params exist if not on last page", %{conn: conn} do address = insert(:address) - block = %Block{number: number} = insert(:block) + block = %Block{number: number} = insert(:block, number: 7000) transaction = %Transaction{index: transaction_index} = @@ -159,7 +172,9 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do :internal_transaction, transaction: transaction, from_address: address, - index: index + index: index, + block_number: transaction.block_number, + transaction_index: transaction.index ) end) diff --git a/apps/block_scout_web/test/block_scout_web/controllers/transaction_internal_transaction_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/transaction_internal_transaction_controller_test.exs index e9cf9721e0..1a1899c82b 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/transaction_internal_transaction_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/transaction_internal_transaction_controller_test.exs @@ -38,10 +38,22 @@ defmodule BlockScoutWeb.TransactionInternalTransactionControllerTest do transaction = :transaction |> insert() - |> with_block() + |> with_block(insert(:block, number: 1)) - expected_internal_transaction = insert(:internal_transaction, transaction: transaction, index: 0) - insert(:internal_transaction, transaction: transaction, index: 1) + expected_internal_transaction = + insert(:internal_transaction, + transaction: transaction, + index: 0, + block_number: transaction.block_number, + transaction_index: transaction.index + ) + + insert(:internal_transaction, + transaction: transaction, + index: 1, + transaction_index: transaction.index, + block_number: transaction.block_number + ) path = transaction_internal_transaction_path(BlockScoutWeb.Endpoint, :index, transaction.hash) @@ -71,11 +83,16 @@ defmodule BlockScoutWeb.TransactionInternalTransactionControllerTest do :transaction |> insert(to_address: nil) |> with_contract_creation(contract_address) - |> with_block() + |> with_block(insert(:block, number: 7000)) internal_transaction = :internal_transaction_create - |> insert(transaction: transaction, index: 0) + |> insert( + transaction: transaction, + index: 0, + block_number: transaction.block_number, + transaction_index: transaction.index + ) |> with_contract_creation(contract_address) conn = @@ -95,13 +112,26 @@ defmodule BlockScoutWeb.TransactionInternalTransactionControllerTest do transaction = :transaction |> insert() - |> with_block() + |> with_block(insert(:block, number: 7000)) - %InternalTransaction{index: index} = insert(:internal_transaction, transaction: transaction, index: 0) + %InternalTransaction{index: index} = + insert(:internal_transaction, + transaction: transaction, + index: 0, + block_number: transaction.block_number, + transaction_index: transaction.index + ) second_page_indexes = 1..50 - |> Enum.map(fn index -> insert(:internal_transaction, transaction: transaction, index: index) end) + |> Enum.map(fn index -> + insert(:internal_transaction, + transaction: transaction, + index: index, + block_number: transaction.block_number, + transaction_index: transaction.index + ) + end) |> Enum.map(& &1.index) conn = @@ -117,7 +147,7 @@ defmodule BlockScoutWeb.TransactionInternalTransactionControllerTest do end test "next_page_params exist if not on last page", %{conn: conn} do - block = %Block{number: number} = insert(:block) + block = %Block{number: number} = insert(:block, number: 7000) transaction = %Transaction{index: transaction_index} = @@ -130,7 +160,9 @@ defmodule BlockScoutWeb.TransactionInternalTransactionControllerTest do insert( :internal_transaction, transaction: transaction, - index: index + index: index, + block_number: transaction.block_number, + transaction_index: transaction.index ) end) @@ -144,14 +176,16 @@ defmodule BlockScoutWeb.TransactionInternalTransactionControllerTest do transaction = :transaction |> insert() - |> with_block() + |> with_block(insert(:block, number: 7000)) 1..2 |> Enum.map(fn index -> insert( :internal_transaction, transaction: transaction, - index: index + index: index, + block_number: transaction.block_number, + transaction_index: transaction.index ) end) diff --git a/apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs b/apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs index 8bf9d851a2..02fce4b206 100644 --- a/apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs +++ b/apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs @@ -4,7 +4,7 @@ defmodule BlockScoutWeb.ViewingAddressesTest do alias BlockScoutWeb.{AddressPage, AddressView, Notifier} setup do - block = insert(:block) + block = insert(:block, number: 42) lincoln = insert(:address, fetched_coin_balance: 5) taft = insert(:address, fetched_coin_balance: 5) @@ -225,9 +225,22 @@ defmodule BlockScoutWeb.ViewingAddressesTest do transaction = transactions.from_lincoln internal_transaction_lincoln_to_address = - insert(:internal_transaction, transaction: transaction, to_address: address, index: 1) + insert(:internal_transaction, + transaction: transaction, + to_address: address, + index: 1, + block_number: 7000, + transaction_index: 1 + ) + + insert(:internal_transaction, + transaction: transaction, + from_address: address, + index: 2, + block_number: 8000, + transaction_index: 2 + ) - insert(:internal_transaction, transaction: transaction, from_address: address, index: 2) {:ok, %{internal_transaction_lincoln_to_address: internal_transaction_lincoln_to_address}} end @@ -270,7 +283,7 @@ defmodule BlockScoutWeb.ViewingAddressesTest do transaction = :transaction |> insert(from_address: addresses.lincoln) - |> with_block() + |> with_block(insert(:block, number: 7000)) session |> AddressPage.visit_page(addresses.lincoln) @@ -278,7 +291,13 @@ defmodule BlockScoutWeb.ViewingAddressesTest do |> assert_has(AddressPage.internal_transactions(count: 2)) internal_transaction = - insert(:internal_transaction, transaction: transaction, index: 2, from_address: addresses.lincoln) + insert(:internal_transaction, + transaction: transaction, + index: 2, + from_address: addresses.lincoln, + block_number: transaction.block_number, + transaction_index: transaction.index + ) Notifier.handle_event({:chain_event, :internal_transactions, :realtime, [internal_transaction]}) @@ -307,7 +326,9 @@ defmodule BlockScoutWeb.ViewingAddressesTest do |> insert( transaction: from_lincoln, from_address: lincoln, - index: 1 + index: 1, + block_number: from_lincoln.block_number, + transaction_index: from_lincoln.index ) |> with_contract_creation(contract_address) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index d671181600..400cd16232 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -124,6 +124,7 @@ defmodule Explorer.Chain do InternalTransaction |> InternalTransaction.where_address_fields_match(hash, direction) |> InternalTransaction.where_is_different_from_parent_transaction() + |> InternalTransaction.where_block_number_is_not_null() |> page_internal_transaction(paging_options) |> limit(^paging_options.page_size) |> order_by( diff --git a/apps/explorer/lib/explorer/chain/internal_transaction.ex b/apps/explorer/lib/explorer/chain/internal_transaction.ex index d57ea5a1d1..52dc47d858 100644 --- a/apps/explorer/lib/explorer/chain/internal_transaction.ex +++ b/apps/explorer/lib/explorer/chain/internal_transaction.ex @@ -476,4 +476,8 @@ defmodule Explorer.Chain.InternalTransaction do (it.type == ^:call and it.index > 0) or it.type != ^:call ) end + + def where_block_number_is_not_null(query) do + where(query, [t], not is_nil(t.block_number)) + end end diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index 3c0fd8bc9b..9bb6242fbb 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -1262,7 +1262,13 @@ defmodule Explorer.ChainTest do describe "address_to_internal_transactions/1" do test "with single transaction containing two internal transactions" do address = insert(:address) - transaction = insert(:transaction) + + block = insert(:block, number: 2000) + + transaction = + :transaction + |> insert() + |> with_block(block) %InternalTransaction{id: first_id} = insert(:internal_transaction, @@ -1293,7 +1299,12 @@ defmodule Explorer.ChainTest do test "loads associations in necessity_by_association" do address = insert(:address) - transaction = insert(:transaction, to_address: address) + block = insert(:block, number: 2000) + + transaction = + :transaction + |> insert() + |> with_block(block) insert(:internal_transaction, transaction: transaction, @@ -1341,7 +1352,12 @@ defmodule Explorer.ChainTest do test "returns results in reverse chronological order by block number, transaction index, internal transaction index" do address = insert(:address) - pending_transaction = insert(:transaction) + block = insert(:block, number: 7000) + + pending_transaction = + :transaction + |> insert() + |> with_block(block) %InternalTransaction{id: first_pending} = insert(