feat(order_utils.py): ERC20 asset data encoding and decoding
In addition to the ERC20 codec, also: Stopped ignoring type errors on 3rd party imports, by including interface stubs for them; Removed the unimplemented signature-utils module, which was just a stand-in when the python project support was first put in place. https://github.com/0xProject/0x-monorepo/pull/1144
This commit is contained in:
53
python-packages/order_utils/test/test_abi_utils.py
Normal file
53
python-packages/order_utils/test/test_abi_utils.py
Normal file
@@ -0,0 +1,53 @@
|
||||
"""Tests of 0x.abi_utils."""
|
||||
|
||||
import pytest
|
||||
|
||||
from zero_ex.dev_utils.abi_utils import (
|
||||
elementary_name,
|
||||
event_id,
|
||||
method_id,
|
||||
parse_signature,
|
||||
simple_encode,
|
||||
)
|
||||
|
||||
|
||||
def test_parse_signature_type_error():
|
||||
"""Test that passing in wrong types raises TypeError."""
|
||||
with pytest.raises(TypeError):
|
||||
parse_signature(123)
|
||||
|
||||
|
||||
def test_parse_signature_bad_input():
|
||||
"""Test that passing a non-signature string raises a ValueError."""
|
||||
with pytest.raises(ValueError):
|
||||
parse_signature("a string that's not even close to a signature")
|
||||
|
||||
|
||||
def test_elementary_name_type_error():
|
||||
"""Test that passing in wrong types raises TypeError."""
|
||||
with pytest.raises(TypeError):
|
||||
elementary_name(123)
|
||||
|
||||
|
||||
def test_event_id_type_error():
|
||||
"""Test that passing in wrong types raises TypeError."""
|
||||
with pytest.raises(TypeError):
|
||||
event_id(123, [])
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
event_id("valid string", 123)
|
||||
|
||||
|
||||
def test_method_id_type_error():
|
||||
"""Test that passing in wrong types raises TypeError."""
|
||||
with pytest.raises(TypeError):
|
||||
method_id(123, [])
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
method_id("ERC20Token", 123)
|
||||
|
||||
|
||||
def test_simple_encode_type_error():
|
||||
"""Test that passing in wrong types raises TypeError."""
|
||||
with pytest.raises(TypeError):
|
||||
simple_encode(123)
|
35
python-packages/order_utils/test/test_asset_data_utils.py
Normal file
35
python-packages/order_utils/test/test_asset_data_utils.py
Normal file
@@ -0,0 +1,35 @@
|
||||
"""Tests of 0x.order_utils.asset_data_utils."""
|
||||
|
||||
import pytest
|
||||
|
||||
from zero_ex.order_utils.asset_data_utils import (
|
||||
encode_erc20_asset_data,
|
||||
decode_erc20_asset_data,
|
||||
ERC20_ASSET_DATA_BYTE_LENGTH,
|
||||
)
|
||||
|
||||
|
||||
def test_encode_erc20_asset_data_type_error():
|
||||
"""Test that passing in a non-string raises a TypeError."""
|
||||
with pytest.raises(TypeError):
|
||||
encode_erc20_asset_data(123)
|
||||
|
||||
|
||||
def test_decode_erc20_asset_data_type_error():
|
||||
"""Test that passing in a non-string raises a TypeError."""
|
||||
with pytest.raises(TypeError):
|
||||
decode_erc20_asset_data(123)
|
||||
|
||||
|
||||
def test_decode_erc20_asset_data_too_short():
|
||||
"""Test that passing an insufficiently long string raises a ValueError."""
|
||||
with pytest.raises(ValueError):
|
||||
decode_erc20_asset_data(" " * (ERC20_ASSET_DATA_BYTE_LENGTH - 1))
|
||||
|
||||
|
||||
def test_decode_erc20_asset_data_invalid_proxy_id():
|
||||
"""Test that passing data with an invalid proxy ID raises a ValueError."""
|
||||
with pytest.raises(ValueError):
|
||||
decode_erc20_asset_data(
|
||||
"0xffffffff" + (" " * ERC20_ASSET_DATA_BYTE_LENGTH)
|
||||
)
|
@@ -1,10 +1,24 @@
|
||||
"""Exercise doctests for order_utils module."""
|
||||
|
||||
from doctest import testmod
|
||||
from zero_ex.order_utils import signature_utils
|
||||
|
||||
from zero_ex.dev_utils import abi_utils, type_assertions
|
||||
from zero_ex.order_utils import asset_data_utils
|
||||
|
||||
|
||||
def test_doctest():
|
||||
"""Invoke doctest on the module."""
|
||||
(failure_count, _) = testmod(signature_utils)
|
||||
def test_doctest_asset_data_utils():
|
||||
"""Invoke doctest on the asset_data_utils module."""
|
||||
(failure_count, _) = testmod(asset_data_utils)
|
||||
assert failure_count == 0
|
||||
|
||||
|
||||
def test_doctest_abi_utils():
|
||||
"""Invoke doctest on the abi_utils module."""
|
||||
(failure_count, _) = testmod(abi_utils)
|
||||
assert failure_count == 0
|
||||
|
||||
|
||||
def test_doctest_type_assertions():
|
||||
"""Invoke doctest on the type_assertions module."""
|
||||
(failure_count, _) = testmod(type_assertions)
|
||||
assert failure_count == 0
|
||||
|
@@ -1,8 +0,0 @@
|
||||
"""Tests of 0x.order_utils.signature_utils.*."""
|
||||
|
||||
from zero_ex.order_utils.signature_utils import ec_sign_order_hash
|
||||
|
||||
|
||||
def test_ec_sign_order_hash():
|
||||
"""Test the signing of order hashes."""
|
||||
assert ec_sign_order_hash() == "stub return value"
|
Reference in New Issue
Block a user