Merge pull request #688 from poanetwork/600-bugfix-contract-address-on-transaction-overview

600 Bugfix contract address on transaction overview
pull/702/head
Andrew Cravenho 6 years ago committed by GitHub
commit fcfec52d3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      apps/block_scout_web/lib/block_scout_web/templates/address/_link.html.eex
  2. 8
      apps/block_scout_web/lib/block_scout_web/templates/transaction/_tile.html.eex
  3. 4
      apps/block_scout_web/lib/block_scout_web/templates/transaction/_token_transfer.html.eex
  4. 10
      apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex
  5. 94
      apps/block_scout_web/lib/block_scout_web/views/address_view.ex
  6. 93
      apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex
  7. 62
      apps/block_scout_web/priv/gettext/default.pot
  8. 62
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  9. 45
      apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs
  10. 124
      apps/block_scout_web/test/block_scout_web/views/address_view_test.exs
  11. 51
      apps/block_scout_web/test/block_scout_web/views/transaction_view_test.exs

@ -1,5 +1,3 @@
<%= if @address_hash do %> <%= link to: address_path(BlockScoutWeb.Endpoint, :show, @address_hash), "data-test": "address_hash_link" do %>
<%= link to: address_path(BlockScoutWeb.Endpoint, :show, @address_hash), "data-test": "address_hash_link" do %> <%= render BlockScoutWeb.AddressView, "_responsive_hash.html", address_hash: @address_hash, contract: @contract, truncate: assigns[:truncate] %>
<%= render BlockScoutWeb.AddressView, "_responsive_hash.html", address_hash: @address_hash, contract: @contract, truncate: assigns[:truncate] %>
<% end %>
<% end %> <% end %>

@ -11,13 +11,9 @@
<div class="col-md-7 col-lg-8 d-flex flex-column pr-2 pr-sm-2 pr-md-0"> <div class="col-md-7 col-lg-8 d-flex flex-column pr-2 pr-sm-2 pr-md-0">
<%= render "_link.html", transaction_hash: @transaction.hash %> <%= render "_link.html", transaction_hash: @transaction.hash %>
<span class="text-nowrap"> <span class="text-nowrap">
<%= BlockScoutWeb.AddressView.display_address_hash(assigns[:current_address], @transaction.from_address) %> <%= @transaction |> BlockScoutWeb.AddressView.address_partial_selector(:from, assigns[:current_address]) |> BlockScoutWeb.AddressView.render_partial() %>
&rarr; &rarr;
<%= if assigns[:current_address] && assigns[:current_address].hash == to_address_hash(@transaction) do %> <%= @transaction |> BlockScoutWeb.AddressView.address_partial_selector(:to, assigns[:current_address]) |> BlockScoutWeb.AddressView.render_partial() %>
<%= render BlockScoutWeb.AddressView, "_responsive_hash.html", address_hash: to_address_hash(@transaction), contract: BlockScoutWeb.AddressView.contract?(@transaction.to_address) %>
<% else %>
<%= render BlockScoutWeb.AddressView, "_link.html", address_hash: to_address_hash(@transaction), contract: BlockScoutWeb.AddressView.contract?(@transaction.to_address) %>
<% end %>
</span> </span>
<span class="d-flex flex-md-row flex-column mt-3 mt-md-0"> <span class="d-flex flex-md-row flex-column mt-3 mt-md-0">
<span class="tile-title"> <span class="tile-title">

@ -11,9 +11,9 @@
</span> </span>
<% end %> <% end %>
<% end %> <% end %>
<%= BlockScoutWeb.AddressView.display_address_hash(@address, @token_transfer.from_address, true) %> <%= @token_transfer |> BlockScoutWeb.AddressView.address_partial_selector(:from, @address, true) |> BlockScoutWeb.AddressView.render_partial() %>
&rarr; &rarr;
<%= BlockScoutWeb.AddressView.display_address_hash(@address, @token_transfer.to_address, true) %> <%= @token_transfer |> BlockScoutWeb.AddressView.address_partial_selector(:to, @address, true) |> BlockScoutWeb.AddressView.render_partial() %>
</span> </span>
<span class="col-12 col-md-7 ml-3 ml-sm-0"> <span class="col-12 col-md-7 ml-3 ml-sm-0">
<%= token_transfer_amount(@token_transfer) %> <%= token_transfer_amount(@token_transfer) %>

@ -14,14 +14,10 @@
</div> </div>
<h1 class="card-title"><%= gettext "Transaction Details" %> </h1> <h1 class="card-title"><%= gettext "Transaction Details" %> </h1>
<h3 data-test="transaction_detail_hash"><%= @transaction %> </h3> <h3 data-test="transaction_detail_hash"><%= @transaction %> </h3>
<span class="d-block mb-2"> <span class="d-block mb-2 text-muted">
<%= render BlockScoutWeb.AddressView, "_link.html", address_hash: @transaction.from_address_hash, contract: BlockScoutWeb.AddressView.contract?(@transaction.from_address) %> <%= @transaction |> BlockScoutWeb.AddressView.address_partial_selector(:from, nil) |> BlockScoutWeb.AddressView.render_partial() %>
<span class="text-muted"> &rarr; </span> <span class="text-muted"> &rarr; </span>
<%= if @transaction.to_address_hash do %> <%= @transaction |> BlockScoutWeb.AddressView.address_partial_selector(:to, nil) |> BlockScoutWeb.AddressView.render_partial() %>
<%= render BlockScoutWeb.AddressView, "_link.html", address_hash: @transaction.to_address_hash, contract: BlockScoutWeb.AddressView.contract?(@transaction.to_address) %>
<% else %>
<%= gettext("Contract Address Pending") %>
<% end %>
</span> </span>
<div class="d-flex flex-row justify-content-start text-muted"> <div class="d-flex flex-row justify-content-start text-muted">
<span class="mr-4 text-<%= BlockScoutWeb.TransactionView.type_suffix(@transaction) %>"><%= BlockScoutWeb.TransactionView.transaction_display_type(@transaction) %></span> <span class="mr-4 text-<%= BlockScoutWeb.TransactionView.type_suffix(@transaction) %>"><%= BlockScoutWeb.TransactionView.transaction_display_type(@transaction) %></span>

