From ab1eb28a45fdf0cd8c60d793b600ca270686c6a0 Mon Sep 17 00:00:00 2001 From: Stamates Date: Fri, 6 Jul 2018 10:35:13 -0400 Subject: [PATCH] Ensure contract creation address hash is shown for to_address on create internal transaction --- .../_internal_transaction.html.eex | 2 +- .../views/internal_transaction_view.ex | 6 +++++ ...s_internal_transaction_controller_test.exs | 23 ---------------- .../features/viewing_addresses_test.exs | 26 +++++++++++++++++++ 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/_internal_transaction.html.eex b/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/_internal_transaction.html.eex index c1e9f8a14a..4e26d7d082 100644 --- a/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/_internal_transaction.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/_internal_transaction.html.eex @@ -8,7 +8,7 @@ <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address: @internal_transaction.from_address %> → - <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address: @internal_transaction.to_address, address_hash: nil %> + <%= render ExplorerWeb.AddressView, "_link.html", Keyword.merge(ExplorerWeb.InternalTransactionView.display_to_address(@internal_transaction), locale: @locale) %> <%= ExplorerWeb.TransactionView.value(@internal_transaction, include_label: false) %> POA diff --git a/apps/explorer_web/lib/explorer_web/views/internal_transaction_view.ex b/apps/explorer_web/lib/explorer_web/views/internal_transaction_view.ex index c7972efa47..1db36950de 100644 --- a/apps/explorer_web/lib/explorer_web/views/internal_transaction_view.ex +++ b/apps/explorer_web/lib/explorer_web/views/internal_transaction_view.ex @@ -6,4 +6,10 @@ defmodule ExplorerWeb.InternalTransactionView do def create?(%InternalTransaction{type: :create}), do: true def create?(_), do: false + + # This is the address to be shown in the to field + def display_to_address(%InternalTransaction{to_address_hash: nil, created_contract_address_hash: address_hash}), + do: [address: nil, address_hash: address_hash] + + def display_to_address(%InternalTransaction{to_address: address}), do: [address: address] end diff --git a/apps/explorer_web/test/explorer_web/controllers/address_internal_transaction_controller_test.exs b/apps/explorer_web/test/explorer_web/controllers/address_internal_transaction_controller_test.exs index 36243100f3..d75b5c3040 100644 --- a/apps/explorer_web/test/explorer_web/controllers/address_internal_transaction_controller_test.exs +++ b/apps/explorer_web/test/explorer_web/controllers/address_internal_transaction_controller_test.exs @@ -180,28 +180,5 @@ defmodule ExplorerWeb.AddressInternalTransactionControllerTest do refute conn.assigns.next_page_params end - - test "returns parent transaction for a contract address", %{conn: conn} do - address = insert(:address, contract_code: data(:address_contract_code)) - block = insert(:block) - - transaction = - :transaction - |> insert(to_address: nil) - |> with_block(block) - - internal_transaction = - insert( - :internal_transaction_create, - index: 0, - created_contract_address: address, - to_address: nil, - transaction: transaction - ) - - conn = get(conn, address_internal_transaction_path(conn, :index, :en, address)) - - assert internal_transaction.id == hd(conn.assigns.internal_transactions).id - end end end diff --git a/apps/explorer_web/test/explorer_web/features/viewing_addresses_test.exs b/apps/explorer_web/test/explorer_web/features/viewing_addresses_test.exs index 4be69702a5..5390ecf115 100644 --- a/apps/explorer_web/test/explorer_web/features/viewing_addresses_test.exs +++ b/apps/explorer_web/test/explorer_web/features/viewing_addresses_test.exs @@ -197,4 +197,30 @@ defmodule ExplorerWeb.ViewingAddressesTest do assert_text(session, AddressPage.balance(), "0.0000000000000001 POA") end + + test "contract creation is shown for to_address on list page", %{ + addresses: addresses, + block: block, + session: session + } do + lincoln = addresses.lincoln + + from_lincoln = + :transaction + |> insert(from_address: lincoln, to_address: nil) + |> with_block(block) + + internal_transaction = + insert( + :internal_transaction_create, + transaction: from_lincoln, + from_address: lincoln, + index: 0 + ) + + session + |> AddressPage.visit_page(addresses.lincoln) + |> AddressPage.click_internal_transactions() + |> assert_has(AddressPage.contract_creation(internal_transaction)) + end end