Modify tests to account for new design

pull/346/head
Tim Mecklem 7 years ago committed by jimmay5469
parent 8c4cee1225
commit 91b68cce66
  1. 4
      apps/explorer/test/explorer/chain/statistics_test.exs
  2. 2
      apps/explorer_web/lib/explorer_web/templates/address/_link.html.eex
  3. 2
      apps/explorer_web/lib/explorer_web/templates/chain/_blocks.html.eex
  4. 4
      apps/explorer_web/lib/explorer_web/templates/chain/_transactions.html.eex
  5. 8
      apps/explorer_web/lib/explorer_web/views/address_view.ex
  6. 119
      apps/explorer_web/lib/explorer_web/views/transaction_view.ex
  7. 2
      apps/explorer_web/test/explorer_web/features/pages/home_page.ex
  8. 2
      apps/explorer_web/test/explorer_web/features/viewing_blocks_test.exs

@ -54,11 +54,11 @@ defmodule Explorer.Chain.StatisticsTest do
end
test "returns the last five blocks" do
insert_list(6, :block)
insert_list(5, :block)
statistics = Statistics.fetch()
assert statistics.blocks |> Enum.count() == 5
assert statistics.blocks |> Enum.count() == 4
end
test "returns the last five transactions with blocks" do

@ -11,6 +11,6 @@
<% else %>
<%= link to: address_path(ExplorerWeb.Endpoint, :show, @locale, @address_hash), "data-address-hash": @address_hash do %>
<span class="tile-label d-none d-md-none d-lg-inline"><%= @address_hash %></span>
<span class="tile-label d-lg-none"><%= @address |> hash() |> String.slice(0..5) %>&ndash;<%= @address |> hash() |> String.slice(-6..-1) %></span>
<span class="tile-label d-lg-none"><%= to_string(@address_hash) |> String.slice(0..5) %>&ndash;<%= to_string(@address_hash) |> String.slice(-6..-1) %></span>
<% end %>
<% end %>

@ -8,7 +8,7 @@
<%= for block <- @chain.blocks do %>
<div class="col-sm-3">
<div class="tile d-flex flex-column">
<div class="tile d-flex flex-column" data-test="chain_block">
<%= link(block, to: block_path(@conn, :show, @conn.assigns.locale, block), class: "tile-title") %>
<div>
<%= block.transactions |> Enum.count %> Transactions

@ -3,8 +3,8 @@
<%= link(gettext("View All Transactions →"), to: transaction_path(@conn, :index, Gettext.get_locale), class: "button button--secondary button--xsmall float-right") %>
<h2 class="card-title"><%= gettext "Transactions" %></h2>
<%= for transaction <- @chain.transactions do %>
<div class="tile <%= ExplorerWeb.TransactionView.tile_class(transaction) %>">
<div class="row">
<div class="tile tile-type-<%= ExplorerWeb.TransactionView.type_suffix(transaction) %>" data-test="<%= ExplorerWeb.TransactionView.type_suffix(transaction) %>">
<div class="row" data-test="chain_transaction">
<div class="col-md-2 d-flex align-items-center justify-content-start justify-content-lg-center tile-label">
<%= ExplorerWeb.TransactionView.transaction_display_type(transaction) %>
</div>

@ -8,9 +8,6 @@ defmodule ExplorerWeb.AddressView do
@dialyzer :no_match
def contract?(%Address{contract_code: nil}), do: false
def contract?(%Address{contract_code: _}), do: true
def address_title(%Address{} = address) do
if contract?(address) do
gettext("Contract Address")
@ -22,7 +19,6 @@ defmodule ExplorerWeb.AddressView do
@doc """
Returns a formatted address balance and includes the unit.
"""
def balance(%Address{fetched_balance: nil}), do: ""
def balance(%Address{fetched_balance: balance}) do
@ -35,6 +31,10 @@ defmodule ExplorerWeb.AddressView do
to_string(fetched_balance_block_number)
end
def contract?(%Address{contract_code: nil}), do: false
def contract?(%Address{contract_code: _}), do: true
def formatted_usd(%Address{fetched_balance: nil}, _), do: nil
def formatted_usd(%Address{fetched_balance: balance}, %Token{} = exchange_rate) do