@ -1,10 +1,46 @@
defmodule BlockScoutWeb.AddressView do defmodule BlockScoutWeb.AddressView do
use BlockScoutWeb, :view use BlockScoutWeb, :view
alias Explorer.Chain.{Address, Hash, SmartContract} alias Explorer.Chain.{Address, Hash, SmartContract, TokenTransfer, Transaction}
@dialyzer :no_match @dialyzer :no_match
def address_partial_selector(struct_to_render_from, direction, current_address, truncate \\ false)
def address_partial_selector(%TokenTransfer{to_address: address}, :to, current_address, truncate) do
matching_address_check(current_address, address.hash, contract?(address), truncate)
end
def address_partial_selector(%TokenTransfer{from_address: address}, :from, current_address, truncate) do
matching_address_check(current_address, address.hash, contract?(address), truncate)
end
def address_partial_selector(
%Transaction{to_address_hash: nil, created_contract_address_hash: nil},
:to,
_current_address,
_truncate
) do
gettext("Contract Address Pending")
end
def address_partial_selector(
%Transaction{to_address_hash: nil, created_contract_address_hash: hash},
:to,
current_address,
truncate
) do
matching_address_check(current_address, hash, true, truncate)
end
def address_partial_selector(%Transaction{to_address: address}, :to, current_address, truncate) do
matching_address_check(current_address, address.hash, contract?(address), truncate)
end
def address_partial_selector(%Transaction{from_address: address}, :from, current_address, truncate) do
matching_address_check(current_address, address.hash, contract?(address), truncate)
end
def address_title(%Address{} = address) do def address_title(%Address{} = address) do
if contract?(address) do if contract?(address) do
gettext("Contract Address") gettext("Contract Address")
@ -45,16 +81,20 @@ defmodule BlockScoutWeb.AddressView do
|> Base.encode64() |> Base.encode64()
end end
def smart_contract_verified?(%Address{smart_contract: %SmartContract{}}), do: true def render_partial(%{partial: partial, address_hash: hash, contract: contract?, truncate: truncate}) do
render(
partial,
address_hash: hash,
contract: contract?,
truncate: truncate
)
end
def smart_contract_verified?(%Address{smart_contract: nil}), do: false def render_partial(text), do: text
def trimmed_hash(%Hash{} = hash) do def smart_contract_verified?(%Address{smart_contract: %SmartContract{}}), do: true
string_hash = to_string(hash)
"#{String.slice(string_hash, 0..5)}#{String.slice(string_hash, -6..-1)}"
end
def trimmed_hash(_), do: "" def smart_contract_verified?(%Address{smart_contract: nil}), do: false
def smart_contract_with_read_only_functions?(%Address{smart_contract: %SmartContract{}} = address) do def smart_contract_with_read_only_functions?(%Address{smart_contract: %SmartContract{}} = address) do
Enum.any?(address.smart_contract.abi, & &1["constant"]) Enum.any?(address.smart_contract.abi, & &1["constant"])
@ -62,32 +102,28 @@ defmodule BlockScoutWeb.AddressView do
def smart_contract_with_read_only_functions?(%Address{smart_contract: nil}), do: false def smart_contract_with_read_only_functions?(%Address{smart_contract: nil}), do: false
def display_address_hash(current_address, target_address, truncate \\ false) def trimmed_hash(%Hash{} = hash) do
string_hash = to_string(hash)
def display_address_hash(nil, target_address, truncate) do "#{String.slice(string_hash, 0..5)}#{String.slice(string_hash, -6..-1)}"
render(
"_link.html",
address_hash: target_address.hash,
contract: contract?(target_address),
truncate: truncate
)
end end
def display_address_hash(current_address, target_address, truncate) do def trimmed_hash(_), do: ""
if current_address.hash == target_address.hash do
render( defp matching_address_check(current_address, hash, contract?, truncate) do
"_responsive_hash.html", if current_address && current_address.hash == hash do
address_hash: current_address.hash, %{
contract: contract?(current_address), partial: "_responsive_hash.html",
address_hash: hash,
contract: contract?,
truncate: truncate truncate: truncate
) }
else else
render( %{
"_link.html", partial: "_link.html",
address_hash: target_address.hash, address_hash: hash,
contract: contract?(target_address), contract: contract?,
truncate: truncate truncate: truncate
) }
end end
end end
end end

