Merge pull request #977 from poanetwork/ams-fix-internal-transaction-listing

Fix InternalTransaction listing page by removing transaction fields.
pull/960/head
Andrew Cravenho 6 years ago committed by GitHub
commit e3555b8892
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex
  2. 25
      apps/block_scout_web/test/block_scout_web/controllers/address_internal_transaction_controller_test.exs
  3. 58
      apps/block_scout_web/test/block_scout_web/controllers/transaction_internal_transaction_controller_test.exs
  4. 33
      apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs
  5. 1
      apps/explorer/lib/explorer/chain.ex
  6. 4
      apps/explorer/lib/explorer/chain/internal_transaction.ex
  7. 22
      apps/explorer/test/explorer/chain_test.exs

@ -19,8 +19,8 @@
<div class="col-md-3 col-lg-2 d-flex flex-row flex-md-column flex-nowrap justify-content-start text-md-right mt-3 mt-md-0"> <div class="col-md-3 col-lg-2 d-flex flex-row flex-md-column flex-nowrap justify-content-start text-md-right mt-3 mt-md-0">
<span class="mr-2 mr-md-0 order-1"> <span class="mr-2 mr-md-0 order-1">
<%= link( <%= link(
gettext("Block #%{number}", number: to_string(@internal_transaction.transaction.block_number)), gettext("Block #%{number}", number: to_string(@internal_transaction.block_number)),
to: block_path(BlockScoutWeb.Endpoint, :show, @internal_transaction.transaction.block) to: block_path(BlockScoutWeb.Endpoint, :show, @internal_transaction.block_number)
) %> ) %>
</span> </span>
<span class="mr-2 mr-md-0 order-2" data-from-now="<%= @internal_transaction.transaction.block.timestamp %>"></span> <span class="mr-2 mr-md-0 order-2" data-from-now="<%= @internal_transaction.transaction.block.timestamp %>"></span>

@ -27,12 +27,25 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do
transaction = transaction =
:transaction :transaction
|> insert() |> insert()
|> with_block() |> with_block(insert(:block, number: 1))
from_internal_transaction = 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) path = address_internal_transaction_path(conn, :index, address)
conn = get(conn, path) 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 test "next_page_params exist if not on last page", %{conn: conn} do
address = insert(:address) address = insert(:address)
block = %Block{number: number} = insert(:block) block = %Block{number: number} = insert(:block, number: 7000)
transaction = transaction =
%Transaction{index: transaction_index} = %Transaction{index: transaction_index} =
@ -159,7 +172,9 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do
:internal_transaction, :internal_transaction,
transaction: transaction, transaction: transaction,
from_address: address, from_address: address,
index: index index: index,
block_number: transaction.block_number,
transaction_index: transaction.index
) )
end) end)

@ -38,10 +38,22 @@ defmodule BlockScoutWeb.TransactionInternalTransactionControllerTest do
transaction = transaction =
:transaction :transaction
|> insert() |> insert()
|> with_block() |> with_block(insert(:block, number: 1))
expected_internal_transaction = insert(:internal_transaction, transaction: transaction, index: 0) expected_internal_transaction =
insert(:internal_transaction, transaction: transaction, index: 1) 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) path = transaction_internal_transaction_path(BlockScoutWeb.Endpoint, :index, transaction.hash)
@ -71,11 +83,16 @@ defmodule BlockScoutWeb.TransactionInternalTransactionControllerTest do
:transaction :transaction
|> insert(to_address: nil) |> insert(to_address: nil)
|> with_contract_creation(contract_address) |> with_contract_creation(contract_address)
|> with_block() |> with_block(insert(:block, number: 7000))
internal_transaction = internal_transaction =
:internal_transaction_create :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) |> with_contract_creation(contract_address)
conn = conn =
@ -95,13 +112,26 @@ defmodule BlockScoutWeb.TransactionInternalTransactionControllerTest do
transaction = transaction =
:transaction :transaction
|> insert() |> 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 = second_page_indexes =
1..50 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) |> Enum.map(& &1.index)
conn = conn =
@ -117,7 +147,7 @@ defmodule BlockScoutWeb.TransactionInternalTransactionControllerTest do
end end
test "next_page_params exist if not on last page", %{conn: conn} do 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 =
%Transaction{index: transaction_index} = %Transaction{index: transaction_index} =
@ -130,7 +160,9 @@ defmodule BlockScoutWeb.TransactionInternalTransactionControllerTest do
insert( insert(
:internal_transaction, :internal_transaction,
transaction: transaction, transaction: transaction,
index: index index: index,
block_number: transaction.block_number,
transaction_index: transaction.index
) )
end) end)
@ -144,14 +176,16 @@ defmodule BlockScoutWeb.TransactionInternalTransactionControllerTest do
transaction = transaction =
:transaction :transaction
|> insert() |> insert()
|> with_block() |> with_block(insert(:block, number: 7000))
1..2 1..2
|> Enum.map(fn index -> |> Enum.map(fn index ->
insert( insert(
:internal_transaction, :internal_transaction,
transaction: transaction, transaction: transaction,
index: index index: index,
block_number: transaction.block_number,
transaction_index: transaction.index
) )
end) end)

