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 %>
<%= render BlockScoutWeb.AddressView, "_responsive_hash.html", address_hash: @address_hash, contract: @contract, truncate: assigns[:truncate] %>
<% end %>
<%= 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] %>
<% 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">
<%= render "_link.html", transaction_hash: @transaction.hash %>
<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;
<%= if assigns[:current_address] && assigns[:current_address].hash == to_address_hash(@transaction) do %>
<%= 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 %>
<%= @transaction |> BlockScoutWeb.AddressView.address_partial_selector(:to, assigns[:current_address]) |> BlockScoutWeb.AddressView.render_partial() %>
</span>
<span class="d-flex flex-md-row flex-column mt-3 mt-md-0">
<span class="tile-title">

@ -11,9 +11,9 @@
</span>
<% 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;
<%= 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 class="col-12 col-md-7 ml-3 ml-sm-0">
<%= token_transfer_amount(@token_transfer) %>

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

@ -1,10 +1,46 @@
defmodule BlockScoutWeb.AddressView do
use BlockScoutWeb, :view
alias Explorer.Chain.{Address, Hash, SmartContract}
alias Explorer.Chain.{Address, Hash, SmartContract, TokenTransfer, Transaction}
@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
if contract?(address) do
gettext("Contract Address")
@ -45,16 +81,20 @@ defmodule BlockScoutWeb.AddressView do
|> Base.encode64()
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
string_hash = to_string(hash)
"#{String.slice(string_hash, 0..5)}#{String.slice(string_hash, -6..-1)}"
end
def smart_contract_verified?(%Address{smart_contract: %SmartContract{}}), do: true
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
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 display_address_hash(current_address, target_address, truncate \\ false)
def display_address_hash(nil, target_address, truncate) do
render(
"_link.html",
address_hash: target_address.hash,
contract: contract?(target_address),
truncate: truncate
)
def trimmed_hash(%Hash{} = hash) do
string_hash = to_string(hash)
"#{String.slice(string_hash, 0..5)}#{String.slice(string_hash, -6..-1)}"
end
def display_address_hash(current_address, target_address, truncate) do
if current_address.hash == target_address.hash do
render(
"_responsive_hash.html",
address_hash: current_address.hash,
contract: contract?(current_address),
def trimmed_hash(_), do: ""
defp matching_address_check(current_address, hash, contract?, truncate) do
if current_address && current_address.hash == hash do
%{
partial: "_responsive_hash.html",
address_hash: hash,
contract: contract?,
truncate: truncate
)
}
else
render(
"_link.html",
address_hash: target_address.hash,
contract: contract?(target_address),
%{
partial: "_link.html",
address_hash: hash,
contract: contract?,
truncate: truncate
)
}
end
end
end

