Load contract creation address link on transactions index

pull/275/head
Stamates 7 years ago committed by katibest
parent 4a4ef716a0
commit 43d0a62118
  1. 4
      apps/explorer/lib/explorer/chain.ex
  2. 6
      apps/explorer/test/explorer/chain_test.exs
  3. 2
      apps/explorer/test/support/factory.ex
  4. 14
      apps/explorer_web/lib/explorer_web/templates/transaction/index.html.eex
  5. 28
      apps/explorer_web/lib/explorer_web/templates/transaction/overview.html.eex
  6. 16
      apps/explorer_web/test/explorer_web/controllers/transaction_internal_transaction_controller_test.exs
  7. 16
      apps/explorer_web/test/explorer_web/features/pages/transaction_list_page.ex
  8. 10
      apps/explorer_web/test/explorer_web/features/pages/transaction_page.ex
  9. 13
      apps/explorer_web/test/explorer_web/features/viewing_transactions_test.exs

@ -1412,6 +1412,10 @@ defmodule Explorer.Chain do
paging_options = Keyword.get(options, :paging_options, %PagingOptions{page_size: 50}) paging_options = Keyword.get(options, :paging_options, %PagingOptions{page_size: 50})
Transaction Transaction
|> load_contract_creation()
|> select_merge([_, internal_transaction], %{
created_contract_address_hash: internal_transaction.created_contract_address_hash
})
|> where([transaction], not is_nil(transaction.block_number) and not is_nil(transaction.index)) |> where([transaction], not is_nil(transaction.block_number) and not is_nil(transaction.index))
|> page_transaction(paging_options) |> page_transaction(paging_options)
|> limit(^paging_options.page_size) |> limit(^paging_options.page_size)

@ -887,5 +887,11 @@ defmodule Explorer.ChainTest do
insert(:transaction) insert(:transaction)
assert [] == Explorer.Chain.recent_collated_transactions() assert [] == Explorer.Chain.recent_collated_transactions()
end end
test "it has contract_creation_address_hash added" do
%InternalTransaction{created_contract_address_hash: hash} = insert(:internal_transaction_create, index: 0)
assert [%Transaction{created_contract_address_hash: ^hash}] = Explorer.Chain.recent_collated_transactions()
end
end end
end end