@ -10,6 +10,8 @@ defmodule BlockScoutWeb.TransactionView do
defguardp is_transaction_type(mod) when mod in [InternalTransaction, Transaction] defguardp is_transaction_type(mod) when mod in [InternalTransaction, Transaction]
defdelegate formatted_timestamp(block), to: BlockView
def confirmations(%Transaction{block: block}, named_arguments) when is_list(named_arguments) do def confirmations(%Transaction{block: block}, named_arguments) when is_list(named_arguments) do
case block do case block do
nil -> 0 nil -> 0
@ -17,22 +19,19 @@ defmodule BlockScoutWeb.TransactionView do
end end
end end
def from_or_to_address?(_token_transfer, nil), do: false def contract_creation?(%Transaction{to_address: nil}), do: true
def from_or_to_address?(%{from_address_hash: from_hash, to_address_hash: to_hash}, %Address{hash: hash}) do
from_hash == hash || to_hash == hash
end
# This is the address to be shown in the to field
def to_address_hash(%Transaction{to_address_hash: nil, created_contract_address_hash: address_hash}), do: address_hash
def to_address_hash(%Transaction{to_address: %Address{hash: address_hash}}), do: address_hash def contract_creation?(_), do: false
def fee(%Transaction{} = transaction) do def fee(%Transaction{} = transaction) do
{_, value} = Chain.fee(transaction, :wei) {_, value} = Chain.fee(transaction, :wei)
value value
end end
def format_gas_limit(gas) do
Number.to_string!(gas)
end
def formatted_fee(%Transaction{} = transaction, opts) do def formatted_fee(%Transaction{} = transaction, opts) do
transaction transaction
|> Chain.fee(:wei) |> Chain.fee(:wei)
@ -43,34 +42,6 @@ defmodule BlockScoutWeb.TransactionView do
end end
end end
def gas_used(%Transaction{gas_used: nil}), do: gettext("Pending")
def gas_used(%Transaction{gas_used: gas_used}) do
Number.to_string!(gas_used)
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_token_transfers?(%Transaction{token_transfers: []}), do: false
def involves_token_transfers?(%Transaction{token_transfers: transfers}) when is_list(transfers), do: true
def contract_creation?(%Transaction{to_address: nil}), do: true
def contract_creation?(_), do: false
def qr_code(%Transaction{hash: hash}) do
hash
|> to_string()
|> QRCode.to_png()
|> Base.encode64()
end
def format_gas_limit(gas) do
Number.to_string!(gas)
end
def formatted_status(transaction) do def formatted_status(transaction) do
transaction transaction
|> Chain.transaction_to_status() |> Chain.transaction_to_status()
@ -82,7 +53,11 @@ defmodule BlockScoutWeb.TransactionView do
end end
end end
defdelegate formatted_timestamp(block), to: BlockView def from_or_to_address?(_token_transfer, nil), do: false
def from_or_to_address?(%{from_address_hash: from_hash, to_address_hash: to_hash}, %Address{hash: hash}) do
from_hash == hash || to_hash == hash
end
def gas(%type{gas: gas}) when is_transaction_type(type) do def gas(%type{gas: gas}) when is_transaction_type(type) do
Cldr.Number.to_string!(gas) Cldr.Number.to_string!(gas)
@ -95,22 +70,39 @@ defmodule BlockScoutWeb.TransactionView do
format_wei_value(gas_price, unit) format_wei_value(gas_price, unit)
end end
def gas_used(%Transaction{gas_used: nil}), do: gettext("Pending")
def gas_used(%Transaction{gas_used: gas_used}) do
Number.to_string!(gas_used)
end
def hash(%Transaction{hash: hash}) do def hash(%Transaction{hash: hash}) do
to_string(hash) to_string(hash)
end 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_token_transfers?(%Transaction{token_transfers: []}), do: false
def involves_token_transfers?(%Transaction{token_transfers: transfers}) when is_list(transfers), do: true
def qr_code(%Transaction{hash: hash}) do
hash
|> to_string()
|> QRCode.to_png()
|> Base.encode64()
end
def status(transaction) do def status(transaction) do
Chain.transaction_to_status(transaction) Chain.transaction_to_status(transaction)
end end
def type_suffix(%Transaction{} = transaction) do # This is the address to be shown in the to field
cond do def to_address_hash(%Transaction{to_address_hash: nil, created_contract_address_hash: address_hash}),
involves_token_transfers?(transaction) -> "token-transfer" do: address_hash
contract_creation?(transaction) -> "contract-creation"
involves_contract?(transaction) -> "contract-call" def to_address_hash(%Transaction{to_address: %Address{hash: address_hash}}), do: address_hash
true -> "transaction"
end
end
def transaction_display_type(%Transaction{} = transaction) do def transaction_display_type(%Transaction{} = transaction) do
cond do cond do
@ -121,6 +113,15 @@ defmodule BlockScoutWeb.TransactionView do
end end
end end
def type_suffix(%Transaction{} = transaction) do
cond do
involves_token_transfers?(transaction) -> "token-transfer"
contract_creation?(transaction) -> "contract-creation"
involves_contract?(transaction) -> "contract-call"
true -> "transaction"
end
end
@doc """ @doc """
Converts a transaction's Wei value to Ether and returns a formatted display value. Converts a transaction's Wei value to Ether and returns a formatted display value.

