Ensure contract creation address hash is shown for to_address on create internal transaction

pull/376/head
Stamates 6 years ago
parent 48ed461c88
commit ab1eb28a45
  1. 2
      apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/_internal_transaction.html.eex
  2. 6
      apps/explorer_web/lib/explorer_web/views/internal_transaction_view.ex
  3. 23
      apps/explorer_web/test/explorer_web/controllers/address_internal_transaction_controller_test.exs
  4. 26
      apps/explorer_web/test/explorer_web/features/viewing_addresses_test.exs

@ -8,7 +8,7 @@
<span> <span>
<%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address: @internal_transaction.from_address %> <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address: @internal_transaction.from_address %>
&rarr; &rarr;
<%= 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) %>
</span> </span>
<%= ExplorerWeb.TransactionView.value(@internal_transaction, include_label: false) %> POA <%= ExplorerWeb.TransactionView.value(@internal_transaction, include_label: false) %> POA
</div> </div>

@ -6,4 +6,10 @@ defmodule ExplorerWeb.InternalTransactionView do
def create?(%InternalTransaction{type: :create}), do: true def create?(%InternalTransaction{type: :create}), do: true
def create?(_), do: false 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 end

@ -180,28 +180,5 @@ defmodule ExplorerWeb.AddressInternalTransactionControllerTest do
refute conn.assigns.next_page_params refute conn.assigns.next_page_params
end 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
end end

@ -197,4 +197,30 @@ defmodule ExplorerWeb.ViewingAddressesTest do
assert_text(session, AddressPage.balance(), "0.0000000000000001 POA") assert_text(session, AddressPage.balance(), "0.0000000000000001 POA")
end 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 end

Loading…
Cancel
Save