Skip to content

Commit

Permalink
Merge pull request #88 from davesque/remove-collapse-type
Browse files Browse the repository at this point in the history
Remove collapse type
  • Loading branch information
davesque committed Aug 29, 2018
2 parents 2b0a310 + 9f87fa9 commit 48c9342
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 54 deletions.
5 changes: 5 additions & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ Development
- Added support for nested dynamic arrays from the Solidity version 2 ABI
- Added support for non-standard packed mode encoding
- Added support for tuple array types e.g. ``(int,int)[]``
- Backwards Incompatible Changes

- The :meth:`~eth_abi.abi.encode_single` and
:meth:`~eth_abi.abi.decode_single` functions no longer accept type tuples
to identify ABI types. Only type strings are accepted.

v2.0.0-alpha.1
-------------
Expand Down
22 changes: 3 additions & 19 deletions eth_abi/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
registry,
)
from eth_abi.utils.parsing import ( # noqa: F401
collapse_type,
process_type,
)

Expand All @@ -42,12 +41,7 @@ def encode_single(typ: TypeStr, arg: Any) -> bytes:
:returns: The binary representation of the python value ``arg`` as a value
of the ABI type ``typ``.
"""
if isinstance(typ, str):
type_str = typ
else:
type_str = collapse_type(*typ)

encoder = registry.get_encoder(type_str)
encoder = registry.get_encoder(typ)

return encoder(arg)

Expand Down Expand Up @@ -87,12 +81,7 @@ def is_encodable(typ: TypeStr, arg: Any) -> bool:
:returns: ``True`` if ``arg`` is encodable as a value of the ABI type
``typ``. Otherwise, ``False``.
"""
if isinstance(typ, str):
type_str = typ
else:
type_str = collapse_type(*typ)

encoder = registry.get_encoder(type_str)
encoder = registry.get_encoder(typ)

try:
encoder.validate_value(arg)
Expand Down Expand Up @@ -122,12 +111,7 @@ def decode_single(typ: TypeStr, data: Decodable) -> Any:
if not is_bytes(data):
raise TypeError("The `data` value must be of bytes type. Got {0}".format(type(data)))

if isinstance(typ, str):
type_str = typ
else:
type_str = collapse_type(*typ)

decoder = registry.get_decoder(type_str)
decoder = registry.get_decoder(typ)
stream = ContextFramesBytesIO(data)

return decoder(stream)
Expand Down
10 changes: 1 addition & 9 deletions eth_abi/packed.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
from eth_abi.registry import (
registry_packed,
)
from eth_abi.utils.parsing import (
collapse_type,
)

warnings.warn(
"Packed mode encoding is an experimental feature. Please report any "
Expand All @@ -36,12 +33,7 @@ def encode_single_packed(typ: TypeStr, arg: Any) -> bytes:
:returns: The non-standard packed mode binary representation of the python
value ``arg`` as a value of the ABI type ``typ``.
"""
if isinstance(typ, str):
type_str = typ
else:
type_str = collapse_type(*typ)

encoder = registry_packed.get_encoder(type_str)
encoder = registry_packed.get_encoder(typ)

return encoder(arg)

Expand Down
4 changes: 0 additions & 4 deletions eth_abi/utils/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,3 @@ def process_type(type_str):
arrlist = []

return abi_type.base, sub, arrlist


def collapse_type(base, sub, arrlist):
return base + sub + ''.join(map(repr, arrlist))
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'test': [
"pytest==3.3.2",
"pytest-pythonpath>=0.7.1",
"pytest-xdist",
"pytest-xdist==1.22.3",
"hypothesis>=3.6.1",
"tox>=2.9.1,<3",
"eth-hash[pycryptodome]",
Expand Down
3 changes: 0 additions & 3 deletions tests/common/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,6 @@ def words(*descriptions: str) -> bytes:
]

CORRECT_SINGLE_ENCODINGS = CORRECT_TUPLE_ENCODINGS + [
# encode_single/decode_single accept tuple of type components
(('uint', '256', []), 2 ** 256 - 1, words('f<f'), words('f<f')),

#####
# (type string, python value, abi encoding, packed encoding)
#####
Expand Down
18 changes: 0 additions & 18 deletions tests/test_utils/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
ParseError,
)
from eth_abi.utils.parsing import (
collapse_type,
process_type,
)

Expand Down Expand Up @@ -64,20 +63,3 @@ def test_process_validation_errors(typestr):
def test_process_parsing_errors(typestr):
with pytest.raises(ParseError):
process_type(typestr)


@pytest.mark.parametrize(
'original, expected',
[
('address', 'address'),
('uint[2][]', 'uint256[2][]'),
('uint256[2][]', 'uint256[2][]'),
('function', 'bytes24'),
('bool', 'bool'),
('bytes32', 'bytes32'),
('bytes', 'bytes'),
('string', 'string'),
],
)
def test_collapse_type(original, expected):
assert collapse_type(*process_type(original)) == expected

0 comments on commit 48c9342

Please sign in to comment.