@ -52,7 +52,7 @@ msgstr ""
msgid "Transactions" msgid "Transactions"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/transaction/overview.html.eex:91 #: lib/block_scout_web/templates/transaction/overview.html.eex:87
msgid "Value" msgid "Value"
msgstr "" msgstr ""
@ -76,7 +76,7 @@ msgid "Miner"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/block/overview.html.eex:59 #: lib/block_scout_web/templates/block/overview.html.eex:59
#: lib/block_scout_web/templates/transaction/overview.html.eex:59 #: lib/block_scout_web/templates/transaction/overview.html.eex:55
msgid "Nonce" msgid "Nonce"
msgstr "" msgstr ""
@ -100,7 +100,7 @@ msgstr ""
msgid "Total Difficulty" msgid "Total Difficulty"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/transaction/overview.html.eex:38 #: lib/block_scout_web/templates/transaction/overview.html.eex:34
msgid "Block Number" msgid "Block Number"
msgstr "" msgstr ""
@ -112,7 +112,7 @@ msgstr ""
msgid "Cumulative Gas Used" msgid "Cumulative Gas Used"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/transaction/overview.html.eex:102 #: lib/block_scout_web/templates/transaction/overview.html.eex:98
msgid "Gas" msgid "Gas"
msgstr "" msgstr ""
@ -120,7 +120,7 @@ msgstr ""
msgid "Gas Price" msgid "Gas Price"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/transaction/overview.html.eex:72 #: lib/block_scout_web/templates/transaction/overview.html.eex:68
msgid "Input" msgid "Input"
msgstr "" msgstr ""
@ -132,7 +132,7 @@ msgstr ""
msgid "%{count} transactions in this block" msgid "%{count} transactions in this block"
msgstr "" msgstr ""
#: lib/block_scout_web/views/address_view.ex:12 #: lib/block_scout_web/views/address_view.ex:48
msgid "Address" msgid "Address"
msgstr "" msgstr ""
@ -148,7 +148,7 @@ msgstr ""
msgid "Overview" msgid "Overview"
msgstr "" msgstr ""
#: lib/block_scout_web/views/transaction_view.ex:81 #: lib/block_scout_web/views/transaction_view.ex:52
msgid "Success" msgid "Success"
msgstr "" msgstr ""
@ -199,9 +199,9 @@ msgstr ""
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:35 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:35
#: lib/block_scout_web/templates/transaction/index.html.eex:16 #: lib/block_scout_web/templates/transaction/index.html.eex:16
#: lib/block_scout_web/templates/transaction/index.html.eex:35 #: lib/block_scout_web/templates/transaction/index.html.eex:35
#: lib/block_scout_web/templates/transaction/overview.html.eex:47 #: lib/block_scout_web/templates/transaction/overview.html.eex:43
#: lib/block_scout_web/views/transaction_view.ex:46 #: lib/block_scout_web/views/transaction_view.ex:51
#: lib/block_scout_web/views/transaction_view.ex:80 #: lib/block_scout_web/views/transaction_view.ex:73
msgid "Pending" msgid "Pending"
msgstr "" msgstr ""
@ -269,11 +269,11 @@ msgstr ""
msgid "Next Page" msgid "Next Page"
msgstr "" msgstr ""
#: lib/block_scout_web/views/transaction_view.ex:78 #: lib/block_scout_web/views/transaction_view.ex:49
msgid "Failed" msgid "Failed"
msgstr "" msgstr ""
#: lib/block_scout_web/views/transaction_view.ex:79 #: lib/block_scout_web/views/transaction_view.ex:50
msgid "Out of Gas" msgid "Out of Gas"
msgstr "" msgstr ""
@ -292,8 +292,8 @@ msgstr ""
#: #:
#: lib/block_scout_web/templates/address_internal_transaction/_internal_transaction.html.eex:22 #: lib/block_scout_web/templates/address_internal_transaction/_internal_transaction.html.eex:22
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:68 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:68
#: lib/block_scout_web/templates/transaction/_tile.html.eex:24 #: lib/block_scout_web/templates/transaction/_tile.html.eex:20
#: lib/block_scout_web/templates/transaction/overview.html.eex:91 #: lib/block_scout_web/templates/transaction/overview.html.eex:87
#: lib/block_scout_web/templates/transaction_internal_transaction/_internal_transaction.html.eex:16 #: lib/block_scout_web/templates/transaction_internal_transaction/_internal_transaction.html.eex:16
#: lib/block_scout_web/views/wei_helpers.ex:72 #: lib/block_scout_web/views/wei_helpers.ex:72
msgid "Ether" msgid "Ether"
@ -453,7 +453,7 @@ msgstr ""
msgid "Total Gas Used" msgid "Total Gas Used"
msgstr "" msgstr ""
#: lib/block_scout_web/views/transaction_view.ex:120 #: lib/block_scout_web/views/transaction_view.ex:112
msgid "Transaction" msgid "Transaction"
msgstr "" msgstr ""
@ -467,8 +467,8 @@ msgid "View All"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:69 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:69
#: lib/block_scout_web/templates/transaction/_tile.html.eex:27 #: lib/block_scout_web/templates/transaction/_tile.html.eex:23
#: lib/block_scout_web/templates/transaction/overview.html.eex:64 #: lib/block_scout_web/templates/transaction/overview.html.eex:60
msgid "TX Fee" msgid "TX Fee"
msgstr "" msgstr ""
@ -476,7 +476,7 @@ msgstr ""
msgid "Contract" msgid "Contract"
msgstr "" msgstr ""
#: lib/block_scout_web/views/address_view.ex:10 #: lib/block_scout_web/views/address_view.ex:46
msgid "Contract Address" msgid "Contract Address"
msgstr "" msgstr ""
@ -540,7 +540,7 @@ msgid "Newer"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:118 #: lib/block_scout_web/views/transaction_view.ex:110
msgid "Contract Creation" msgid "Contract Creation"
msgstr "" msgstr ""
@ -634,12 +634,12 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:64 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:64
#: lib/block_scout_web/templates/transaction/overview.html.eex:23 #: lib/block_scout_web/views/address_view.ex:24
msgid "Contract Address Pending" msgid "Contract Address Pending"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:119 #: lib/block_scout_web/views/transaction_view.ex:111
msgid "Contract Call" msgid "Contract Call"
msgstr "" msgstr ""
@ -655,21 +655,21 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/tokens/token/_token_transfer.html.eex:36 #: lib/block_scout_web/templates/tokens/token/_token_transfer.html.eex:36
#: lib/block_scout_web/templates/transaction/_tile.html.eex:34 #: lib/block_scout_web/templates/transaction/_tile.html.eex:30
msgid "Block #%{number}" msgid "Block #%{number}"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: #:
#: lib/block_scout_web/templates/address_internal_transaction/_internal_transaction.html.eex:29 #: lib/block_scout_web/templates/address_internal_transaction/_internal_transaction.html.eex:29
#: lib/block_scout_web/templates/transaction/_tile.html.eex:47 #: lib/block_scout_web/templates/transaction/_tile.html.eex:43
msgid "IN" msgid "IN"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: #:
#: lib/block_scout_web/templates/address_internal_transaction/_internal_transaction.html.eex:27 #: lib/block_scout_web/templates/address_internal_transaction/_internal_transaction.html.eex:27
#: lib/block_scout_web/templates/transaction/_tile.html.eex:43 #: lib/block_scout_web/templates/transaction/_tile.html.eex:39
msgid "OUT" msgid "OUT"
msgstr "" msgstr ""
@ -714,12 +714,12 @@ msgid "Github"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:52 #: lib/block_scout_web/templates/transaction/overview.html.eex:48
msgid "Block Confirmations" msgid "Block Confirmations"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:114 #: lib/block_scout_web/templates/transaction/overview.html.eex:110
msgid "Limit" msgid "Limit"
msgstr "" msgstr ""
@ -735,14 +735,14 @@ msgid "There are no logs for this transaction."
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:107 #: lib/block_scout_web/templates/transaction/overview.html.eex:103
msgid "Used" msgid "Used"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/tokens/token/_token_transfer.html.eex:4 #: lib/block_scout_web/templates/tokens/token/_token_transfer.html.eex:4
#: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:4 #: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:4
#: lib/block_scout_web/views/transaction_view.ex:117 #: lib/block_scout_web/views/transaction_view.ex:109
msgid "Token Transfer" msgid "Token Transfer"
msgstr "" msgstr ""
@ -1001,12 +1001,12 @@ msgid "loading....."
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/_tile.html.eex:67 #: lib/block_scout_web/templates/transaction/_tile.html.eex:63
msgid "View More Transfers" msgid "View More Transfers"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/_tile.html.eex:68 #: lib/block_scout_web/templates/transaction/_tile.html.eex:64
msgid "View Less Transfers" msgid "View Less Transfers"
msgstr "" msgstr ""
@ -1016,7 +1016,7 @@ msgid "Less than"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:42 #: lib/block_scout_web/views/transaction_view.ex:41
msgid "Max of" msgid "Max of"
msgstr "" msgstr ""

