Co-authored-by: jimmay5469 <jimmay5469@gmail.com>pull/201/head
parent
426433e83b
commit
bd35a7c2d8
@ -0,0 +1,48 @@ |
||||
defmodule ExplorerWeb.TransactionInternalTransactionController do |
||||
use ExplorerWeb, :controller |
||||
|
||||
alias Explorer.Chain |
||||
|
||||
def index(conn, %{"transaction_id" => hash_string}) do |
||||
with {:ok, hash} <- Chain.string_to_transaction_hash(hash_string), |
||||
{:ok, transaction} <- |
||||
Chain.hash_to_transaction( |
||||
hash, |
||||
necessity_by_association: %{ |
||||
block: :optional, |
||||
from_address: :optional, |
||||
to_address: :optional, |
||||
receipt: :optional |
||||
} |
||||
) do |
||||
internal_transactions = |
||||
Chain.transaction_hash_to_internal_transactions( |
||||
transaction.hash, |
||||
necessity_by_association: %{from_address: :required, to_address: :optional} |
||||
) |
||||
|
||||
max_block_number = max_block_number() |
||||
|
||||
render( |
||||
conn, |
||||
"index.html", |
||||
internal_transactions: internal_transactions, |
||||
max_block_number: max_block_number, |
||||
transaction: transaction |
||||
) |
||||
else |
||||
:error -> |
||||
not_found(conn) |
||||
|
||||
{:error, :not_found} -> |
||||
not_found(conn) |
||||
end |
||||
end |
||||
|
||||
defp max_block_number do |
||||
case Chain.max_block_number() do |
||||
{:ok, number} -> number |
||||
{:error, :not_found} -> 0 |
||||
end |
||||
end |
||||
end |
@ -1,5 +1,5 @@ |
||||
<section class="container__section"> |
||||
<%= render "overview.html", assigns %> |
||||
<%= render ExplorerWeb.TransactionView, "overview.html", assigns %> |
||||
<div> |
||||
<ul class="nav nav-tabs"> |
||||
<li class="nav-item"> |
@ -0,0 +1,9 @@ |
||||
defmodule ExplorerWeb.TransactionInternalTransactionView do |
||||
use ExplorerWeb, :view |
||||
@dialyzer :no_match |
||||
|
||||
alias ExplorerWeb.TransactionView |
||||
|
||||
defdelegate value(txn, opts), to: TransactionView |
||||
defdelegate gas(txn), to: TransactionView |
||||
end |
@ -0,0 +1,45 @@ |
||||
defmodule ExplorerWeb.TransactionInternalTransactionControllerTest do |
||||
use ExplorerWeb.ConnCase |
||||
|
||||
import ExplorerWeb.Router.Helpers, only: [transaction_internal_transaction_path: 4] |
||||
|
||||
describe "GET index/3" do |
||||
test "without transaction", %{conn: conn} do |
||||
conn = get(conn, transaction_internal_transaction_path(ExplorerWeb.Endpoint, :index, :en, "nope")) |
||||
|
||||
assert html_response(conn, 404) |
||||
end |
||||
|
||||
test "includes transaction data", %{conn: conn} do |
||||
block = insert(:block, %{number: 777}) |
||||
|
||||
transaction = |
||||
:transaction |
||||
|> insert() |
||||
|> with_block(block) |
||||
|
||||
conn = get(conn, transaction_internal_transaction_path(ExplorerWeb.Endpoint, :index, :en, transaction.hash)) |
||||
|
||||
assert html_response(conn, 200) |
||||
assert conn.assigns.transaction.hash == transaction.hash |
||||
end |
||||
|
||||
test "includes internal transactions for the transaction", %{conn: conn} do |
||||
transaction = insert(:transaction) |
||||
expected_internal_transaction = insert(:internal_transaction, transaction_hash: transaction.hash, index: 0) |
||||
insert(:internal_transaction, transaction_hash: transaction.hash, index: 1) |
||||
|
||||
path = transaction_internal_transaction_path(ExplorerWeb.Endpoint, :index, :en, transaction.hash) |
||||
|
||||
conn = get(conn, path) |
||||
|
||||
actual_internal_transaction_ids = |
||||
conn.assigns.internal_transactions.entries |
||||
|> Enum.map(fn it -> it.id end) |
||||
|
||||
assert html_response(conn, 200) |
||||
|
||||
assert Enum.member?(actual_internal_transaction_ids, expected_internal_transaction.id) |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue