Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove utf-8 string decoding from normalizers #974

Merged
merged 3 commits into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/core/contracts/test_contract_call_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
Decimal,
getcontext,
)
from distutils.version import (
LooseVersion,
)
import json
import pytest

import eth_abi
from hexbytes import (
HexBytes,
)
Expand Down Expand Up @@ -184,6 +188,9 @@ def test_call_get_string_value(string_contract, call):
assert result == "Caqalai"


@pytest.mark.skipif(
LooseVersion(eth_abi.__version__) >= LooseVersion("2"),
reason="eth-abi >=2 does utf-8 string decoding")
def test_call_read_string_variable(string_contract, call):
result = call(contract=string_contract,
contract_function='constValue')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a second test that shows what happens on an ABI decoding error. We should probably do something like capture the eth-abi error and re-raise a generic ValueError.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It raises a 'BadFunctionCallOutput' error

Expand Down
11 changes: 9 additions & 2 deletions web3/utils/normalizers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@

import codecs
from distutils.version import (
LooseVersion,
)
import functools
import json

import eth_abi
from eth_abi.abi import (
process_type,
)
Expand Down Expand Up @@ -140,11 +144,14 @@ def abi_ens_resolver(w3, abi_type, val):


BASE_RETURN_NORMALIZERS = [
addresses_checksummed,
decode_abi_strings,
addresses_checksummed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nitpick leave the trailing comma.

]


if LooseVersion(eth_abi.__version__) < LooseVersion("2"):
BASE_RETURN_NORMALIZERS.append(decode_abi_strings)


#
# Property Normalizers
#
Expand Down