Combine address transactions into a single tab

Co-authored-by: tmecklem <timothy@mecklem.com>
Co-authored-by: Luke Imhoff <luke.imhoff@dockyard.com>
pull/130/head
jimmay5469 7 years ago committed by Luke Imhoff
parent 4ee2e4c2a0
commit 5270f6b720
  1. 94
      apps/explorer/lib/explorer/chain.ex
  2. 317
      apps/explorer/test/explorer/chain_test.exs
  3. 28
      apps/explorer_web/lib/explorer_web/controllers/address_controller.ex
  4. 9
      apps/explorer_web/lib/explorer_web/controllers/address_transaction_controller.ex
  5. 31
      apps/explorer_web/lib/explorer_web/controllers/address_transaction_from_controller.ex
  6. 13
      apps/explorer_web/lib/explorer_web/router.ex
  7. 13
      apps/explorer_web/lib/explorer_web/templates/address/show.html.eex
  8. 13
      apps/explorer_web/lib/explorer_web/templates/address_transaction/index.html.eex
  9. 108
      apps/explorer_web/lib/explorer_web/templates/address_transaction_from/index.html.eex
  10. 8
      apps/explorer_web/lib/explorer_web/views/address_transaction_from_view.ex
  11. 2
      apps/explorer_web/lib/explorer_web/views/address_transaction_view.ex
  12. 36
      apps/explorer_web/priv/gettext/default.pot
  13. 36
      apps/explorer_web/priv/gettext/en/LC_MESSAGES/default.po
  14. 16
      apps/explorer_web/test/explorer_web/controllers/address_transaction_controller_test.exs
  15. 92
      apps/explorer_web/test/explorer_web/controllers/address_transaction_from_controller_test.exs
  16. 4
      apps/explorer_web/test/explorer_web/features/contributor_browsing_test.exs

