diff options
Diffstat (limited to 'python-packages/contract_demo/test')
-rw-r--r-- | python-packages/contract_demo/test/__init__.py | 1 | ||||
-rw-r--r-- | python-packages/contract_demo/test/conf.py | 54 | ||||
-rw-r--r-- | python-packages/contract_demo/test/doc_static/.gitkeep | 0 | ||||
-rw-r--r-- | python-packages/contract_demo/test/index.rst | 18 | ||||
-rw-r--r-- | python-packages/contract_demo/test/test_exchange.py | 65 |
5 files changed, 138 insertions, 0 deletions
diff --git a/python-packages/contract_demo/test/__init__.py b/python-packages/contract_demo/test/__init__.py new file mode 100644 index 000000000..600f143bf --- /dev/null +++ b/python-packages/contract_demo/test/__init__.py @@ -0,0 +1 @@ +"""Demonstrations of calling 0x smart contracts.""" diff --git a/python-packages/contract_demo/test/conf.py b/python-packages/contract_demo/test/conf.py new file mode 100644 index 000000000..45ed4b2a5 --- /dev/null +++ b/python-packages/contract_demo/test/conf.py @@ -0,0 +1,54 @@ +"""Configuration file for the Sphinx documentation builder.""" + +# Reference: http://www.sphinx-doc.org/en/master/config + +from typing import List +import pkg_resources + + +# pylint: disable=invalid-name +# because these variables are not named in upper case, as globals should be. + +project = "0x-contract-demo" +# pylint: disable=redefined-builtin +copyright = "2018, ZeroEx, Intl." +author = "F. Eugene Aumson" +version = pkg_resources.get_distribution("0x-contract-demo").version +release = "" # The full version, including alpha/beta/rc tags + +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.doctest", + "sphinx.ext.intersphinx", + "sphinx.ext.coverage", + "sphinx.ext.viewcode", +] + +templates_path = ["doc_templates"] + +source_suffix = ".rst" +# eg: source_suffix = [".rst", ".md"] + +master_doc = "index" # The master toctree document. + +language = None + +exclude_patterns: List[str] = [] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = None + +html_theme = "alabaster" + +html_static_path = ["doc_static"] +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". + +# Output file base name for HTML help builder. +htmlhelp_basename = "contract_demopydoc" + +# -- Extension configuration: + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = {"https://docs.python.org/": None} diff --git a/python-packages/contract_demo/test/doc_static/.gitkeep b/python-packages/contract_demo/test/doc_static/.gitkeep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/python-packages/contract_demo/test/doc_static/.gitkeep diff --git a/python-packages/contract_demo/test/index.rst b/python-packages/contract_demo/test/index.rst new file mode 100644 index 000000000..c546eccfa --- /dev/null +++ b/python-packages/contract_demo/test/index.rst @@ -0,0 +1,18 @@ +.. source for the sphinx-generated build/docs/web/index.html + +Python demo of 0x Smart Contracts +================================= + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + +.. automodule:: test.test_exchange + :members: + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/python-packages/contract_demo/test/test_exchange.py b/python-packages/contract_demo/test/test_exchange.py new file mode 100644 index 000000000..07492a403 --- /dev/null +++ b/python-packages/contract_demo/test/test_exchange.py @@ -0,0 +1,65 @@ +"""Test calling methods on the Exchange contract.""" + +from eth_utils import to_checksum_address +from web3 import Web3 +from web3.utils import datatypes + +from zero_ex.contract_addresses import NETWORK_TO_ADDRESSES, NetworkId +import zero_ex.contract_artifacts +from zero_ex.json_schemas import assert_valid +from zero_ex.order_utils import ( + Order, + OrderInfo, + order_to_jsdict, + generate_order_hash_hex, +) + + +def test_get_order_info(): + """Demonstrate Exchange.getOrderInfo().""" + order: Order = { + "makerAddress": "0x0000000000000000000000000000000000000000", + "takerAddress": "0x0000000000000000000000000000000000000000", + "feeRecipientAddress": "0x0000000000000000000000000000000000000000", + "senderAddress": "0x0000000000000000000000000000000000000000", + "makerAssetAmount": 1000000000000000000, + "takerAssetAmount": 1000000000000000000, + "makerFee": 0, + "takerFee": 0, + "expirationTimeSeconds": 12345, + "salt": 12345, + "makerAssetData": (b"\x00") * 20, + "takerAssetData": (b"\x00") * 20, + } + + web3_instance = Web3(Web3.HTTPProvider("http://127.0.0.1:8545")) + + # false positive from pylint: disable=no-member + contract_address = NETWORK_TO_ADDRESSES[ + NetworkId(int(web3_instance.net.version)) + ].exchange + + assert_valid( + order_to_jsdict(order, exchange_address=contract_address), + "/orderSchema", + ) + + # false positive from pylint: disable=no-member + exchange: datatypes.Contract = web3_instance.eth.contract( + address=to_checksum_address(contract_address), + abi=zero_ex.contract_artifacts.abi_by_name("Exchange"), + ) + + order_info = OrderInfo(*exchange.call().getOrderInfo(order)) + + assert isinstance(order_info.order_status, int) + assert order_info.order_status == 4 + + assert isinstance(order_info.order_hash, bytes) + assert order_info.order_hash.hex() == generate_order_hash_hex( + order, + exchange_address=NETWORK_TO_ADDRESSES[NetworkId.GANACHE].exchange, + ) + + assert isinstance(order_info.order_taker_asset_filled_amount, int) + assert order_info.order_taker_asset_filled_amount == 0 |