diff options
author | August Skare <post@augustskare.no> | 2018-11-16 18:28:24 +0800 |
---|---|---|
committer | August Skare <post@augustskare.no> | 2018-11-16 18:28:24 +0800 |
commit | c08108144825c33d8db26053c1d2d41460b09359 (patch) | |
tree | 6f21ce1e6834e0130b0f6063a097014cc1cc671f /python-packages/order_utils/src/zero_ex/dev_utils | |
parent | 54bd7df900316504e4403bc94cffd92930a6c763 (diff) | |
parent | cabb7432b9a6d4a5bb8da6fc7fe4522d24e4ece5 (diff) | |
download | dexon-sol-tools-c08108144825c33d8db26053c1d2d41460b09359.tar dexon-sol-tools-c08108144825c33d8db26053c1d2d41460b09359.tar.gz dexon-sol-tools-c08108144825c33d8db26053c1d2d41460b09359.tar.bz2 dexon-sol-tools-c08108144825c33d8db26053c1d2d41460b09359.tar.lz dexon-sol-tools-c08108144825c33d8db26053c1d2d41460b09359.tar.xz dexon-sol-tools-c08108144825c33d8db26053c1d2d41460b09359.tar.zst dexon-sol-tools-c08108144825c33d8db26053c1d2d41460b09359.zip |
Merge branch 'development' into dev-tools-pages
Diffstat (limited to 'python-packages/order_utils/src/zero_ex/dev_utils')
-rw-r--r-- | python-packages/order_utils/src/zero_ex/dev_utils/abi_utils.py | 3 | ||||
-rw-r--r-- | python-packages/order_utils/src/zero_ex/dev_utils/type_assertions.py | 31 |
2 files changed, 32 insertions, 2 deletions
diff --git a/python-packages/order_utils/src/zero_ex/dev_utils/abi_utils.py b/python-packages/order_utils/src/zero_ex/dev_utils/abi_utils.py index 71b6128ca..3fec775b0 100644 --- a/python-packages/order_utils/src/zero_ex/dev_utils/abi_utils.py +++ b/python-packages/order_utils/src/zero_ex/dev_utils/abi_utils.py @@ -10,8 +10,8 @@ from typing import Any, List from mypy_extensions import TypedDict -from eth_abi import encode_abi from web3 import Web3 +from eth_abi import encode_abi from .type_assertions import assert_is_string, assert_is_list @@ -84,7 +84,6 @@ def method_id(name: str, types: List[str]) -> str: def simple_encode(method: str, *args: Any) -> bytes: - # docstring considered all one line by pylint: disable=line-too-long r"""Encode a method ABI. >>> simple_encode("ERC20Token(address)", "0x1dc4c1cefef38a777b15aa20260a54e584b16c48") diff --git a/python-packages/order_utils/src/zero_ex/dev_utils/type_assertions.py b/python-packages/order_utils/src/zero_ex/dev_utils/type_assertions.py index 08c1b0ea5..1dcfb39a9 100644 --- a/python-packages/order_utils/src/zero_ex/dev_utils/type_assertions.py +++ b/python-packages/order_utils/src/zero_ex/dev_utils/type_assertions.py @@ -2,6 +2,9 @@ from typing import Any +from eth_utils import is_address +from web3.providers.base import BaseProvider + def assert_is_string(value: Any, name: str) -> None: """If :param value: isn't of type str, raise a TypeError. @@ -56,3 +59,31 @@ def assert_is_hex_string(value: Any, name: str) -> None: """ assert_is_string(value, name) int(value, 16) # raises a ValueError if value isn't a base-16 str + + +def assert_is_address(value: Any, name: str) -> None: + """Assert that `value` is a valid Ethereum address. + + If `value` isn't a hex string, raise a TypeError. If it isn't a valid + Ethereum address, raise a ValueError. + """ + assert_is_hex_string(value, name) + if not is_address(value): + raise ValueError( + f"Expected variable '{name}' to be a valid Ethereum" + + " address, but it's not." + ) + + +def assert_is_provider(value: Any, name: str) -> None: + """Assert that `value` is a Web3 provider. + + If `value` isn't a Web3 provider, raise a TypeError. + """ + # TODO: make this provider check more flexible. + # https://app.asana.com/0/684263176955174/901300863045491/f + if not isinstance(value, BaseProvider): + raise TypeError( + f"Expected variable '{name}' to be an instance of a Web3 provider," + + " but it's not." + ) |