@ -3,7 +3,7 @@ defmodule Explorer.Chain do
The chain context. The chain context.
""" """
import Ecto.Query, only: [from: 2, order_by: 2, preload: 2, where: 2, where: 3] import Ecto.Query, only: [from: 2, or_where: 3, order_by: 2, preload: 2, where: 2]
alias Explorer.Chain.{ alias Explorer.Chain.{
Address, Address,
@ -44,9 +44,33 @@ defmodule Explorer.Chain do
@typep necessity_by_association_option :: {:necessity_by_association, necessity_by_association} @typep necessity_by_association_option :: {:necessity_by_association, necessity_by_association}
@typep pagination_option :: {:pagination, pagination} @typep pagination_option :: {:pagination, pagination}
@typep direction_option :: :to | :from
# Functions # Functions
@doc """
`t:Explorer.Chain.Transaction/0`s from `address`.
## Options
* `:direction` - if specified, will filter transactions by address type. If `:to` is specified, only transactions
where the "to" address matches will be returned. Likewise, if `:from` is specified, only transactions where the
"from" address matches will be returned. If :direction is omitted, transactions either to or from the address
will be returned.
* `:necessity_by_association` - use to load `t:association/0` as `:required` or `:optional`. If an association is
`:required`, and the `t:Explorer.Chain.Transaction.t/0` has no associated record for that association, then the
`t:Explorer.Chain.Transaction.t/0` will not be included in the page `entries`.
* `:pagination` - pagination params to pass to scrivener.
"""
@spec address_to_transactions(Address.t(), [
direction_option | necessity_by_association_option | pagination_option
]) :: %Scrivener.Page{entries: [Transaction.t()]}
def address_to_transactions(address = %Address{}, options \\ [])
when is_list(options) do
address_id_to_transactions(address.id, options)
end
@doc """ @doc """
Finds all `t:Explorer.Chain.Transaction.t/0` in the `t:Explorer.Chain.Block.t/0`. Finds all `t:Explorer.Chain.Transaction.t/0` in the `t:Explorer.Chain.Block.t/0`.
@ -154,25 +178,6 @@ defmodule Explorer.Chain do
end end
end end
@doc """
`t:Explorer.Chain.Transaction/0`s from `address`.
## Options
* `:necessity_by_association` - use to load `t:association/0` as `:required` or `:optional`. If an association is
`:required`, and the `t:Explorer.Chain.Transaction.t/0` has no associated record for that association, then the
`t:Explorer.Chain.Transaction.t/0` will not be included in the page `entries`.
* `:pagination` - pagination params to pass to scrivener.
"""
@spec from_address_to_transactions(Address.t(), [
necessity_by_association_option | pagination_option
]) :: %Scrivener.Page{entries: [Transaction.t()]}
def from_address_to_transactions(address = %Address{}, options \\ [])
when is_list(options) do
address_to_transactions(address, Keyword.put(options, :direction, :from))
end
@doc """ @doc """
The `t:Explorer.Chain.Transaction.t/0` `gas_price` of the `transaction` in `unit`. The `t:Explorer.Chain.Transaction.t/0` `gas_price` of the `transaction` in `unit`.
""" """
@ -335,24 +340,6 @@ defmodule Explorer.Chain do
end end
end end
@doc """
`t:Explorer.Chain.Transaction/0`s to `address`.
## Options
* `:necessity_by_association` - use to load `t:association/0` as `:required` or `:optional`. If an association is
`:required`, and the `t:Explorer.Chain.Transaction.t/0` has no associated record for that association, then the
`t:Explorer.Chain.Transaction.t/0` will not be included in the page `entries`.
* `:pagination` - pagination params to pass to scrivener.
"""
@spec to_address_to_transactions(Address.t(), [
necessity_by_association_option | pagination_option
]) :: %Scrivener.Page{entries: [Transaction.t()]}
def to_address_to_transactions(address = %Address{}, options \\ []) when is_list(options) do
address_to_transactions(address, Keyword.put(options, :direction, :to))
end
@doc """ @doc """
Count of `t:Explorer.Chain.Transaction.t/0`. Count of `t:Explorer.Chain.Transaction.t/0`.
@ -499,10 +486,11 @@ defmodule Explorer.Chain do
defp address_id_to_transactions(address_id, named_arguments) defp address_id_to_transactions(address_id, named_arguments)
when is_integer(address_id) and is_list(named_arguments) do when is_integer(address_id) and is_list(named_arguments) do
field = address_fields =
case Keyword.fetch!(named_arguments, :direction) do case Keyword.get(named_arguments, :direction) do
:to -> :to_address_id :to -> [:to_address_id]
:from -> :from_address_id :from -> [:from_address_id]
nil -> [:to_address_id, :from_address_id]
end end
necessity_by_association = Keyword.get(named_arguments, :necessity_by_association, %{}) necessity_by_association = Keyword.get(named_arguments, :necessity_by_association, %{})
@ -510,19 +498,11 @@ defmodule Explorer.Chain do
Transaction Transaction
|> join_associations(necessity_by_association) |> join_associations(necessity_by_association)
|> chronologically() |> reverse_chronologically()
|> where([t], field(t, ^field) == ^address_id) |> where_address_fields_match(address_fields, address_id)
|> Repo.paginate(pagination) |> Repo.paginate(pagination)
end end
defp address_to_transactions(%Address{id: address_id}, options) when is_list(options) do
address_id_to_transactions(address_id, options)
end
defp chronologically(query) do
from(q in query, order_by: [desc: q.inserted_at, desc: q.id])
end
defp for_parent_transaction(query, hash) when is_binary(hash) do defp for_parent_transaction(query, hash) when is_binary(hash) do
from( from(
child in query, child in query,
@ -556,6 +536,10 @@ defmodule Explorer.Chain do
) )
end end
defp reverse_chronologically(query) do
from(q in query, order_by: [desc: q.inserted_at, desc: q.id])
end
defp transaction_hash_to_logs(transaction_hash, options) defp transaction_hash_to_logs(transaction_hash, options)
when is_binary(transaction_hash) and is_list(options) do when is_binary(transaction_hash) and is_list(options) do
lower_transaction_hash = String.downcase(transaction_hash) lower_transaction_hash = String.downcase(transaction_hash)
@ -575,6 +559,12 @@ defmodule Explorer.Chain do
|> Repo.paginate(pagination) |> Repo.paginate(pagination)
end end
defp where_address_fields_match(query, address_fields, address_id) do
Enum.reduce(address_fields, query, fn field, query ->
or_where(query, [t], field(t, ^field) == ^address_id)
end)
end
defp where_hash(query, hash) do defp where_hash(query, hash) do
from( from(
q in query, q in query,

@ -12,6 +12,147 @@ defmodule Explorer.ChainTest do
# Tests # Tests
describe "address_to_transactions/2" do
test "without transactions" do
address = insert(:address)
assert Repo.aggregate(Transaction, :count, :id) == 0
assert %Scrivener.Page{
entries: [],
page_number: 1,
total_entries: 0
} = Chain.address_to_transactions(address)
end
test "with from transactions" do
%Transaction{from_address_id: from_address_id, id: transaction_id} = insert(:transaction)
address = Repo.get!(Address, from_address_id)
assert %Scrivener.Page{
entries: [%Transaction{id: ^transaction_id}],
page_number: 1,
total_entries: 1
} = Chain.address_to_transactions(address, direction: :from)
end
test "with to transactions" do
%Transaction{to_address_id: to_address_id, id: transaction_id} = insert(:transaction)
address = Repo.get!(Address, to_address_id)
assert %Scrivener.Page{
entries: [%Transaction{id: ^transaction_id}],
page_number: 1,
total_entries: 1
} = Chain.address_to_transactions(address, direction: :to)
end
test "with to and from transactions and direction: :from" do
%Transaction{from_address_id: address_id, id: from_transaction_id} = insert(:transaction)
%Transaction{} = insert(:transaction, to_address_id: address_id)
address = Repo.get!(Address, address_id)
# only contains "from" transaction
assert %Scrivener.Page{
entries: [%Transaction{id: ^from_transaction_id}],
page_number: 1,
total_entries: 1
} = Chain.address_to_transactions(address, direction: :from)
end
test "with to and from transactions and direction: :to" do
%Transaction{from_address_id: address_id} = insert(:transaction)
%Transaction{id: to_transaction_id} = insert(:transaction, to_address_id: address_id)
address = Repo.get!(Address, address_id)
# only contains "to" transaction
assert %Scrivener.Page{
entries: [%Transaction{id: ^to_transaction_id}],
page_number: 1,
total_entries: 1
} = Chain.address_to_transactions(address, direction: :to)
end
test "with to and from transactions and no :direction option" do
%Transaction{from_address_id: address_id, id: from_transaction_id} = insert(:transaction)
%Transaction{id: to_transaction_id} = insert(:transaction, to_address_id: address_id)
address = Repo.get!(Address, address_id)
# only contains "to" transaction
assert %Scrivener.Page{
entries: [
%Transaction{id: ^to_transaction_id},
%Transaction{id: ^from_transaction_id}
],
page_number: 1,
total_entries: 2
} = Chain.address_to_transactions(address)
end
test "with transactions with receipt required without receipt does not return transaction" do
address = %Address{id: to_address_id} = insert(:address)
%Transaction{id: transaction_id_with_receipt} = insert(:transaction, to_address_id: to_address_id)
insert(:receipt, transaction_id: transaction_id_with_receipt)
%Transaction{id: transaction_id_without_receipt} = insert(:transaction, to_address_id: to_address_id)
assert %Scrivener.Page{
entries: [%Transaction{id: ^transaction_id_with_receipt, receipt: %Receipt{}}],
page_number: 1,
total_entries: 1
} =
Chain.address_to_transactions(
address,
necessity_by_association: %{receipt: :required}
)
assert %Scrivener.Page{
entries: transactions,
page_number: 1,
total_entries: 2
} =
Chain.address_to_transactions(
address,
necessity_by_association: %{receipt: :optional}
)
assert length(transactions) == 2
transaction_by_id =
Enum.into(transactions, %{}, fn transaction = %Transaction{id: id} ->
{id, transaction}
end)
assert %Transaction{receipt: %Receipt{}} = transaction_by_id[transaction_id_with_receipt]
assert %Transaction{receipt: nil} = transaction_by_id[transaction_id_without_receipt]
end
test "with transactions can be paginated" do
adddress = %Address{id: to_address_id} = insert(:address)
transactions = insert_list(2, :transaction, to_address_id: to_address_id)
[%Transaction{id: oldest_transaction_id}, %Transaction{id: newest_transaction_id}] = transactions
assert %Scrivener.Page{
entries: [%Transaction{id: ^newest_transaction_id}],
page_number: 1,
page_size: 1,
total_entries: 2,
total_pages: 2
} = Chain.address_to_transactions(adddress, pagination: %{page_size: 1})
assert %Scrivener.Page{
entries: [%Transaction{id: ^oldest_transaction_id}],
page_number: 2,
page_size: 1,
total_entries: 2,
total_pages: 2
} = Chain.address_to_transactions(adddress, pagination: %{page: 2, page_size: 1})
end
end
describe "block_to_transactions/1" do describe "block_to_transactions/1" do
test "without transactions" do test "without transactions" do
block = insert(:block) block = insert(:block)
@ -198,94 +339,6 @@ defmodule Explorer.ChainTest do
end end
end end
describe "from_address_to_transactions/2" do
test "without transactions" do
address = insert(:address)
assert Repo.aggregate(Transaction, :count, :id) == 0
assert %Scrivener.Page{
entries: [],
page_number: 1,
total_entries: 0
} = Chain.from_address_to_transactions(address)
end
test "with transactions" do
%Transaction{from_address_id: from_address_id, id: transaction_id} = insert(:transaction)
address = Repo.get!(Address, from_address_id)
assert %Scrivener.Page{
entries: [%Transaction{id: ^transaction_id}],
page_number: 1,
total_entries: 1
} = Chain.from_address_to_transactions(address)
end
test "with transactions with receipt required without receipt does not return transaction" do
address = %Address{id: from_address_id} = insert(:address)
%Transaction{id: transaction_id_with_receipt} = insert(:transaction, from_address_id: from_address_id)
insert(:receipt, transaction_id: transaction_id_with_receipt)
%Transaction{id: transaction_id_without_receipt} = insert(:transaction, from_address_id: from_address_id)
assert %Scrivener.Page{
entries: [%Transaction{id: ^transaction_id_with_receipt, receipt: %Receipt{}}],
page_number: 1,
total_entries: 1
} =
Chain.from_address_to_transactions(
address,
necessity_by_association: %{receipt: :required}
)
assert %Scrivener.Page{
entries: transactions,
page_number: 1,
total_entries: 2
} =
Chain.from_address_to_transactions(
address,
necessity_by_association: %{receipt: :optional}
)
assert length(transactions) == 2
transaction_by_id =
Enum.into(transactions, %{}, fn transaction = %Transaction{id: id} ->
{id, transaction}
end)
assert %Transaction{receipt: %Receipt{}} = transaction_by_id[transaction_id_with_receipt]
assert %Transaction{receipt: nil} = transaction_by_id[transaction_id_without_receipt]
end
test "with transactions can be paginated" do
adddress = %Address{id: from_address_id} = insert(:address)
transactions = insert_list(2, :transaction, from_address_id: from_address_id)
[%Transaction{id: oldest_transaction_id}, %Transaction{id: newest_transaction_id}] = transactions
assert %Scrivener.Page{
entries: [%Transaction{id: ^newest_transaction_id}],
page_number: 1,
page_size: 1,
total_entries: 2,
total_pages: 2
} = Chain.from_address_to_transactions(adddress, pagination: %{page_size: 1})
assert %Scrivener.Page{
entries: [%Transaction{id: ^oldest_transaction_id}],
page_number: 2,
page_size: 1,
total_entries: 2,
total_pages: 2
} = Chain.from_address_to_transactions(adddress, pagination: %{page: 2, page_size: 1})
end
end
describe "hash_to_address/1" do describe "hash_to_address/1" do
test "without address returns {:error, :not_found}" do test "without address returns {:error, :not_found}" do
assert {:error, :not_found} = Chain.hash_to_address("unknown") assert {:error, :not_found} = Chain.hash_to_address("unknown")
@ -442,94 +495,6 @@ defmodule Explorer.ChainTest do
end end
end end
describe "to_address_to_transactions/2" do
test "without transactions" do
address = insert(:address)
assert Repo.aggregate(Transaction, :count, :id) == 0
assert %Scrivener.Page{
entries: [],
page_number: 1,
total_entries: 0
} = Chain.to_address_to_transactions(address)
end
test "with transactions" do
%Transaction{to_address_id: to_address_id, id: transaction_id} = insert(:transaction)
address = Repo.get!(Address, to_address_id)
assert %Scrivener.Page{
entries: [%Transaction{id: ^transaction_id}],
page_number: 1,
total_entries: 1
} = Chain.to_address_to_transactions(address)
end
test "with transactions with receipt required without receipt does not return transaction" do
address = %Address{id: to_address_id} = insert(:address)
%Transaction{id: transaction_id_with_receipt} = insert(:transaction, to_address_id: to_address_id)
insert(:receipt, transaction_id: transaction_id_with_receipt)
%Transaction{id: transaction_id_without_receipt} = insert(:transaction, to_address_id: to_address_id)
assert %Scrivener.Page{
entries: [%Transaction{id: ^transaction_id_with_receipt, receipt: %Receipt{}}],
page_number: 1,
total_entries: 1
} =
Chain.to_address_to_transactions(
address,
necessity_by_association: %{receipt: :required}
)
assert %Scrivener.Page{
entries: transactions,
page_number: 1,
total_entries: 2
} =
Chain.to_address_to_transactions(
address,
necessity_by_association: %{receipt: :optional}
)
assert length(transactions) == 2
transaction_by_id =
Enum.into(transactions, %{}, fn transaction = %Transaction{id: id} ->
{id, transaction}
end)
assert %Transaction{receipt: %Receipt{}} = transaction_by_id[transaction_id_with_receipt]
assert %Transaction{receipt: nil} = transaction_by_id[transaction_id_without_receipt]
end
test "with transactions can be paginated" do
adddress = %Address{id: to_address_id} = insert(:address)
transactions = insert_list(2, :transaction, to_address_id: to_address_id)
[%Transaction{id: oldest_transaction_id}, %Transaction{id: newest_transaction_id}] = transactions
assert %Scrivener.Page{
entries: [%Transaction{id: ^newest_transaction_id}],
page_number: 1,
page_size: 1,
total_entries: 2,
total_pages: 2
} = Chain.to_address_to_transactions(adddress, pagination: %{page_size: 1})
assert %Scrivener.Page{
entries: [%Transaction{id: ^oldest_transaction_id}],
page_number: 2,
page_size: 1,
total_entries: 2,
total_pages: 2
} = Chain.to_address_to_transactions(adddress, pagination: %{page: 2, page_size: 1})
end
end
describe "transaction_count/0" do describe "transaction_count/0" do
test "without transactions" do test "without transactions" do
assert Chain.transaction_count() == 0 assert Chain.transaction_count() == 0

@ -3,12 +3,28 @@ defmodule ExplorerWeb.AddressController do
alias Explorer.Chain alias Explorer.Chain
def show(conn, %{"id" => hash}) do def show(conn, %{"id" => hash} = params) do
hash case Chain.hash_to_address(hash) do
|> Chain.hash_to_address() {:ok, address} ->
|> case do page = transactions_for_address(address, params)
{:ok, address} -> render(conn, "show.html", address: address) render(conn, "show.html", address: address, page: page)
{:error, :not_found} -> not_found(conn)
{:error, :not_found} ->
not_found(conn)
end end
end end
defp transactions_for_address(address, params) do
Chain.address_to_transactions(
address,
direction: :to,
necessity_by_association: %{
block: :required,
from_address: :optional,
to_address: :optional,
receipt: :required
},
pagination: params
)
end
end end

@ -1,4 +1,4 @@
defmodule ExplorerWeb.AddressTransactionToController do defmodule ExplorerWeb.AddressTransactionController do
@moduledoc """ @moduledoc """
Display all the Transactions that terminate at this Address. Display all the Transactions that terminate at this Address.
""" """
@ -9,10 +9,11 @@ defmodule ExplorerWeb.AddressTransactionToController do
def index(conn, %{"address_id" => to_address_hash} = params) do def index(conn, %{"address_id" => to_address_hash} = params) do
case Chain.hash_to_address(to_address_hash) do case Chain.hash_to_address(to_address_hash) do
{:ok, to_address} -> {:ok, address} ->
page = page =
Chain.to_address_to_transactions( Chain.address_to_transactions(
to_address, address,
direction: :to,
necessity_by_association: %{ necessity_by_association: %{
block: :required, block: :required,
from_address: :optional, from_address: :optional,

@ -1,31 +0,0 @@
defmodule ExplorerWeb.AddressTransactionFromController do
@moduledoc """
Display all the Transactions that originate at this Address.
"""
use ExplorerWeb, :controller
alias Explorer.Chain
def index(conn, %{"address_id" => from_address_hash} = params) do
case Chain.hash_to_address(from_address_hash) do
{:ok, from_address} ->
page =
Chain.from_address_to_transactions(
from_address,
necessity_by_association: %{
block: :required,
from_address: :optional,
to_address: :optional,
receipt: :required
},
pagination: params
)
render(conn, "index.html", page: page)
{:error, :not_found} ->
not_found(conn)
end
end
end

@ -77,17 +77,10 @@ defmodule ExplorerWeb.Router do
resources "/addresses", AddressController, only: [:show] do resources "/addresses", AddressController, only: [:show] do
resources( resources(
"/transactions_to", "/transactions",
AddressTransactionToController, AddressTransactionController,
only: [:index], only: [:index],
as: :transaction_to as: :transaction
)
resources(
"/transactions_from",
AddressTransactionFromController,
only: [:index],
as: :transaction_from
) )
end end

@ -8,18 +8,15 @@
<h2 class="address__tab address__tab--active"> <h2 class="address__tab address__tab--active">
<%= link( <%= link(
gettext("Overview"), gettext("Overview"),
to: address_path(@conn, :show, @conn.assigns.locale, @address.hash), class: "address__link address__link--active",
class: "address__link address__link--active" to: address_path(@conn, :show, @conn.assigns.locale, @address.hash)
) %> ) %>
</h2> </h2>
<h2 class="address__tab">
<%= link(gettext("Transactions To"), to: address_transaction_to_path(@conn, :index, @conn.assigns.locale, @address.hash), class: "address__link") %>
</h2>
<h2 class="address__tab"> <h2 class="address__tab">
<%= link( <%= link(
gettext("Transactions From"), gettext("Transactions"),
to: address_transaction_from_path(@conn, :index, @conn.assigns.locale, @address.hash), class: "address__link",
class: "address__link" to: address_transaction_path(@conn, :index, @conn.assigns.locale, @address.hash)
) %> ) %>
</h2> </h2>
</div> </div>

@ -9,7 +9,7 @@
distance: 1, distance: 1,
first: true, first: true,
next: Phoenix.HTML.raw("&rsaquo;"), next: Phoenix.HTML.raw("&rsaquo;"),
path: &address_transaction_to_path/5, path: &address_transaction_path/5,
previous: Phoenix.HTML.raw("&lsaquo;"), previous: Phoenix.HTML.raw("&lsaquo;"),
view_style: :bulma view_style: :bulma
) %> ) %>
@ -26,16 +26,9 @@
</h2> </h2>
<h2 class="address__tab address__tab--active"> <h2 class="address__tab address__tab--active">
<%= link( <%= link(
gettext("Transactions To"), gettext("Transactions"),
class: "address__link address__link--active", class: "address__link address__link--active",
to: address_transaction_to_path(@conn, :index, @conn.assigns.locale, @conn.params["address_id"]) to: address_transaction_path(@conn, :index, @conn.assigns.locale, @conn.params["address_id"])
) %>
</h2>
<h2 class="address__tab">
<%= link(
gettext("Transactions From"),
class: "address__link",
to: address_transaction_from_path(@conn, :index, @conn.assigns.locale, @conn.params["address_id"])
) %> ) %>
</h2> </h2>
</div> </div>

@ -1,108 +0,0 @@
<section class="container__section block">
<div class="address__headline">
<h1 class="address__headline-title"><%= gettext("Address %{number}", number: @conn.params["address_id"]) %></h1>
<div class="address__pagination"><%= pagination_links @conn, @page, ["en", @conn.params["address_id"]], view_style: :bulma, first: true, distance: 1, previous: Phoenix.HTML.raw("&lsaquo;"), next: Phoenix.HTML.raw("&rsaquo;"), path: &address_transaction_to_path/5 %></div>
<div class="address__pagination">
<%= pagination_links(
@conn,
@page,
["en", @conn.params["address_id"]],
distance: 1,
first: true,
next: Phoenix.HTML.raw("&rsaquo;"),
path: &address_transaction_to_path/5,
previous: Phoenix.HTML.raw("&lsaquo;"),
view_style: :bulma
) %>
</div>
</div>
<div class="address__container">
<div class="address__tabs">
<h2 class="address__tab">
<%= link(
gettext("Overview"),
class: "address__link",
to: address_path(@conn, :show, @conn.assigns.locale, @conn.params["address_id"])
) %>
</h2>
<h2 class="address__tab">
<%= link(
gettext("Transactions To"),
class: "address__link",
to: address_transaction_to_path(@conn, :index, @conn.assigns.locale, @conn.params["address_id"])
) %>
</h2>
<h2 class="address__tab address__tab--active">
<%= link(
gettext("Transactions From"),
class: "address__link address__link--active",
to: address_transaction_from_path(@conn, :index, @conn.assigns.locale, @conn.params["address_id"])
) %>
</h2>
</div>
<div class="transactions__container">
<table class="transactions__table">
<thead class="transactions__header">
<tr>
<th class="transactions__column-header transactions__column-header--status">
<span class="transactions__column-title transactions__column-title--status"><%= gettext "Status" %></span>
</th>
<th class="transactions__column-header"><%= gettext "Hash" %></th>
<th class="transactions__column-header transactions__column-header--optional"><%= gettext "Block" %></th>
<th class="transactions__column-header"><%= gettext "Age" %></th>
<th class="transactions__column-header transactions__column-header--optional"><%= gettext "From" %></th>
<th class="transactions__column-header transactions__column-header--optional"><%= gettext "To" %></th>
<th class="transactions__column-header"><%= gettext "Value" %></th>
</tr>
</thead>
<tbody>
<%= for transaction <- @page.entries do %>
<tr class="transactions__row">
<td class="transactions__column transactions__column--status">
<div class="transactions__dot transactions__dot--<%= status(transaction) %>"></div>
</td>
<td class="transactions__column transactions__column--hash">
<div class="transactions__hash">
<%= link(
transaction.hash,
class: "transactions__link transactions__link--truncated transactions__link--long-hash",
to: transaction_path(@conn, :show, @conn.assigns.locale, transaction.hash)
) %>
</div>
</td>
<td class="transactions__column transactions__column--block transactions__column--optional">
<%= link(
transaction.block.number,
class: "transactions__link",
to: block_path(@conn, :show, @conn.assigns.locale, transaction.block.number)
) %>
</td>
<td class="transactions__column transactions__column--age">
<%= transaction.block.timestamp |> Timex.from_now %>
</td>
<td class="transactions__column transactions__column--from transactions__column--optional">
<div class="transactions__hash">
<%= link(
transaction.from_address.hash,
class: "transactions__link transactions__link--truncated transactions__link--hash",
to: address_path(@conn, :show, @conn.assigns.locale, transaction.from_address.hash)
) %>
</div>
</td>
<td class="transactions__column transactions__column--to transactions__column--optional">
<div class="transactions__hash">
<%= link(
transaction.to_address.hash,
class: "transactions__link transactions__link--truncated transactions__link--hash",
to: address_path(@conn, :show, @conn.assigns.locale, transaction.to_address.hash)
) %>
</div>
</td>
<td class="transactions__column transactions__column--value"><%= value(transaction) %> <%= gettext "Ether" %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</section>

@ -1,8 +0,0 @@
defmodule ExplorerWeb.AddressTransactionFromView do
use ExplorerWeb, :view
alias ExplorerWeb.TransactionView
defdelegate status(transacton), to: TransactionView
defdelegate value(transaction), to: TransactionView
end

@ -1,4 +1,4 @@
defmodule ExplorerWeb.AddressTransactionToView do defmodule ExplorerWeb.AddressTransactionView do
use ExplorerWeb, :view use ExplorerWeb, :view
alias ExplorerWeb.TransactionView alias ExplorerWeb.TransactionView

@ -1,5 +1,4 @@
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:52 #: lib/explorer_web/templates/address_transaction/index.html.eex:44
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:51
#: lib/explorer_web/templates/block/index.html.eex:30 #: lib/explorer_web/templates/block/index.html.eex:30
#: lib/explorer_web/templates/block_transaction/index.html.eex:43 #: lib/explorer_web/templates/block_transaction/index.html.eex:43
#: lib/explorer_web/templates/chain/show.html.eex:65 #: lib/explorer_web/templates/chain/show.html.eex:65
@ -9,8 +8,7 @@
msgid "Age" msgid "Age"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:51 #: lib/explorer_web/templates/address_transaction/index.html.eex:43
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:50
#: lib/explorer_web/templates/block_transaction/index.html.eex:42 #: lib/explorer_web/templates/block_transaction/index.html.eex:42
#: lib/explorer_web/templates/chain/show.html.eex:28 #: lib/explorer_web/templates/chain/show.html.eex:28
#: lib/explorer_web/templates/chain/show.html.eex:100 #: lib/explorer_web/templates/chain/show.html.eex:100
@ -33,8 +31,7 @@ msgstr ""
msgid "Gas Used" msgid "Gas Used"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:50 #: lib/explorer_web/templates/address_transaction/index.html.eex:42
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:49
#: lib/explorer_web/templates/block/show.html.eex:40 #: lib/explorer_web/templates/block/show.html.eex:40
#: lib/explorer_web/templates/block_transaction/index.html.eex:41 #: lib/explorer_web/templates/block_transaction/index.html.eex:41
#: lib/explorer_web/templates/chain/show.html.eex:99 #: lib/explorer_web/templates/chain/show.html.eex:99
@ -53,6 +50,8 @@ msgstr ""
msgid "POA Network Explorer" msgid "POA Network Explorer"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address/show.html.eex:17
#: lib/explorer_web/templates/address_transaction/index.html.eex:29
#: lib/explorer_web/templates/block/index.html.eex:31 #: lib/explorer_web/templates/block/index.html.eex:31
#: lib/explorer_web/templates/block/show.html.eex:16 #: lib/explorer_web/templates/block/show.html.eex:16
#: lib/explorer_web/templates/block/show.html.eex:34 #: lib/explorer_web/templates/block/show.html.eex:34
@ -65,8 +64,7 @@ msgstr ""
msgid "Transactions" msgid "Transactions"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:55 #: lib/explorer_web/templates/address_transaction/index.html.eex:47
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:54
#: lib/explorer_web/templates/block_transaction/index.html.eex:46 #: lib/explorer_web/templates/block_transaction/index.html.eex:46
#: lib/explorer_web/templates/chain/show.html.eex:102 #: lib/explorer_web/templates/chain/show.html.eex:102
#: lib/explorer_web/templates/pending_transaction/index.html.eex:38 #: lib/explorer_web/templates/pending_transaction/index.html.eex:38
@ -161,8 +159,7 @@ msgstr ""
msgid "Address" msgid "Address"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:53 #: lib/explorer_web/templates/address_transaction/index.html.eex:45
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:52
#: lib/explorer_web/templates/block_transaction/index.html.eex:44 #: lib/explorer_web/templates/block_transaction/index.html.eex:44
#: lib/explorer_web/templates/pending_transaction/index.html.eex:36 #: lib/explorer_web/templates/pending_transaction/index.html.eex:36
#: lib/explorer_web/templates/transaction/index.html.eex:37 #: lib/explorer_web/templates/transaction/index.html.eex:37
@ -172,8 +169,7 @@ msgid "From"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address/show.html.eex:10 #: lib/explorer_web/templates/address/show.html.eex:10
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:23 #: lib/explorer_web/templates/address_transaction/index.html.eex:22
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:22
#: lib/explorer_web/templates/block/show.html.eex:9 #: lib/explorer_web/templates/block/show.html.eex:9
#: lib/explorer_web/templates/block_transaction/index.html.eex:21 #: lib/explorer_web/templates/block_transaction/index.html.eex:21
msgid "Overview" msgid "Overview"
@ -183,8 +179,7 @@ msgstr ""
msgid "Success" msgid "Success"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:54 #: lib/explorer_web/templates/address_transaction/index.html.eex:46
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:53
#: lib/explorer_web/templates/block_transaction/index.html.eex:45 #: lib/explorer_web/templates/block_transaction/index.html.eex:45
#: lib/explorer_web/templates/pending_transaction/index.html.eex:37 #: lib/explorer_web/templates/pending_transaction/index.html.eex:37
#: lib/explorer_web/templates/transaction/index.html.eex:38 #: lib/explorer_web/templates/transaction/index.html.eex:38
@ -202,7 +197,7 @@ msgstr ""
msgid "Transaction Status" msgid "Transaction Status"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address/show.html.eex:29 #: lib/explorer_web/templates/address/show.html.eex:26
msgid "Balance" msgid "Balance"
msgstr "" msgstr ""
@ -308,16 +303,14 @@ msgstr ""
msgid "Out of Gas" msgid "Out of Gas"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:48 #: lib/explorer_web/templates/address_transaction/index.html.eex:40
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:47
#: lib/explorer_web/templates/block_transaction/index.html.eex:39 #: lib/explorer_web/templates/block_transaction/index.html.eex:39
#: lib/explorer_web/templates/pending_transaction/index.html.eex:31 #: lib/explorer_web/templates/pending_transaction/index.html.eex:31
#: lib/explorer_web/templates/transaction/index.html.eex:31 #: lib/explorer_web/templates/transaction/index.html.eex:31
msgid "Status" msgid "Status"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:3 #: lib/explorer_web/templates/address_transaction/index.html.eex:3
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:3
msgid "Address %{number}" msgid "Address %{number}"
msgstr "" msgstr ""
@ -325,9 +318,8 @@ msgstr ""
msgid "Showing #%{number}" msgid "Showing #%{number}"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address/show.html.eex:31 #: lib/explorer_web/templates/address/show.html.eex:28
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:101 #: lib/explorer_web/templates/address_transaction/index.html.eex:94
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:101
#: lib/explorer_web/templates/block_transaction/index.html.eex:90 #: lib/explorer_web/templates/block_transaction/index.html.eex:90
#: lib/explorer_web/templates/chain/show.html.eex:128 #: lib/explorer_web/templates/chain/show.html.eex:128
#: lib/explorer_web/templates/pending_transaction/index.html.eex:80 #: lib/explorer_web/templates/pending_transaction/index.html.eex:80

@ -10,8 +10,7 @@ msgid ""
msgstr "" msgstr ""
"Language: en\n" "Language: en\n"
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:52 #: lib/explorer_web/templates/address_transaction/index.html.eex:44
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:51
#: lib/explorer_web/templates/block/index.html.eex:30 #: lib/explorer_web/templates/block/index.html.eex:30
#: lib/explorer_web/templates/block_transaction/index.html.eex:43 #: lib/explorer_web/templates/block_transaction/index.html.eex:43
#: lib/explorer_web/templates/chain/show.html.eex:65 #: lib/explorer_web/templates/chain/show.html.eex:65
@ -21,8 +20,7 @@ msgstr ""
msgid "Age" msgid "Age"
msgstr "Age" msgstr "Age"
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:51 #: lib/explorer_web/templates/address_transaction/index.html.eex:43
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:50
#: lib/explorer_web/templates/block_transaction/index.html.eex:42 #: lib/explorer_web/templates/block_transaction/index.html.eex:42
#: lib/explorer_web/templates/chain/show.html.eex:28 #: lib/explorer_web/templates/chain/show.html.eex:28
#: lib/explorer_web/templates/chain/show.html.eex:100 #: lib/explorer_web/templates/chain/show.html.eex:100
@ -45,8 +43,7 @@ msgstr "%{year} POA Network Ltd. All rights reserved"
msgid "Gas Used" msgid "Gas Used"
msgstr "Gas Used" msgstr "Gas Used"
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:50 #: lib/explorer_web/templates/address_transaction/index.html.eex:42
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:49
#: lib/explorer_web/templates/block/show.html.eex:40 #: lib/explorer_web/templates/block/show.html.eex:40
#: lib/explorer_web/templates/block_transaction/index.html.eex:41 #: lib/explorer_web/templates/block_transaction/index.html.eex:41
#: lib/explorer_web/templates/chain/show.html.eex:99 #: lib/explorer_web/templates/chain/show.html.eex:99
@ -65,6 +62,8 @@ msgstr "Height"
msgid "POA Network Explorer" msgid "POA Network Explorer"
msgstr "POA Network Explorer" msgstr "POA Network Explorer"
#: lib/explorer_web/templates/address/show.html.eex:17
#: lib/explorer_web/templates/address_transaction/index.html.eex:29
#: lib/explorer_web/templates/block/index.html.eex:31 #: lib/explorer_web/templates/block/index.html.eex:31
#: lib/explorer_web/templates/block/show.html.eex:16 #: lib/explorer_web/templates/block/show.html.eex:16
#: lib/explorer_web/templates/block/show.html.eex:34 #: lib/explorer_web/templates/block/show.html.eex:34
@ -77,8 +76,7 @@ msgstr "POA Network Explorer"
msgid "Transactions" msgid "Transactions"
msgstr "Transactions" msgstr "Transactions"
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:55 #: lib/explorer_web/templates/address_transaction/index.html.eex:47
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:54
#: lib/explorer_web/templates/block_transaction/index.html.eex:46 #: lib/explorer_web/templates/block_transaction/index.html.eex:46
#: lib/explorer_web/templates/chain/show.html.eex:102 #: lib/explorer_web/templates/chain/show.html.eex:102
#: lib/explorer_web/templates/pending_transaction/index.html.eex:38 #: lib/explorer_web/templates/pending_transaction/index.html.eex:38
@ -173,8 +171,7 @@ msgstr "%{count} transactions in this block"
msgid "Address" msgid "Address"
msgstr "Address" msgstr "Address"
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:53 #: lib/explorer_web/templates/address_transaction/index.html.eex:45
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:52
#: lib/explorer_web/templates/block_transaction/index.html.eex:44 #: lib/explorer_web/templates/block_transaction/index.html.eex:44
#: lib/explorer_web/templates/pending_transaction/index.html.eex:36 #: lib/explorer_web/templates/pending_transaction/index.html.eex:36
#: lib/explorer_web/templates/transaction/index.html.eex:37 #: lib/explorer_web/templates/transaction/index.html.eex:37
@ -184,8 +181,7 @@ msgid "From"
msgstr "From" msgstr "From"
#: lib/explorer_web/templates/address/show.html.eex:10 #: lib/explorer_web/templates/address/show.html.eex:10
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:23 #: lib/explorer_web/templates/address_transaction/index.html.eex:22
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:22
#: lib/explorer_web/templates/block/show.html.eex:9 #: lib/explorer_web/templates/block/show.html.eex:9
#: lib/explorer_web/templates/block_transaction/index.html.eex:21 #: lib/explorer_web/templates/block_transaction/index.html.eex:21
msgid "Overview" msgid "Overview"
@ -195,8 +191,7 @@ msgstr "Overview"
msgid "Success" msgid "Success"
msgstr "Success" msgstr "Success"
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:54 #: lib/explorer_web/templates/address_transaction/index.html.eex:46
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:53
#: lib/explorer_web/templates/block_transaction/index.html.eex:45 #: lib/explorer_web/templates/block_transaction/index.html.eex:45
#: lib/explorer_web/templates/pending_transaction/index.html.eex:37 #: lib/explorer_web/templates/pending_transaction/index.html.eex:37
#: lib/explorer_web/templates/transaction/index.html.eex:38 #: lib/explorer_web/templates/transaction/index.html.eex:38
@ -214,7 +209,7 @@ msgstr "Transaction Hash"
msgid "Transaction Status" msgid "Transaction Status"
msgstr "Transaction Status" msgstr "Transaction Status"
#: lib/explorer_web/templates/address/show.html.eex:29 #: lib/explorer_web/templates/address/show.html.eex:26
msgid "Balance" msgid "Balance"
msgstr "Balance" msgstr "Balance"
@ -320,16 +315,14 @@ msgstr ""
msgid "Out of Gas" msgid "Out of Gas"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:48 #: lib/explorer_web/templates/address_transaction/index.html.eex:40
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:47
#: lib/explorer_web/templates/block_transaction/index.html.eex:39 #: lib/explorer_web/templates/block_transaction/index.html.eex:39
#: lib/explorer_web/templates/pending_transaction/index.html.eex:31 #: lib/explorer_web/templates/pending_transaction/index.html.eex:31
#: lib/explorer_web/templates/transaction/index.html.eex:31 #: lib/explorer_web/templates/transaction/index.html.eex:31
msgid "Status" msgid "Status"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:3 #: lib/explorer_web/templates/address_transaction/index.html.eex:3
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:3
msgid "Address %{number}" msgid "Address %{number}"
msgstr "" msgstr ""
@ -337,9 +330,8 @@ msgstr ""
msgid "Showing #%{number}" msgid "Showing #%{number}"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address/show.html.eex:31 #: lib/explorer_web/templates/address/show.html.eex:28
#: lib/explorer_web/templates/address_transaction_from/index.html.eex:101 #: lib/explorer_web/templates/address_transaction/index.html.eex:94
#: lib/explorer_web/templates/address_transaction_to/index.html.eex:101
#: lib/explorer_web/templates/block_transaction/index.html.eex:90 #: lib/explorer_web/templates/block_transaction/index.html.eex:90
#: lib/explorer_web/templates/chain/show.html.eex:128 #: lib/explorer_web/templates/chain/show.html.eex:128
#: lib/explorer_web/templates/pending_transaction/index.html.eex:80 #: lib/explorer_web/templates/pending_transaction/index.html.eex:80

@ -1,11 +1,11 @@
defmodule ExplorerWeb.AddressTransactionToControllerTest do defmodule ExplorerWeb.AddressTransactionControllerTest do
use ExplorerWeb.ConnCase use ExplorerWeb.ConnCase
import ExplorerWeb.Router.Helpers, only: [address_transaction_to_path: 4] import ExplorerWeb.Router.Helpers, only: [address_transaction_path: 4]
describe "GET index/2" do describe "GET index/2" do
test "without address", %{conn: conn} do test "without address", %{conn: conn} do
conn = get(conn, address_transaction_to_path(conn, :index, :en, "unknown")) conn = get(conn, address_transaction_path(conn, :index, :en, "unknown"))
assert html_response(conn, 404) assert html_response(conn, 404)
end end
@ -18,7 +18,7 @@ defmodule ExplorerWeb.AddressTransactionToControllerTest do
block = insert(:block) block = insert(:block)
insert(:block_transaction, transaction: transaction, block: block) insert(:block_transaction, transaction: transaction, block: block)
conn = get(conn, address_transaction_to_path(ExplorerWeb.Endpoint, :index, :en, address.hash)) conn = get(conn, address_transaction_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200) assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 1 assert html |> Floki.find("tbody tr") |> length == 1
@ -42,7 +42,7 @@ defmodule ExplorerWeb.AddressTransactionToControllerTest do
insert(:to_address, transaction: transaction, address: other_address) insert(:to_address, transaction: transaction, address: other_address)
insert(:from_address, transaction: transaction, address: address) insert(:from_address, transaction: transaction, address: address)
conn = get(conn, address_transaction_to_path(ExplorerWeb.Endpoint, :index, :en, address.hash)) conn = get(conn, address_transaction_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200) assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0 assert html |> Floki.find("tbody tr") |> length == 0
@ -56,7 +56,7 @@ defmodule ExplorerWeb.AddressTransactionToControllerTest do
insert(:to_address, transaction: transaction, address: address) insert(:to_address, transaction: transaction, address: address)
insert(:from_address, transaction: transaction, address: address) insert(:from_address, transaction: transaction, address: address)
conn = get(conn, address_transaction_to_path(ExplorerWeb.Endpoint, :index, :en, address.hash)) conn = get(conn, address_transaction_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200) assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0 assert html |> Floki.find("tbody tr") |> length == 0
@ -70,7 +70,7 @@ defmodule ExplorerWeb.AddressTransactionToControllerTest do
address = insert(:address) address = insert(:address)
insert(:to_address, transaction: transaction, address: address) insert(:to_address, transaction: transaction, address: address)
conn = get(conn, address_transaction_to_path(ExplorerWeb.Endpoint, :index, :en, address.hash)) conn = get(conn, address_transaction_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200) assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0 assert html |> Floki.find("tbody tr") |> length == 0
@ -84,7 +84,7 @@ defmodule ExplorerWeb.AddressTransactionToControllerTest do
address = insert(:address) address = insert(:address)
insert(:from_address, transaction: transaction, address: address) insert(:from_address, transaction: transaction, address: address)
conn = get(conn, address_transaction_to_path(ExplorerWeb.Endpoint, :index, :en, address.hash)) conn = get(conn, address_transaction_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200) assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0 assert html |> Floki.find("tbody tr") |> length == 0

@ -1,92 +0,0 @@
defmodule ExplorerWeb.AddressTransactionFromControllerTest do
use ExplorerWeb.ConnCase
import ExplorerWeb.Router.Helpers, only: [address_transaction_from_path: 4]
describe "GET index/2" do
test "without address", %{conn: conn} do
conn = get(conn, address_transaction_from_path(conn, :index, :en, "unknown"))
assert html_response(conn, 404)
end
test "returns transactions from this address", %{conn: conn} do
address = insert(:address)
hash = "0xsnacks"
transaction = insert(:transaction, hash: hash, from_address_id: address.id)
insert(:receipt, transaction: transaction)
block = insert(:block)
insert(:block_transaction, transaction: transaction, block: block)
conn = get(conn, address_transaction_from_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200)
transaction_hash_divs = Floki.find(html, "td.transactions__column--hash div.transactions__hash a")
assert length(transaction_hash_divs) == 1
assert List.first(transaction_hash_divs) |> Floki.attribute("href") == [
"/en/transactions/#{hash}"
]
end
test "does not return transactions to this address", %{conn: conn} do
transaction = insert(:transaction, hash: "0xsnacks")
insert(:receipt, transaction: transaction)
block = insert(:block)
insert(:block_transaction, transaction: transaction, block: block)
address = insert(:address)
other_address = insert(:address)
insert(:to_address, transaction: transaction, address: address)
insert(:from_address, transaction: transaction, address: other_address)
conn = get(conn, address_transaction_from_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0
end
test "does not return related transactions without a receipt", %{conn: conn} do
transaction = insert(:transaction)
block = insert(:block)
insert(:block_transaction, transaction: transaction, block: block)
address = insert(:address)
insert(:to_address, transaction: transaction, address: address)
insert(:from_address, transaction: transaction, address: address)
conn = get(conn, address_transaction_from_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0
end
test "does not return related transactions without a from address", %{conn: conn} do
transaction = insert(:transaction)
insert(:receipt, transaction: transaction)
block = insert(:block)
insert(:block_transaction, transaction: transaction, block: block)
address = insert(:address)
insert(:to_address, transaction: transaction, address: address)
conn = get(conn, address_transaction_from_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0
end
test "does not return related transactions without a to address", %{conn: conn} do
transaction = insert(:transaction)
insert(:receipt, transaction: transaction)
block = insert(:block)
insert(:block_transaction, transaction: transaction, block: block)
address = insert(:address)
insert(:from_address, transaction: transaction, address: address)
conn = get(conn, address_transaction_from_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0
end
end
end

@ -187,7 +187,7 @@ defmodule ExplorerWeb.UserListTest do
|> assert_has(css(".transaction__item", text: "0xlincoln")) |> assert_has(css(".transaction__item", text: "0xlincoln"))
|> assert_has(css(".transaction__item", text: "0xhowardtaft")) |> assert_has(css(".transaction__item", text: "0xhowardtaft"))
|> assert_has(css(".transaction__item", text: "block confirmations")) |> assert_has(css(".transaction__item", text: "block confirmations"))
|> assert_has(css(".transaction__item", text: "48 years ago")) |> assert_has(css(".transaction__item", text: "49 years ago"))
|> assert_has(css(".transaction__item", text: "38 years ago")) |> assert_has(css(".transaction__item", text: "38 years ago"))
|> click(link("Internal Transactions")) |> click(link("Internal Transactions"))
|> assert_has(css(".internal-transaction__table", text: internal.call_type)) |> assert_has(css(".internal-transaction__table", text: internal.call_type))
@ -196,7 +196,7 @@ defmodule ExplorerWeb.UserListTest do
|> assert_has(css(".transaction-log__link", text: "0xlincoln")) |> assert_has(css(".transaction-log__link", text: "0xlincoln"))
|> click(css(".transaction-log__link", text: "0xlincoln")) |> click(css(".transaction-log__link", text: "0xlincoln"))
|> assert_has(css(".address__subheading", text: "0xlincoln")) |> assert_has(css(".address__subheading", text: "0xlincoln"))
|> click(css(".address__link", text: "Transactions To")) |> click(css(".address__link", text: "Transactions"))
|> assert_has(css(".transactions__link--long-hash", text: "0xSk8")) |> assert_has(css(".transactions__link--long-hash", text: "0xSk8"))
|> click(css(".address__link", text: "Transactions From")) |> click(css(".address__link", text: "Transactions From"))
|> assert_has(css(".transactions__link--long-hash", text: "0xrazerscooter")) |> assert_has(css(".transactions__link--long-hash", text: "0xrazerscooter"))

Loading…
Cancel
Save