@ -4,7 +4,7 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
alias BlockScoutWeb.{AddressPage, AddressView, Notifier} alias BlockScoutWeb.{AddressPage, AddressView, Notifier}
setup do setup do
block = insert(:block) block = insert(:block, number: 42)
lincoln = insert(:address, fetched_coin_balance: 5) lincoln = insert(:address, fetched_coin_balance: 5)
taft = 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 transaction = transactions.from_lincoln
internal_transaction_lincoln_to_address = 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}} {:ok, %{internal_transaction_lincoln_to_address: internal_transaction_lincoln_to_address}}
end end
@ -270,7 +283,7 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
transaction = transaction =
:transaction :transaction
|> insert(from_address: addresses.lincoln) |> insert(from_address: addresses.lincoln)
|> with_block() |> with_block(insert(:block, number: 7000))
session session
|> AddressPage.visit_page(addresses.lincoln) |> AddressPage.visit_page(addresses.lincoln)
@ -278,7 +291,13 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
|> assert_has(AddressPage.internal_transactions(count: 2)) |> assert_has(AddressPage.internal_transactions(count: 2))
internal_transaction = 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]}) Notifier.handle_event({:chain_event, :internal_transactions, :realtime, [internal_transaction]})
@ -307,7 +326,9 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
|> insert( |> insert(
transaction: from_lincoln, transaction: from_lincoln,
from_address: lincoln, from_address: lincoln,
index: 1 index: 1,
block_number: from_lincoln.block_number,
transaction_index: from_lincoln.index
) )
|> with_contract_creation(contract_address) |> with_contract_creation(contract_address)

@ -124,6 +124,7 @@ defmodule Explorer.Chain do
InternalTransaction InternalTransaction
|> InternalTransaction.where_address_fields_match(hash, direction) |> InternalTransaction.where_address_fields_match(hash, direction)
|> InternalTransaction.where_is_different_from_parent_transaction() |> InternalTransaction.where_is_different_from_parent_transaction()
|> InternalTransaction.where_block_number_is_not_null()
|> page_internal_transaction(paging_options) |> page_internal_transaction(paging_options)
|> limit(^paging_options.page_size) |> limit(^paging_options.page_size)
|> order_by( |> order_by(

@ -476,4 +476,8 @@ defmodule Explorer.Chain.InternalTransaction do
(it.type == ^:call and it.index > 0) or it.type != ^:call (it.type == ^:call and it.index > 0) or it.type != ^:call
) )
end end
def where_block_number_is_not_null(query) do
where(query, [t], not is_nil(t.block_number))
end
end end

@ -1262,7 +1262,13 @@ defmodule Explorer.ChainTest do
describe "address_to_internal_transactions/1" do describe "address_to_internal_transactions/1" do
test "with single transaction containing two internal transactions" do test "with single transaction containing two internal transactions" do
address = insert(:address) address = insert(:address)
transaction = insert(:transaction)
block = insert(:block, number: 2000)
transaction =
:transaction
|> insert()
|> with_block(block)
%InternalTransaction{id: first_id} = %InternalTransaction{id: first_id} =
insert(:internal_transaction, insert(:internal_transaction,
@ -1293,7 +1299,12 @@ defmodule Explorer.ChainTest do
test "loads associations in necessity_by_association" do test "loads associations in necessity_by_association" do
address = insert(:address) address = insert(:address)
transaction = insert(:transaction, to_address: address) block = insert(:block, number: 2000)
transaction =
:transaction
|> insert()
|> with_block(block)
insert(:internal_transaction, insert(:internal_transaction,
transaction: 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 test "returns results in reverse chronological order by block number, transaction index, internal transaction index" do
address = insert(:address) address = insert(:address)
pending_transaction = insert(:transaction) block = insert(:block, number: 7000)
pending_transaction =
:transaction
|> insert()
|> with_block(block)
%InternalTransaction{id: first_pending} = %InternalTransaction{id: first_pending} =
insert( insert(

Loading…
Cancel
Save