@ -64,7 +64,7 @@ msgstr "BlockScout"
msgid "Transactions" msgid "Transactions"
msgstr "Transactions" msgstr "Transactions"
#: lib/block_scout_web/templates/transaction/overview.html.eex:91 #: lib/block_scout_web/templates/transaction/overview.html.eex:87
msgid "Value" msgid "Value"
msgstr "Value" msgstr "Value"
@ -88,7 +88,7 @@ msgid "Miner"
msgstr "Validator" msgstr "Validator"
#: lib/block_scout_web/templates/block/overview.html.eex:59 #: lib/block_scout_web/templates/block/overview.html.eex:59
#: lib/block_scout_web/templates/transaction/overview.html.eex:59 #: lib/block_scout_web/templates/transaction/overview.html.eex:55
msgid "Nonce" msgid "Nonce"
msgstr "Nonce" msgstr "Nonce"
@ -112,7 +112,7 @@ msgstr "Timestamp"
msgid "Total Difficulty" msgid "Total Difficulty"
msgstr "Total Difficulty" msgstr "Total Difficulty"
#: lib/block_scout_web/templates/transaction/overview.html.eex:38 #: lib/block_scout_web/templates/transaction/overview.html.eex:34
msgid "Block Number" msgid "Block Number"
msgstr "Block Height" msgstr "Block Height"
@ -124,7 +124,7 @@ msgstr "Transaction Details"
msgid "Cumulative Gas Used" msgid "Cumulative Gas Used"
msgstr "Cumulative Gas Used" msgstr "Cumulative Gas Used"
#: lib/block_scout_web/templates/transaction/overview.html.eex:102 #: lib/block_scout_web/templates/transaction/overview.html.eex:98
msgid "Gas" msgid "Gas"
msgstr "Gas" msgstr "Gas"
@ -132,7 +132,7 @@ msgstr "Gas"
msgid "Gas Price" msgid "Gas Price"
msgstr "Gas Price" msgstr "Gas Price"
#: lib/block_scout_web/templates/transaction/overview.html.eex:72 #: lib/block_scout_web/templates/transaction/overview.html.eex:68
msgid "Input" msgid "Input"
msgstr "Input" msgstr "Input"
@ -144,7 +144,7 @@ msgstr "%{confirmations} block confirmations"
msgid "%{count} transactions in this block" msgid "%{count} transactions in this block"
msgstr "%{count} transactions in this block" msgstr "%{count} transactions in this block"
#: lib/block_scout_web/views/address_view.ex:12 #: lib/block_scout_web/views/address_view.ex:48
msgid "Address" msgid "Address"
msgstr "Address" msgstr "Address"
@ -160,7 +160,7 @@ msgstr "From"
msgid "Overview" msgid "Overview"
msgstr "Overview" msgstr "Overview"
#: lib/block_scout_web/views/transaction_view.ex:81 #: lib/block_scout_web/views/transaction_view.ex:52
msgid "Success" msgid "Success"
msgstr "Success" msgstr "Success"
@ -211,9 +211,9 @@ msgstr "Showing %{count} Transactions"
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:35 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:35
#: lib/block_scout_web/templates/transaction/index.html.eex:16 #: lib/block_scout_web/templates/transaction/index.html.eex:16
#: lib/block_scout_web/templates/transaction/index.html.eex:35 #: lib/block_scout_web/templates/transaction/index.html.eex:35
#: lib/block_scout_web/templates/transaction/overview.html.eex:47 #: lib/block_scout_web/templates/transaction/overview.html.eex:43
#: lib/block_scout_web/views/transaction_view.ex:46 #: lib/block_scout_web/views/transaction_view.ex:51
#: lib/block_scout_web/views/transaction_view.ex:80 #: lib/block_scout_web/views/transaction_view.ex:73
msgid "Pending" msgid "Pending"
msgstr "Pending" msgstr "Pending"
@ -281,11 +281,11 @@ msgstr ""
msgid "Next Page" msgid "Next Page"
msgstr "" msgstr ""
#: lib/block_scout_web/views/transaction_view.ex:78 #: lib/block_scout_web/views/transaction_view.ex:49
msgid "Failed" msgid "Failed"
msgstr "" msgstr ""
#: lib/block_scout_web/views/transaction_view.ex:79 #: lib/block_scout_web/views/transaction_view.ex:50
msgid "Out of Gas" msgid "Out of Gas"
msgstr "" msgstr ""
@ -304,8 +304,8 @@ msgstr ""
#: #:
#: lib/block_scout_web/templates/address_internal_transaction/_internal_transaction.html.eex:22 #: lib/block_scout_web/templates/address_internal_transaction/_internal_transaction.html.eex:22
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:68 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:68
#: lib/block_scout_web/templates/transaction/_tile.html.eex:24 #: lib/block_scout_web/templates/transaction/_tile.html.eex:20
#: lib/block_scout_web/templates/transaction/overview.html.eex:91 #: lib/block_scout_web/templates/transaction/overview.html.eex:87
#: lib/block_scout_web/templates/transaction_internal_transaction/_internal_transaction.html.eex:16 #: lib/block_scout_web/templates/transaction_internal_transaction/_internal_transaction.html.eex:16
#: lib/block_scout_web/views/wei_helpers.ex:72 #: lib/block_scout_web/views/wei_helpers.ex:72
msgid "Ether" msgid "Ether"
@ -465,7 +465,7 @@ msgstr ""
msgid "Total Gas Used" msgid "Total Gas Used"
msgstr "" msgstr ""
#: lib/block_scout_web/views/transaction_view.ex:120 #: lib/block_scout_web/views/transaction_view.ex:112
msgid "Transaction" msgid "Transaction"
msgstr "" msgstr ""
@ -479,8 +479,8 @@ msgid "View All"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:69 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:69
#: lib/block_scout_web/templates/transaction/_tile.html.eex:27 #: lib/block_scout_web/templates/transaction/_tile.html.eex:23
#: lib/block_scout_web/templates/transaction/overview.html.eex:64 #: lib/block_scout_web/templates/transaction/overview.html.eex:60
msgid "TX Fee" msgid "TX Fee"
msgstr "" msgstr ""
@ -488,7 +488,7 @@ msgstr ""
msgid "Contract" msgid "Contract"
msgstr "" msgstr ""
#: lib/block_scout_web/views/address_view.ex:10 #: lib/block_scout_web/views/address_view.ex:46
msgid "Contract Address" msgid "Contract Address"
msgstr "" msgstr ""
@ -552,7 +552,7 @@ msgid "Newer"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:118 #: lib/block_scout_web/views/transaction_view.ex:110
msgid "Contract Creation" msgid "Contract Creation"
msgstr "" msgstr ""
@ -646,12 +646,12 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:64 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:64
#: lib/block_scout_web/templates/transaction/overview.html.eex:23 #: lib/block_scout_web/views/address_view.ex:24
msgid "Contract Address Pending" msgid "Contract Address Pending"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:119 #: lib/block_scout_web/views/transaction_view.ex:111
msgid "Contract Call" msgid "Contract Call"
msgstr "" msgstr ""
@ -667,21 +667,21 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/tokens/token/_token_transfer.html.eex:36 #: lib/block_scout_web/templates/tokens/token/_token_transfer.html.eex:36
#: lib/block_scout_web/templates/transaction/_tile.html.eex:34 #: lib/block_scout_web/templates/transaction/_tile.html.eex:30
msgid "Block #%{number}" msgid "Block #%{number}"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: #:
#: lib/block_scout_web/templates/address_internal_transaction/_internal_transaction.html.eex:29 #: lib/block_scout_web/templates/address_internal_transaction/_internal_transaction.html.eex:29
#: lib/block_scout_web/templates/transaction/_tile.html.eex:47 #: lib/block_scout_web/templates/transaction/_tile.html.eex:43
msgid "IN" msgid "IN"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: #:
#: lib/block_scout_web/templates/address_internal_transaction/_internal_transaction.html.eex:27 #: lib/block_scout_web/templates/address_internal_transaction/_internal_transaction.html.eex:27
#: lib/block_scout_web/templates/transaction/_tile.html.eex:43 #: lib/block_scout_web/templates/transaction/_tile.html.eex:39
msgid "OUT" msgid "OUT"
msgstr "" msgstr ""
@ -726,12 +726,12 @@ msgid "Github"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:52 #: lib/block_scout_web/templates/transaction/overview.html.eex:48
msgid "Block Confirmations" msgid "Block Confirmations"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:114 #: lib/block_scout_web/templates/transaction/overview.html.eex:110
msgid "Limit" msgid "Limit"
msgstr "" msgstr ""
@ -747,14 +747,14 @@ msgid "There are no logs for this transaction."
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:107 #: lib/block_scout_web/templates/transaction/overview.html.eex:103
msgid "Used" msgid "Used"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/tokens/token/_token_transfer.html.eex:4 #: lib/block_scout_web/templates/tokens/token/_token_transfer.html.eex:4
#: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:4 #: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:4
#: lib/block_scout_web/views/transaction_view.ex:117 #: lib/block_scout_web/views/transaction_view.ex:109
msgid "Token Transfer" msgid "Token Transfer"
msgstr "" msgstr ""
@ -1013,12 +1013,12 @@ msgid "loading....."
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/_tile.html.eex:67 #: lib/block_scout_web/templates/transaction/_tile.html.eex:63
msgid "View More Transfers" msgid "View More Transfers"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/_tile.html.eex:68 #: lib/block_scout_web/templates/transaction/_tile.html.eex:64
msgid "View Less Transfers" msgid "View Less Transfers"
msgstr "" msgstr ""
@ -1028,7 +1028,7 @@ msgid "Less than"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:42 #: lib/block_scout_web/views/transaction_view.ex:41
msgid "Max of" msgid "Max of"
msgstr "" msgstr ""