@ -161,7 +161,7 @@ defmodule Explorer.Factory do
transaction = transaction =
:transaction :transaction
|> insert() |> insert(to_address: nil, to_address_hash: nil)
|> with_block() |> with_block()
%InternalTransaction{ %InternalTransaction{

@ -62,7 +62,19 @@
<%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: transaction.from_address %> <%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: transaction.from_address %>
</td> </td>
<td> <td>
<%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: transaction.to_address %> <%= cond do %>
<% transaction.to_address_hash != nil -> %>
<%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: transaction.to_address %>
<% transaction.created_contract_address_hash != nil -> %>
<%= link(
"Contract Creation",
class: "transaction__link",
"data-address-hash": transaction.created_contract_address_hash,
to: address_path(@conn, :show, @conn.assigns.locale, transaction.created_contract_address_hash),
title: transaction.created_contract_address_hash
) %>
<% true -> %>
<% end %>
</td> </td>
<td> <td>
<%= ExplorerWeb.TransactionView.value(transaction, include_label: false) %> <%= ExplorerWeb.TransactionView.value(transaction, include_label: false) %>

@ -85,19 +85,21 @@
<%= gettext "To" %> <%= gettext "To" %>
</th> </th>
<td> <td>
<%= if @transaction.to_address do %> <%= cond do %>
<%= link( <% @transaction.to_address_hash != nil -> %>
@transaction.to_address, <%= link(
class: "transaction__link", @transaction.to_address,
to: address_path(@conn, :show, @conn.assigns.locale, @transaction.to_address) class: "transaction__link",
) %> to: address_path(@conn, :show, @conn.assigns.locale, @transaction.to_address)
<% else %> ) %>
[Contract <%= link( <% @transaction.created_contract_address_hash != nil -> %>
@transaction.created_contract_address_hash, [Contract <%= link(
class: "transaction__link", @transaction.created_contract_address_hash,
"data-test": "created_contract_address_hash", class: "transaction__link",
to: address_path(@conn, :show, @conn.assigns.locale, @transaction.created_contract_address_hash) "data-test": "created_contract_address_hash",
) %> Created] to: address_path(@conn, :show, @conn.assigns.locale, @transaction.created_contract_address_hash)
) %> Created]
<% true -> %>
<% end %> <% end %>
</td> </td>
</tr> </tr>

@ -60,10 +60,18 @@ defmodule ExplorerWeb.TransactionInternalTransactionControllerTest do
end end
test "with no to_address_hash overview contains contract create address", %{conn: conn} do test "with no to_address_hash overview contains contract create address", %{conn: conn} do
transaction = insert(:transaction, to_address_hash: nil) internal_transaction = insert(:internal_transaction_create, index: 0)
insert(:internal_transaction_create, transaction_hash: transaction.hash, index: 0)
conn =
conn = get(conn, transaction_internal_transaction_path(ExplorerWeb.Endpoint, :index, :en, transaction.hash)) get(
conn,
transaction_internal_transaction_path(
ExplorerWeb.Endpoint,
:index,
:en,
internal_transaction.transaction_hash
)
)
refute is_nil(conn.assigns.transaction.created_contract_address_hash) refute is_nil(conn.assigns.transaction.created_contract_address_hash)
end end

@ -3,23 +3,27 @@ defmodule ExplorerWeb.TransactionListPage do
use Wallaby.DSL use Wallaby.DSL
import Wallaby.Query, only: [css: 1] import Wallaby.Query, only: [css: 1, css: 2]
alias Explorer.Chain.Transaction alias Explorer.Chain.{InternalTransaction, Transaction}
def click_transaction(session, %Transaction{hash: transaction_hash}) do def click_transaction(session, %Transaction{hash: transaction_hash}) do
click(session, css("[data-test='transaction_hash'][data-transaction-hash='#{transaction_hash}']")) click(session, css("[data-test='transaction_hash'][data-transaction-hash='#{transaction_hash}']"))
end end
def visit_page(session) do
visit(session, "/en/transactions")
end
def click_pending(session) do def click_pending(session) do
click(session, css("[data-test='pending_transactions_link']")) click(session, css("[data-test='pending_transactions_link']"))
end end
def contract_creation(%InternalTransaction{created_contract_address_hash: hash}) do
css("[data-address-hash='#{hash}']", text: "Contract Created")
end
def transaction(%Transaction{hash: transaction_hash}) do def transaction(%Transaction{hash: transaction_hash}) do
css("[data-test='transaction_hash'][data-transaction-hash='#{transaction_hash}']") css("[data-test='transaction_hash'][data-transaction-hash='#{transaction_hash}']")
end end
def visit_page(session) do
visit(session, "/en/transactions")
end
end end

@ -11,15 +11,19 @@ defmodule ExplorerWeb.TransactionPage do
click(session, css("[data-test='transaction_logs_link']")) click(session, css("[data-test='transaction_logs_link']"))
end end
def contract_creation_address_hash(%InternalTransaction{created_contract_address_hash: hash}) do
css("[data-test='created_contract_address_hash']", text: Hash.to_string(hash))
end
def detail_hash(%Transaction{hash: transaction_hash}) do def detail_hash(%Transaction{hash: transaction_hash}) do
css("[data-test='transaction_detail_hash']", text: Hash.to_string(transaction_hash)) css("[data-test='transaction_detail_hash']", text: Hash.to_string(transaction_hash))
end end
def contract_creation_address_hash(%InternalTransaction{created_contract_address_hash: hash}) do def visit_page(session, %Transaction{hash: transaction_hash}) do
css("[data-test='created_contract_address_hash']", text: Hash.to_string(hash)) visit(session, "/en/transactions/#{transaction_hash}")
end end
def visit_page(session, %Transaction{hash: transaction_hash}) do def visit_page(session, transaction_hash = %Hash{}) do
visit(session, "/en/transactions/#{transaction_hash}") visit(session, "/en/transactions/#{transaction_hash}")
end end
end end

@ -87,8 +87,14 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
|> TransactionListPage.visit_page() |> TransactionListPage.visit_page()
|> TransactionListPage.click_pending() |> TransactionListPage.click_pending()
|> assert_has(TransactionListPage.transaction(pending)) |> assert_has(TransactionListPage.transaction(pending))
end
test "contract creation is shown for to_address", %{session: session} do
internal_transaction = insert(:internal_transaction_create, index: 0)
# |> click(css(".transactions__link", text: to_string(pending.hash))) session
|> TransactionListPage.visit_page()
|> assert_has(TransactionListPage.contract_creation(internal_transaction))
end end
end end
@ -107,11 +113,10 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
end end
test "can see a contract creation address in to_address", %{session: session} do test "can see a contract creation address in to_address", %{session: session} do
transaction = insert(:transaction, to_address_hash: nil) internal_transaction = insert(:internal_transaction_create, index: 0)
internal_transaction = insert(:internal_transaction_create, transaction_hash: transaction.hash, index: 0)
session session
|> TransactionPage.visit_page(transaction) |> TransactionPage.visit_page(internal_transaction.transaction_hash)
|> assert_has(TransactionPage.contract_creation_address_hash(internal_transaction)) |> assert_has(TransactionPage.contract_creation_address_hash(internal_transaction))
end end

Loading…
Cancel
Save