Merge pull request #1022 from poanetwork/gsf-address-is-printed-weird

address type is printed weird on smart contracts
pull/1033/head
Andrew Cravenho 6 years ago committed by GitHub
commit a33d5ef48f
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/_function_response.html.eex
  2. 11
      apps/block_scout_web/lib/block_scout_web/views/smart_contract_view.ex
  3. 26
      apps/block_scout_web/test/block_scout_web/views/tokens/smart_contract_view_test.exs

@ -5,6 +5,6 @@
[<%= for item <- @outputs do %> [<%= for item <- @outputs do %>
<span class="function-response-item"><%= if named_argument?(item) do %><%= item["name"] %> <span class="function-response-item"><%= if named_argument?(item) do %><%= item["name"] %>
<% end %> <% end %>
<span class="text-muted">(<%= item["type"] %>)</span> : <%= values(item["value"]) %></span><% end %>] <span class="text-muted">(<%= item["type"] %>)</span> : <%= values(item["value"], item["type"]) %></span><% end %>]
</pre> </pre>
</div> </div>

@ -3,13 +3,18 @@ defmodule BlockScoutWeb.SmartContractView do
def queryable?(inputs), do: Enum.any?(inputs) def queryable?(inputs), do: Enum.any?(inputs)
def address?(type), do: type == "address" def address?(type), do: type in ["address", "address payable"]
def named_argument?(%{"name" => ""}), do: false def named_argument?(%{"name" => ""}), do: false
def named_argument?(%{"name" => nil}), do: false def named_argument?(%{"name" => nil}), do: false
def named_argument?(%{"name" => _}), do: true def named_argument?(%{"name" => _}), do: true
def named_argument?(_), do: false def named_argument?(_), do: false
def values(values) when is_list(values), do: Enum.join(values, ",") def values(value, type) when type in ["address", "address payable"] do
def values(value), do: value {:ok, address} = Explorer.Chain.Hash.Address.cast(value)
to_string(address)
end
def values(values, _) when is_list(values), do: Enum.join(values, ",")
def values(value, _), do: value
end end

@ -24,6 +24,12 @@ defmodule BlockScoutWeb.SmartContractViewTest do
assert SmartContractView.address?(type) assert SmartContractView.address?(type)
end end
test "returns true when the type is equal to the string 'address payable'" do
type = "address payable"
assert SmartContractView.address?(type)
end
test "returns false when the type is not equal the string 'address'" do test "returns false when the type is not equal the string 'address'" do
type = "name" type = "name"
@ -57,17 +63,27 @@ defmodule BlockScoutWeb.SmartContractViewTest do
end end
end end
describe "values/1" do describe "values/2" do
test "joins the values when it is a list" do test "joins the values when it is a list of a given type" do
values = [8, 6, 9, 2, 2, 37] values = [8, 6, 9, 2, 2, 37]
assert SmartContractView.values(values) == "8,6,9,2,2,37" assert SmartContractView.values(values, "type") == "8,6,9,2,2,37"
end
test "convert the value to string receiving a value and the 'address' type" do
value = <<95, 38, 9, 115, 52, 182, 163, 43, 121, 81, 223, 97, 253, 12, 88, 3, 236, 93, 131, 84>>
assert SmartContractView.values(value, "address") == "0x5f26097334b6a32b7951df61fd0c5803ec5d8354"
end
test "convert the value to string receiving a value and the 'address payable' type" do
value = <<95, 38, 9, 115, 52, 182, 163, 43, 121, 81, 223, 97, 253, 12, 88, 3, 236, 93, 131, 84>>
assert SmartContractView.values(value, "address payable") == "0x5f26097334b6a32b7951df61fd0c5803ec5d8354"
end end
test "returns the value" do test "returns the value when the type is neither 'address' nor 'address payable'" do
value = "POA" value = "POA"
assert SmartContractView.values(value) == "POA" assert SmartContractView.values(value, "not address") == "POA"
end end
end end
end end

Loading…
Cancel
Save