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. 12
      apps/explorer_web/lib/explorer_web/templates/transaction/index.html.eex
  5. 6
      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})
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))
|> page_transaction(paging_options)
|> limit(^paging_options.page_size)

@ -887,5 +887,11 @@ defmodule Explorer.ChainTest do
insert(:transaction)
assert [] == Explorer.Chain.recent_collated_transactions()
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

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

@ -62,7 +62,19 @@
<%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: transaction.from_address %>
</td>
<td>
<%= 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>
<%= ExplorerWeb.TransactionView.value(transaction, include_label: false) %>

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

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

@ -3,23 +3,27 @@ defmodule ExplorerWeb.TransactionListPage do
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
click(session, css("[data-test='transaction_hash'][data-transaction-hash='#{transaction_hash}']"))
end
def visit_page(session) do
visit(session, "/en/transactions")
end
def click_pending(session) do
click(session, css("[data-test='pending_transactions_link']"))
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
css("[data-test='transaction_hash'][data-transaction-hash='#{transaction_hash}']")
end
def visit_page(session) do
visit(session, "/en/transactions")
end
end

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

@ -87,8 +87,14 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
|> TransactionListPage.visit_page()
|> TransactionListPage.click_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
@ -107,11 +113,10 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
end
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, transaction_hash: transaction.hash, index: 0)
internal_transaction = insert(:internal_transaction_create, index: 0)
session
|> TransactionPage.visit_page(transaction)
|> TransactionPage.visit_page(internal_transaction.transaction_hash)
|> assert_has(TransactionPage.contract_creation_address_hash(internal_transaction))
end

Loading…
Cancel
Save