Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Demonstrate calling contracts with tuple arrays #1615

Merged
merged 1 commit into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions python-packages/contract_demo/test/test_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,55 @@ def test_get_order_info():

assert isinstance(order_info.order_taker_asset_filled_amount, int)
assert order_info.order_taker_asset_filled_amount == 0


def test_get_orders_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"),
)

orders_info = exchange.call().getOrdersInfo([order])

for order_info in orders_info:
order_info = OrderInfo(*order_info)
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
2 changes: 1 addition & 1 deletion python-packages/order_utils/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ def run(self):
"0x-contract-addresses",
"0x-contract-artifacts",
"0x-json-schemas",
"0x-web3",
"eth-abi",
"eth_utils",
"hypothesis>=3.31.2", # HACK! this is web3's dependency!
# above works around https://github.com/ethereum/web3.py/issues/1179
"mypy_extensions",
"web3",
],
extras_require={
"dev": [
Expand Down