@ -10,26 +10,12 @@ defmodule ExplorerWeb.TransactionView do
import ExplorerWeb.Gettext
def contract_creation?(%Transaction{created_contract_address_hash: nil}), do: false
def contract_creation?(_), do: true
def contract?(%Transaction{from_address: from_address, to_address: to_address}) do
AddressView.contract?(from_address) || AddressView.contract?(to_address)
end
def tile_class(%Transaction{} = transaction) do
cond do
contract_creation?(transaction) -> "tile-type-contract-creation"
contract?(transaction) -> "tile-type-contract"
true -> "tile-type-transaction"
end
end
defguardp is_transaction_type(mod) when mod in [InternalTransaction, Transaction]
def transaction_display_type(%Transaction{} = transaction) do
cond do
contract_creation?(transaction) -> gettext("Contract Creation")
contract?(transaction) -> gettext("Contract")
true -> gettext("Transaction")
def confirmations(%Transaction{block: block}, named_arguments) when is_list(named_arguments) do
case block do
nil -> 0
_ -> Chain.confirmations(block, named_arguments)
end
end
@ -39,11 +25,15 @@ defmodule ExplorerWeb.TransactionView do
def display_to_address(%Transaction{to_address: address}), do: [address: address]
def confirmations(%Transaction{block: block}, named_arguments) when is_list(named_arguments) do
case block do
nil -> 0
_ -> Chain.confirmations(block, named_arguments)
end
def formatted_fee(%Transaction{} = transaction, opts) do
transaction
|> Chain.fee(:wei)
|> fee_to_currency(opts)
|> case do
{_, nil} -> nil
{:actual, value} -> value
{:maximum, value} -> "<= " <> value
end
end
def gas_used(%Transaction{gas_used: nil}), do: gettext("Pending")
@ -52,17 +42,18 @@ defmodule ExplorerWeb.TransactionView do
Number.to_string!(gas_used)
end
def formatted_fee(%Transaction{} = transaction, opts) do
transaction
|> Chain.fee(:wei)
|> fee_to_currency(opts)
|> case do
{_, nil} -> nil
{:actual, value} -> value
{:maximum, value} -> "<= " <> value
end
def involves_contract?(%Transaction{from_address: from_address, to_address: to_address}) do
AddressView.contract?(from_address) || AddressView.contract?(to_address)
end
def involves_contract_creation?(%Transaction{created_contract_address_hash: nil}), do: false
def involves_contract_creation?(_), do: true
def contract_creation?(%Transaction{created_contract_address_hash: nil}), do: false
def contract_creation?(_), do: true
def qr_code(%Transaction{hash: hash}) do
hash
|> to_string()
@ -70,24 +61,21 @@ defmodule ExplorerWeb.TransactionView do
|> Base.encode64()
end
defp fee_to_currency({fee_type, fee}, denomination: denomination) do
{fee_type, format_wei_value(Wei.from(fee, :wei), denomination)}
end
defp fee_to_currency({fee_type, fee}, exchange_rate: %Token{} = exchange_rate) do
formatted =
fee
|> Wei.from(:wei)
|> USD.from(exchange_rate)
|> format_usd_value()
{fee_type, formatted}
end
def format_gas_limit(gas) do
Number.to_string!(gas)
end
def formatted_status(transaction) do
transaction
|> Chain.transaction_to_status()
|> case do
:failed -> gettext("Failed")
:out_of_gas -> gettext("Out of Gas")
:pending -> gettext("Pending")
:success -> gettext("Success")
end
end
def formatted_usd_value(%Transaction{value: nil}, _token), do: nil
def formatted_usd_value(%Transaction{value: value}, token) do
@ -96,8 +84,6 @@ defmodule ExplorerWeb.TransactionView do
defdelegate formatted_timestamp(block), to: BlockView
defguardp is_transaction_type(mod) when mod in [InternalTransaction, Transaction]
def gas(%type{gas: gas}) when is_transaction_type(type) do
Cldr.Number.to_string!(gas)
end
@ -117,14 +103,19 @@ defmodule ExplorerWeb.TransactionView do
Chain.transaction_to_status(transaction)
end
def formatted_status(transaction) do
transaction
|> Chain.transaction_to_status()
|> case do
:failed -> gettext("Failed")
:out_of_gas -> gettext("Out of Gas")
:pending -> gettext("Pending")
:success -> gettext("Success")
def type_suffix(%Transaction{} = transaction) do
cond do
involves_contract_creation?(transaction) -> "contract-creation"
involves_contract?(transaction) -> "contract"
true -> "transaction"
end
end
def transaction_display_type(%Transaction{} = transaction) do
cond do
involves_contract_creation?(transaction) -> gettext("Contract Creation")
involves_contract?(transaction) -> gettext("Contract")
true -> gettext("Transaction")
end
end
@ -139,4 +130,18 @@ defmodule ExplorerWeb.TransactionView do
include_label? = Keyword.get(opts, :include_label, true)
format_wei_value(value, :ether, include_unit_label: include_label?)
end
defp fee_to_currency({fee_type, fee}, denomination: denomination) do
{fee_type, format_wei_value(Wei.from(fee, :wei), denomination)}
end
defp fee_to_currency({fee_type, fee}, exchange_rate: %Token{} = exchange_rate) do
formatted =
fee
|> Wei.from(:wei)
|> USD.from(exchange_rate)
|> format_usd_value()
{fee_type, formatted}
end
end

@ -12,7 +12,7 @@ defmodule ExplorerWeb.HomePage do
end
def contract_creation(%InternalTransaction{created_contract_address_hash: hash}) do
css("[data-address-hash='#{hash}']", text: "Contract Creation")
css("[data-test='contract-creation'] [data-address-hash='#{hash}']")
end
def search(session, text) do

@ -23,7 +23,7 @@ defmodule ExplorerWeb.ViewingBlocksTest do
test "viewing blocks on the home page", %{session: session} do
session
|> HomePage.visit_page()
|> assert_has(HomePage.blocks(count: 5))
|> assert_has(HomePage.blocks(count: 4))
end
test "search for blocks from home page", %{session: session} do

Loading…
Cancel
Save