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:
F. Eugene Aumson
2018-10-23 12:08:16 -04:00
committed by GitHub
parent 1ba207f1fe
commit 1f0c7f8fbe
23 changed files with 410 additions and 37 deletions

View 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)
)