Skip to content

Commit

Permalink
Merge pull request #3607 from poanetwork/vb-contract-reader-fix
Browse files Browse the repository at this point in the history
Process :bool, :string types in contract together with  string representations
  • Loading branch information
vbaranov committed Feb 5, 2021
2 parents 082a928 + 55eba0e commit b9b3088
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

### Fixes
- [#3600](https://github.com/poanetwork/blockscout/pull/3600) - Prevent update validator metadata with empty name from contract
- [#3592](https://github.com/poanetwork/blockscout/pull/3592), [#3601](https://github.com/poanetwork/blockscout/pull/3601) - Contract interaction: fix nested tuples in the output view, add formatting
- [#3592](https://github.com/poanetwork/blockscout/pull/3592), [#3601](https://github.com/poanetwork/blockscout/pull/3601), [#3607](https://github.com/poanetwork/blockscout/pull/3607) - Contract interaction: fix nested tuples in the output view, add formatting
- [#3583](https://github.com/poanetwork/blockscout/pull/3583) - Reduce RPC requests and DB changes by Staking DApp
- [#3577](https://github.com/poanetwork/blockscout/pull/3577) - Eliminate GraphiQL page XSS attack

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ defmodule BlockScoutWeb.SmartContractView do

def values_with_type(value, "string", _components), do: render_type_value("string", value)

def values_with_type(value, :string, _components), do: render_type_value("string", value)

def values_with_type(value, "bool", _components), do: render_type_value("bool", to_string(value))

def values_with_type(value, :bool, _components), do: render_type_value("bool", to_string(value))

def values_with_type(value, type, _components) do
if String.starts_with?(type, "uint") do
render_type_value(type, to_string(value))
Expand Down Expand Up @@ -166,8 +170,12 @@ defmodule BlockScoutWeb.SmartContractView do

def values_only(value, "string", _components), do: value

def values_only(value, :string, _components), do: value

def values_only(value, "bool", _components), do: to_string(value)

def values_only(value, :bool, _components), do: to_string(value)

def values_only(value, type, _components) do
if String.starts_with?(type, "uint") do
to_string(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,24 @@ defmodule BlockScoutWeb.SmartContractViewTest do
assert SmartContractView.values_only(value, "string", nil) == "POA"
end

test "returns the value when the type is :string" do
value = "POA"

assert SmartContractView.values_only(value, :string, nil) == "POA"
end

test "returns the value when the type is boolean" do
value = "true"

assert SmartContractView.values_only(value, "bool", nil) == "true"
end

test "returns the value when the type is :bool" do
value = "true"

assert SmartContractView.values_only(value, :bool, nil) == "true"
end

test "returns the value when the type is bytes4" do
value = <<228, 184, 12, 77>>

Expand Down

0 comments on commit b9b3088

Please sign in to comment.