aboutsummaryrefslogtreecommitdiffstats
path: root/python-packages/order_utils/test
diff options
context:
space:
mode:
Diffstat (limited to 'python-packages/order_utils/test')
-rw-r--r--python-packages/order_utils/test/__init__.py1
-rw-r--r--python-packages/order_utils/test/test_abi_utils.py53
-rw-r--r--python-packages/order_utils/test/test_asset_data_utils.py72
-rw-r--r--python-packages/order_utils/test/test_doctest.py17
-rw-r--r--python-packages/order_utils/test/test_generate_order_hash_hex.py12
-rw-r--r--python-packages/order_utils/test/test_signature_utils.py128
6 files changed, 283 insertions, 0 deletions
diff --git a/python-packages/order_utils/test/__init__.py b/python-packages/order_utils/test/__init__.py
new file mode 100644
index 000000000..ec5b114aa
--- /dev/null
+++ b/python-packages/order_utils/test/__init__.py
@@ -0,0 +1 @@
+"""Tests of zero_x.order_utils."""
diff --git a/python-packages/order_utils/test/test_abi_utils.py b/python-packages/order_utils/test/test_abi_utils.py
new file mode 100644
index 000000000..49a2a4f20
--- /dev/null
+++ b/python-packages/order_utils/test/test_abi_utils.py
@@ -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)
diff --git a/python-packages/order_utils/test/test_asset_data_utils.py b/python-packages/order_utils/test/test_asset_data_utils.py
new file mode 100644
index 000000000..079368714
--- /dev/null
+++ b/python-packages/order_utils/test/test_asset_data_utils.py
@@ -0,0 +1,72 @@
+"""Tests of 0x.order_utils.asset_data_utils."""
+
+import pytest
+
+from zero_ex.order_utils.asset_data_utils import (
+ decode_erc20_asset_data,
+ decode_erc721_asset_data,
+ encode_erc20_asset_data,
+ encode_erc721_asset_data,
+ ERC20_ASSET_DATA_BYTE_LENGTH,
+ ERC721_ASSET_DATA_MINIMUM_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)
+ )
+
+
+def test_encode_erc721_asset_data_type_error_on_token_address():
+ """Test that passing a non-string for token_address raises a TypeError."""
+ with pytest.raises(TypeError):
+ encode_erc721_asset_data(123, 123)
+
+
+def test_encode_erc721_asset_data_type_error_on_token_id():
+ """Test that passing a non-int for token_id raises a TypeError."""
+ with pytest.raises(TypeError):
+ encode_erc721_asset_data("asdf", "asdf")
+
+
+def test_decode_erc721_asset_data_type_error():
+ """Test that passing a non-string for asset_data raises a TypeError."""
+ with pytest.raises(TypeError):
+ decode_erc721_asset_data(123)
+
+
+def test_decode_erc721_asset_data_with_asset_data_too_short():
+ """Test that passing in too short of a string raises a ValueError."""
+ with pytest.raises(ValueError):
+ decode_erc721_asset_data(
+ " " * (ERC721_ASSET_DATA_MINIMUM_BYTE_LENGTH - 1)
+ )
+
+
+def test_decode_erc721_asset_data_invalid_proxy_id():
+ """Test that passing in too short of a string raises a ValueError."""
+ with pytest.raises(ValueError):
+ decode_erc721_asset_data(
+ "0xffffffff" + " " * (ERC721_ASSET_DATA_MINIMUM_BYTE_LENGTH - 1)
+ )
diff --git a/python-packages/order_utils/test/test_doctest.py b/python-packages/order_utils/test/test_doctest.py
new file mode 100644
index 000000000..f692b3b6c
--- /dev/null
+++ b/python-packages/order_utils/test/test_doctest.py
@@ -0,0 +1,17 @@
+"""Exercise doctests for all of our modules."""
+
+from doctest import testmod
+import pkgutil
+
+import zero_ex
+
+
+def test_all_doctests():
+ """Gather zero_ex.* modules and doctest them."""
+ for (importer, modname, _) in pkgutil.walk_packages(
+ path=zero_ex.__path__, prefix="zero_ex."
+ ):
+ module = importer.find_module(modname).load_module(modname)
+ print(module)
+ (failure_count, _) = testmod(module)
+ assert failure_count == 0
diff --git a/python-packages/order_utils/test/test_generate_order_hash_hex.py b/python-packages/order_utils/test/test_generate_order_hash_hex.py
new file mode 100644
index 000000000..6869a40ed
--- /dev/null
+++ b/python-packages/order_utils/test/test_generate_order_hash_hex.py
@@ -0,0 +1,12 @@
+"""Test zero_ex.order_utils.get_order_hash_hex()."""
+
+from zero_ex.order_utils import generate_order_hash_hex, make_empty_order
+
+
+def test_get_order_hash_hex__empty_order():
+ """Test the hashing of an uninitialized order."""
+ expected_hash_hex = (
+ "faa49b35faeb9197e9c3ba7a52075e6dad19739549f153b77dfcf59408a4b422"
+ )
+ actual_hash_hex = generate_order_hash_hex(make_empty_order())
+ assert actual_hash_hex == expected_hash_hex
diff --git a/python-packages/order_utils/test/test_signature_utils.py b/python-packages/order_utils/test/test_signature_utils.py
new file mode 100644
index 000000000..c5acc9d62
--- /dev/null
+++ b/python-packages/order_utils/test/test_signature_utils.py
@@ -0,0 +1,128 @@
+"""Tests of zero_ex.order_utils.signature_utils."""
+
+import pytest
+from web3 import Web3
+
+from zero_ex.order_utils import is_valid_signature
+
+
+def test_is_valid_signature__provider_wrong_type():
+ """Test that giving a non-HTTPProvider raises a TypeError."""
+ with pytest.raises(TypeError):
+ is_valid_signature(
+ 123,
+ "0x6927e990021d23b1eb7b8789f6a6feaf98fe104bb0cf8259421b79f9a34222b"
+ + "0",
+ "0x1B61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351b"
+ + "c3340349190569279751135161d22529dc25add4f6069af05be04cacbda2ace"
+ + "225403",
+ "0x5409ed021d9299bf6814279a6a1411a7e866a631",
+ )
+
+
+def test_is_valid_signature__data_not_string():
+ """Test that giving non-string `data` raises a TypeError."""
+ with pytest.raises(TypeError):
+ is_valid_signature(
+ Web3.HTTPProvider("http://127.0.0.1:8545"),
+ 123,
+ "0x1B61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351b"
+ + "c3340349190569279751135161d22529dc25add4f6069af05be04cacbda2ace"
+ + "225403",
+ "0x5409ed021d9299bf6814279a6a1411a7e866a631",
+ )
+
+
+def test_is_valid_signature__data_not_hex_string():
+ """Test that giving non-hex-string `data` raises a ValueError."""
+ with pytest.raises(ValueError):
+ is_valid_signature(
+ Web3.HTTPProvider("http://127.0.0.1:8545"),
+ "jjj",
+ "0x1B61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351b"
+ + "c3340349190569279751135161d22529dc25add4f6069af05be04cacbda2ace"
+ + "225403",
+ "0x5409ed021d9299bf6814279a6a1411a7e866a631",
+ )
+
+
+def test_is_valid_signature__signature_not_string():
+ """Test that passng a non-string signature raises a TypeError."""
+ with pytest.raises(TypeError):
+ is_valid_signature(
+ Web3.HTTPProvider("http://127.0.0.1:8545"),
+ "0x6927e990021d23b1eb7b8789f6a6feaf98fe104bb0cf8259421b79f9a34222b"
+ + "0",
+ 123,
+ "0x5409ed021d9299bf6814279a6a1411a7e866a631",
+ )
+
+
+def test_is_valid_signature__signature_not_hex_string():
+ """Test that passing a non-hex-string signature raises a ValueError."""
+ with pytest.raises(ValueError):
+ is_valid_signature(
+ Web3.HTTPProvider("http://127.0.0.1:8545"),
+ "0x6927e990021d23b1eb7b8789f6a6feaf98fe104bb0cf8259421b79f9a34222b"
+ + "0",
+ "jjj",
+ "0x5409ed021d9299bf6814279a6a1411a7e866a631",
+ )
+
+
+def test_is_valid_signature__signer_address_not_string():
+ """Test that giving a non-address `signer_address` raises a ValueError."""
+ with pytest.raises(TypeError):
+ is_valid_signature(
+ Web3.HTTPProvider("http://127.0.0.1:8545"),
+ "0x6927e990021d23b1eb7b8789f6a6feaf98fe104bb0cf8259421b79f9a34222b"
+ + "0",
+ "0x1B61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351b"
+ + "c3340349190569279751135161d22529dc25add4f6069af05be04cacbda2ace"
+ + "225403",
+ 123,
+ )
+
+
+def test_is_valid_signature__signer_address_not_hex_string():
+ """Test that giving a non-hex-str `signer_address` raises a ValueError."""
+ with pytest.raises(ValueError):
+ is_valid_signature(
+ Web3.HTTPProvider("http://127.0.0.1:8545"),
+ "0x6927e990021d23b1eb7b8789f6a6feaf98fe104bb0cf8259421b79f9a34222b"
+ + "0",
+ "0x1B61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351b"
+ + "c3340349190569279751135161d22529dc25add4f6069af05be04cacbda2ace"
+ + "225403",
+ "jjj",
+ )
+
+
+def test_is_valid_signature__signer_address_not_valid_address():
+ """Test that giving a non-address for `signer_address` raises an error."""
+ with pytest.raises(ValueError):
+ is_valid_signature(
+ Web3.HTTPProvider("http://127.0.0.1:8545"),
+ "0x6927e990021d23b1eb7b8789f6a6feaf98fe104bb0cf8259421b79f9a34222b"
+ + "0",
+ "0x1B61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351b"
+ + "c3340349190569279751135161d22529dc25add4f6069af05be04cacbda2ace"
+ + "225403",
+ "0xff",
+ )
+
+
+def test_is_valid_signature__unsupported_sig_types():
+ """Test that passing in a sig w/invalid type raises error.
+
+ To induce this error, the last byte of the signature is tweaked from 03 to
+ ff."""
+ (is_valid, reason) = is_valid_signature(
+ Web3.HTTPProvider("http://127.0.0.1:8545"),
+ "0x6927e990021d23b1eb7b8789f6a6feaf98fe104bb0cf8259421b79f9a34222b0",
+ "0x1B61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc334"
+ + "0349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254ff",
+ "0x5409ed021d9299bf6814279a6a1411a7e866a631",
+ )
+ assert is_valid is False
+ assert reason == "SIGNATURE_UNSUPPORTED"