@ -2,7 +2,6 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
use BlockScoutWeb.FeatureCase, async: true use BlockScoutWeb.FeatureCase, async: true
alias Explorer.Chain.Wei alias Explorer.Chain.Wei
alias Explorer.Factory
alias BlockScoutWeb.{AddressPage, AddressView, Notifier} alias BlockScoutWeb.{AddressPage, AddressView, Notifier}
setup do setup do
@ -41,7 +40,7 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
describe "viewing contract creator" do describe "viewing contract creator" do
test "see the contract creator and transaction links", %{session: session} do test "see the contract creator and transaction links", %{session: session} do
address = insert(:address) address = insert(:address)
contract = insert(:address, contract_code: Factory.data("contract_code")) contract = insert(:contract_address)
transaction = insert(:transaction, from_address: address, created_contract_address: contract) transaction = insert(:transaction, from_address: address, created_contract_address: contract)
internal_transaction = internal_transaction =
@ -63,9 +62,9 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
test "see the contract creator and transaction links even when the creator is another contract", %{session: session} do test "see the contract creator and transaction links even when the creator is another contract", %{session: session} do
lincoln = insert(:address) lincoln = insert(:address)
contract = insert(:address, contract_code: Factory.data("contract_code")) contract = insert(:contract_address)
transaction = insert(:transaction) transaction = insert(:transaction)
another_contract = insert(:address, contract_code: Factory.data("contract_code")) another_contract = insert(:contract_address)
insert( insert(
:internal_transaction, :internal_transaction,
@ -285,12 +284,12 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
lincoln = addresses.lincoln lincoln = addresses.lincoln
taft = addresses.taft taft = addresses.taft
contract_token_address = insert(:contract_address) contract_address = insert(:contract_address)
insert(:token, contract_address: contract_token_address) insert(:token, contract_address: contract_address)
transaction = transaction =
:transaction :transaction
|> insert(from_address: lincoln, to_address: contract_token_address) |> insert(from_address: lincoln, to_address: contract_address)
|> with_block(block) |> with_block(block)
insert( insert(
@ -298,7 +297,7 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
from_address: lincoln, from_address: lincoln,
to_address: taft, to_address: taft,
transaction: transaction, transaction: transaction,
token_contract_address: contract_token_address token_contract_address: contract_address
) )
session session
@ -318,12 +317,12 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
taft = addresses.taft taft = addresses.taft
morty = build(:address) morty = build(:address)
contract_token_address = insert(:contract_address) contract_address = insert(:contract_address)
insert(:token, contract_address: contract_token_address) insert(:token, contract_address: contract_address)
transaction = transaction =
:transaction :transaction
|> insert(from_address: lincoln, to_address: contract_token_address) |> insert(from_address: lincoln, to_address: contract_address)
|> with_block(block) |> with_block(block)
insert( insert(
@ -331,7 +330,7 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
from_address: lincoln, from_address: lincoln,
to_address: taft, to_address: taft,
transaction: transaction, transaction: transaction,
token_contract_address: contract_token_address token_contract_address: contract_address
) )
insert( insert(
@ -339,7 +338,7 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
from_address: lincoln, from_address: lincoln,
to_address: morty, to_address: morty,
transaction: transaction, transaction: transaction,
token_contract_address: contract_token_address token_contract_address: contract_address
) )
session session
@ -358,17 +357,13 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
lincoln = addresses.lincoln lincoln = addresses.lincoln
taft = addresses.taft taft = addresses.taft
contract_token_address = contract_address = insert(:contract_address)
insert(
:address,
contract_code: Factory.data("contract_code")
)
insert(:token, contract_address: contract_token_address) insert(:token, contract_address: contract_address)
transaction = transaction =
:transaction :transaction
|> insert(from_address: lincoln, to_address: contract_token_address) |> insert(from_address: lincoln, to_address: contract_address)
|> with_block(block) |> with_block(block)
insert_list( insert_list(
@ -377,7 +372,7 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
from_address: lincoln, from_address: lincoln,
to_address: taft, to_address: taft,
transaction: transaction, transaction: transaction,
token_contract_address: contract_token_address token_contract_address: contract_address
) )
session session
@ -393,12 +388,12 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
lincoln = addresses.lincoln lincoln = addresses.lincoln
taft = addresses.taft taft = addresses.taft
contract_token_address = insert(:contract_address) contract_address = insert(:contract_address)
insert(:token, contract_address: contract_token_address) insert(:token, contract_address: contract_address)
transaction = transaction =
:transaction :transaction
|> insert(from_address: lincoln, to_address: contract_token_address) |> insert(from_address: lincoln, to_address: contract_address)
|> with_block(block) |> with_block(block)
insert_list( insert_list(
@ -407,7 +402,7 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
from_address: lincoln, from_address: lincoln,
to_address: taft, to_address: taft,
transaction: transaction, transaction: transaction,
token_contract_address: contract_token_address token_contract_address: contract_address
) )
session session

@ -1,9 +1,106 @@
defmodule BlockScoutWeb.AddressViewTest do defmodule BlockScoutWeb.AddressViewTest do
use BlockScoutWeb.ConnCase, async: true use BlockScoutWeb.ConnCase, async: true
alias Explorer.Chain.Data alias Explorer.Chain.{Address, Data, Transaction}
alias BlockScoutWeb.AddressView alias BlockScoutWeb.AddressView
describe "address_partial_selector/4" do
test "for a pending contract creation to address" do
transaction = insert(:transaction, to_address: nil, created_contract_address_hash: nil)
assert AddressView.address_partial_selector(transaction, :to, nil) == "Contract Address Pending"
end
test "will truncate address" do
transaction = %Transaction{to_address_hash: hash} = insert(:transaction)
assert %{
partial: "_link.html",
address_hash: ^hash,
contract: false,
truncate: true
} = AddressView.address_partial_selector(transaction, :to, nil, true)
end
test "for a non-contract to address not on address page" do
transaction = %Transaction{to_address_hash: hash} = insert(:transaction)
assert %{
partial: "_link.html",
address_hash: ^hash,
contract: false,
truncate: false
} = AddressView.address_partial_selector(transaction, :to, nil)
end
test "for a non-contract to address non matching address page" do
transaction = %Transaction{to_address_hash: hash} = insert(:transaction)
assert %{
partial: "_link.html",
address_hash: ^hash,
contract: false,
truncate: false
} = AddressView.address_partial_selector(transaction, :to, nil)
end
test "for a non-contract to address matching address page" do
transaction = %Transaction{to_address_hash: hash} = insert(:transaction)
assert %{
partial: "_responsive_hash.html",
address_hash: ^hash,
contract: false,
truncate: false
} = AddressView.address_partial_selector(transaction, :to, transaction.to_address)
end
test "for a contract to address non matching address page" do
contract = %Address{hash: hash} = insert(:contract_address)
transaction = insert(:transaction, to_address: nil, created_contract_address: contract)
assert %{
partial: "_link.html",
address_hash: ^hash,
contract: true,
truncate: false
} = AddressView.address_partial_selector(transaction, :to, transaction.to_address)
end
test "for a contract to address matching address page" do
contract = %Address{hash: hash} = insert(:contract_address)
transaction = insert(:transaction, to_address: nil, created_contract_address: contract)
assert %{
partial: "_responsive_hash.html",
address_hash: ^hash,
contract: true,
truncate: false
} = AddressView.address_partial_selector(transaction, :to, contract)
end
test "for a non-contract from address not on address page" do
transaction = %Transaction{to_address_hash: hash} = insert(:transaction)
assert %{
partial: "_link.html",
address_hash: ^hash,
contract: false,
truncate: false
} = AddressView.address_partial_selector(transaction, :to, nil)
end
test "for a non-contract from address matching address page" do
transaction = %Transaction{from_address_hash: hash} = insert(:transaction)
assert %{
partial: "_responsive_hash.html",
address_hash: ^hash,
contract: false,
truncate: false
} = AddressView.address_partial_selector(transaction, :from, transaction.from_address)
end
end
describe "contract?/1" do describe "contract?/1" do
test "with a smart contract" do test "with a smart contract" do
{:ok, code} = Data.cast("0x000000000000000000000000862d67cb0773ee3f8ce7ea89b328ffea861ab3ef") {:ok, code} = Data.cast("0x000000000000000000000000862d67cb0773ee3f8ce7ea89b328ffea861ab3ef")
@ -15,6 +112,10 @@ defmodule BlockScoutWeb.AddressViewTest do
address = insert(:address, contract_code: nil) address = insert(:address, contract_code: nil)
refute AddressView.contract?(address) refute AddressView.contract?(address)
end end
test "with nil address" do
assert AddressView.contract?(nil)
end
end end
describe "qr_code/1" do describe "qr_code/1" do
@ -24,6 +125,27 @@ defmodule BlockScoutWeb.AddressViewTest do
end end
end end
describe "render_partial/1" do
test "renders _link partial" do
%Address{hash: hash} = build(:address)
assert {:safe, _} =
AddressView.render_partial(%{partial: "_link.html", address_hash: hash, contract: false, truncate: false})
end
test "renders _responsive_hash partial" do
%Address{hash: hash} = build(:address)
assert {:safe, _} =
AddressView.render_partial(%{
partial: "_responsive_hash.html",
address_hash: hash,
contract: false,
truncate: false
})
end
end
describe "smart_contract_verified?/1" do describe "smart_contract_verified?/1" do
test "returns true when smart contract is verified" do test "returns true when smart contract is verified" do
smart_contract = insert(:smart_contract) smart_contract = insert(:smart_contract)

@ -5,6 +5,35 @@ defmodule BlockScoutWeb.TransactionViewTest do
alias Explorer.Repo alias Explorer.Repo
alias BlockScoutWeb.TransactionView alias BlockScoutWeb.TransactionView
describe "confirmations/2" do
test "returns 0 if pending transaction" do
transaction = build(:transaction, block: nil)
assert 0 == TransactionView.confirmations(transaction, [])
end
test "returns string of number of blocks validated since subject block" do
block = insert(:block)
transaction =
:transaction
|> insert()
|> with_block(block)
assert "1" == TransactionView.confirmations(transaction, max_block_number: block.number + 1)
end
end
describe "contract_creation?/1" do
test "returns true if contract creation transaction" do
assert TransactionView.contract_creation?(build(:transaction, to_address: nil))
end
test "returns false if not contract" do
refute TransactionView.contract_creation?(build(:transaction))
end
end
describe "formatted_fee/2" do describe "formatted_fee/2" do
test "pending transaction with no Receipt" do test "pending transaction with no Receipt" do
{:ok, gas_price} = Wei.cast(3_000_000_000) {:ok, gas_price} = Wei.cast(3_000_000_000)
@ -78,10 +107,32 @@ defmodule BlockScoutWeb.TransactionViewTest do
end end
end end
test "gas/1 returns the gas as a string" do
assert "2" == TransactionView.gas(build(:transaction, gas: 2))
end
test "hash/1 returns the hash as a string" do
assert "test" == TransactionView.hash(build(:transaction, hash: "test"))
end
describe "qr_code/1" do describe "qr_code/1" do
test "it returns an encoded value" do test "it returns an encoded value" do
transaction = build(:transaction) transaction = build(:transaction)
assert {:ok, _} = Base.decode64(TransactionView.qr_code(transaction)) assert {:ok, _} = Base.decode64(TransactionView.qr_code(transaction))
end end
end end
describe "to_address_hash/1" do
test "returns contract address for created contract transaction" do
contract = insert(:contract_address)
transaction = insert(:transaction, to_address: nil, created_contract_address: contract)
assert contract.hash == TransactionView.to_address_hash(transaction)
end
test "returns hash for transaction" do
address = insert(:address)
transaction = insert(:transaction, to_address: address)
assert address.hash == TransactionView.to_address_hash(transaction)
end
end
end end

Loading…
Cancel
Save