Merge pull request #1038 from poanetwork/ln-invalid-address-display-on-read-contract

Fix address[] display when reading Smart Contracts
pull/1036/head
Andrew Cravenho 6 years ago committed by GitHub
commit b4533802ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      apps/block_scout_web/lib/block_scout_web/templates/smart_contract/_functions.html.eex
  2. 6
      apps/block_scout_web/lib/block_scout_web/views/smart_contract_view.ex
  3. 10
      apps/block_scout_web/test/block_scout_web/views/tokens/smart_contract_view_test.exs

@ -51,7 +51,7 @@
</span> </span>
</div> </div>
<% else %> <% else %>
<%= output["value"] %> <%= values(output["value"], output["type"]) %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>

@ -10,6 +10,12 @@ defmodule BlockScoutWeb.SmartContractView do
def named_argument?(%{"name" => _}), do: true def named_argument?(%{"name" => _}), do: true
def named_argument?(_), do: false def named_argument?(_), do: false
def values(addresses, type) when type == "address[]" do
addresses
|> Enum.map(&values(&1, "address"))
|> Enum.join(", ")
end
def values(value, type) when type in ["address", "address payable"] do def values(value, type) when type in ["address", "address payable"] do
{:ok, address} = Explorer.Chain.Hash.Address.cast(value) {:ok, address} = Explorer.Chain.Hash.Address.cast(value)
to_string(address) to_string(address)

@ -80,6 +80,16 @@ defmodule BlockScoutWeb.SmartContractViewTest do
assert SmartContractView.values(value, "address payable") == "0x5f26097334b6a32b7951df61fd0c5803ec5d8354" assert SmartContractView.values(value, "address payable") == "0x5f26097334b6a32b7951df61fd0c5803ec5d8354"
end end
test "convert each value to string and join them when receiving 'address[]' as the type" do
value = [
<<95, 38, 9, 115, 52, 182, 163, 43, 121, 81, 223, 97, 253, 12, 88, 3, 236, 93, 131, 84>>,
<<207, 38, 14, 163, 23, 85, 86, 55, 197, 95, 112, 229, 93, 186, 141, 90, 216, 65, 76, 176>>
]
assert SmartContractView.values(value, "address[]") ==
"0x5f26097334b6a32b7951df61fd0c5803ec5d8354, 0xcf260ea317555637c55f70e55dba8d5ad8414cb0"
end
test "returns the value when the type is neither 'address' nor 'address payable'" do test "returns the value when the type is neither 'address' nor 'address payable'" do
value = "POA" value = "POA"

Loading…
Cancel
Save