aboutsummaryrefslogtreecommitdiffstats
path: root/python-packages/contract_demo/test/test_exchange.py
blob: 07492a4030fa97b523e7e9fd98bb1229a2e9890f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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