@ -10,6 +10,8 @@ defmodule BlockScoutWeb.TransactionView do
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
case block do
nil -> 0
@ -17,22 +19,19 @@ defmodule BlockScoutWeb.TransactionView do
end
end
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
# 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 contract_creation?(%Transaction{to_address: nil}), do: true
def to_address_hash(%Transaction{to_address: %Address{hash: address_hash}}), do: address_hash
def contract_creation?(_), do: false
def fee(%Transaction{} = transaction) do
{_, value} = Chain.fee(transaction, :wei)
value
end
def format_gas_limit(gas) do
Number.to_string!(gas)
end
def formatted_fee(%Transaction{} = transaction, opts) do
transaction
|> Chain.fee(:wei)
@ -43,34 +42,6 @@ defmodule BlockScoutWeb.TransactionView do
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
transaction
|> Chain.transaction_to_status()
@ -82,7 +53,11 @@ defmodule BlockScoutWeb.TransactionView do
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
Cldr.Number.to_string!(gas)
@ -95,22 +70,39 @@ defmodule BlockScoutWeb.TransactionView do
format_wei_value(gas_price, unit)
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
to_string(hash)
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
Chain.transaction_to_status(transaction)
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
# 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 transaction_display_type(%Transaction{} = transaction) do
cond do
@ -121,6 +113,15 @@ defmodule BlockScoutWeb.TransactionView do
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 """
Converts a transaction's Wei value to Ether and returns a formatted display value.

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

@ -64,7 +64,7 @@ msgstr "BlockScout"
msgid "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"
msgstr "Value"
@ -88,7 +88,7 @@ msgid "Miner"
msgstr "Validator"
#: 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"
msgstr "Nonce"
@ -112,7 +112,7 @@ msgstr "Timestamp"
msgid "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"
msgstr "Block Height"
@ -124,7 +124,7 @@ msgstr "Transaction Details"
msgid "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"
msgstr "Gas"
@ -132,7 +132,7 @@ msgstr "Gas"
msgid "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"
msgstr "Input"
@ -144,7 +144,7 @@ msgstr "%{confirmations} block confirmations"
msgid "%{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"
msgstr "Address"
@ -160,7 +160,7 @@ msgstr "From"
msgid "Overview"
msgstr "Overview"
#: lib/block_scout_web/views/transaction_view.ex:81
#: lib/block_scout_web/views/transaction_view.ex:52
msgid "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/transaction/index.html.eex:16
#: lib/block_scout_web/templates/transaction/index.html.eex:35
#: lib/block_scout_web/templates/transaction/overview.html.eex:47
#: lib/block_scout_web/views/transaction_view.ex:46
#: lib/block_scout_web/views/transaction_view.ex:80
#: lib/block_scout_web/templates/transaction/overview.html.eex:43
#: lib/block_scout_web/views/transaction_view.ex:51
#: lib/block_scout_web/views/transaction_view.ex:73
msgid "Pending"
msgstr "Pending"
@ -281,11 +281,11 @@ msgstr ""
msgid "Next Page"
msgstr ""
#: lib/block_scout_web/views/transaction_view.ex:78
#: lib/block_scout_web/views/transaction_view.ex:49
msgid "Failed"
msgstr ""
#: lib/block_scout_web/views/transaction_view.ex:79
#: lib/block_scout_web/views/transaction_view.ex:50
msgid "Out of Gas"
msgstr ""
@ -304,8 +304,8 @@ msgstr ""
#:
#: 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/transaction/_tile.html.eex:24
#: lib/block_scout_web/templates/transaction/overview.html.eex:91
#: lib/block_scout_web/templates/transaction/_tile.html.eex:20
#: 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/views/wei_helpers.ex:72
msgid "Ether"
@ -465,7 +465,7 @@ msgstr ""
msgid "Total Gas Used"
msgstr ""
#: lib/block_scout_web/views/transaction_view.ex:120
#: lib/block_scout_web/views/transaction_view.ex:112
msgid "Transaction"
msgstr ""
@ -479,8 +479,8 @@ msgid "View All"
msgstr ""
#: 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/overview.html.eex:64
#: lib/block_scout_web/templates/transaction/_tile.html.eex:23
#: lib/block_scout_web/templates/transaction/overview.html.eex:60
msgid "TX Fee"
msgstr ""
@ -488,7 +488,7 @@ msgstr ""
msgid "Contract"
msgstr ""
#: lib/block_scout_web/views/address_view.ex:10
#: lib/block_scout_web/views/address_view.ex:46
msgid "Contract Address"
msgstr ""
@ -552,7 +552,7 @@ msgid "Newer"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:118
#: lib/block_scout_web/views/transaction_view.ex:110
msgid "Contract Creation"
msgstr ""
@ -646,12 +646,12 @@ msgstr ""
#, elixir-format
#: 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"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:119
#: lib/block_scout_web/views/transaction_view.ex:111
msgid "Contract Call"
msgstr ""
@ -667,21 +667,21 @@ msgstr ""
#, elixir-format
#: 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}"
msgstr ""
#, elixir-format
#:
#: 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"
msgstr ""
#, elixir-format
#:
#: 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"
msgstr ""
@ -726,12 +726,12 @@ msgid "Github"
msgstr ""
#, 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"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:114
#: lib/block_scout_web/templates/transaction/overview.html.eex:110
msgid "Limit"
msgstr ""
@ -747,14 +747,14 @@ msgid "There are no logs for this transaction."
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:107
#: lib/block_scout_web/templates/transaction/overview.html.eex:103
msgid "Used"
msgstr ""
#, elixir-format
#: 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/views/transaction_view.ex:117
#: lib/block_scout_web/views/transaction_view.ex:109
msgid "Token Transfer"
msgstr ""
@ -1013,12 +1013,12 @@ msgid "loading....."
msgstr ""
#, 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"
msgstr ""
#, 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"
msgstr ""
@ -1028,7 +1028,7 @@ msgid "Less than"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:42
#: lib/block_scout_web/views/transaction_view.ex:41
msgid "Max of"
msgstr ""

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

@ -1,9 +1,106 @@
defmodule BlockScoutWeb.AddressViewTest do
use BlockScoutWeb.ConnCase, async: true
alias Explorer.Chain.Data
alias Explorer.Chain.{Address, Data, Transaction}
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
test "with a smart contract" do
{:ok, code} = Data.cast("0x000000000000000000000000862d67cb0773ee3f8ce7ea89b328ffea861ab3ef")
@ -15,6 +112,10 @@ defmodule BlockScoutWeb.AddressViewTest do
address = insert(:address, contract_code: nil)
refute AddressView.contract?(address)
end
test "with nil address" do
assert AddressView.contract?(nil)
end
end
describe "qr_code/1" do
@ -24,6 +125,27 @@ defmodule BlockScoutWeb.AddressViewTest do
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
test "returns true when smart contract is verified" do
smart_contract = insert(:smart_contract)

@ -5,6 +5,35 @@ defmodule BlockScoutWeb.TransactionViewTest do
alias Explorer.Repo
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
test "pending transaction with no Receipt" do
{:ok, gas_price} = Wei.cast(3_000_000_000)
@ -78,10 +107,32 @@ defmodule BlockScoutWeb.TransactionViewTest do
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
test "it returns an encoded value" do
transaction = build(:transaction)
assert {:ok, _} = Base.decode64(TransactionView.qr_code(transaction))
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

Loading…
Cancel
Save