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

Commit

Permalink
Pre-release version bumps; test fixes for latest mesh/ganache versions (
Browse files Browse the repository at this point in the history
#2363)

* Use pre-release ver's for tests against deployment

* Pre-release version number bumps

* pin sra_client dev deps to prereleases

for testing against deployed package

* middlewares: incl doctest in tests of deployment

* Unpin mesh, use new snapshot, & pay protocol fees

* .gitignore gen'd wrappers for new contracts

* test build_tx() & support for empty TxParams.from_

* fix doc: fill TAKERAssetAmount, not maker...
  • Loading branch information
feuGeneA authored Nov 26, 2019
1 parent 4b5f2c3 commit 42c4fe5
Show file tree
Hide file tree
Showing 22 changed files with 219 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ jobs:
- image: nikolaik/python-nodejs:python3.7-nodejs8
- image: 0xorg/ganache-cli:4.4.0-beta.1
environment:
VERSION: 4.4.0-beta.1
VERSION: latest
SNAPSHOT_NAME: 0x_ganache_snapshot-v3-beta
- image: 0xorg/mesh:6.0.0-beta-0xv3
- image: 0xorg/mesh:0xV3
environment:
ETHEREUM_RPC_URL: 'http://localhost:8545'
ETHEREUM_NETWORK_ID: '50'
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ python-packages/contract_wrappers/src/zero_ex/contract_wrappers/dummy_erc721_tok
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/dutch_auction/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/erc1155_mintable/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/erc1155_proxy/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/erc20_bridge_proxy/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/erc20_proxy/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/erc721_proxy/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/erc721_token/__init__.py
Expand All @@ -185,6 +186,7 @@ python-packages/contract_wrappers/src/zero_ex/contract_wrappers/staking_proxy/__
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/static_call_proxy/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/weth9/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/zrx_token/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/zrx_vault/__init__.py

# solc-bin in sol-compiler
packages/sol-compiler/solc_bin/
Expand Down
2 changes: 1 addition & 1 deletion python-packages/contract_addresses/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def run_tests(self):

setup(
name="0x-contract-addresses",
version="2.2.0",
version="3.0.0.dev3",
description="Addresses at which the 0x smart contracts have been deployed",
long_description=README_MD,
long_description_content_type="text/markdown",
Expand Down
2 changes: 1 addition & 1 deletion python-packages/contract_addresses/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ commands =
[testenv:run_tests_against_deployment]
setenv = PY_IGNORE_IMPORTMISMATCH = 1
commands=
pip install 0x-contract-addresses[dev]
pip install --pre 0x-contract-addresses[dev]
pytest --doctest-modules src
2 changes: 1 addition & 1 deletion python-packages/contract_artifacts/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def run_tests(self):

setup(
name="0x-contract-artifacts",
version="3.0.0",
version="3.0.0.dev2",
description="0x smart contract compilation artifacts",
long_description=README_MD,
long_description_content_type="text/markdown",
Expand Down
2 changes: 1 addition & 1 deletion python-packages/contract_artifacts/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ commands =
[testenv:run_tests_against_deployment]
setenv = PY_IGNORE_IMPORTMISMATCH = 1
commands=
pip install 0x-contract-artifacts[dev]
pip install --pre 0x-contract-artifacts[dev]
pytest --doctest-modules src
10 changes: 5 additions & 5 deletions python-packages/contract_wrappers/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def run(self):

setup(
name="0x-contract-wrappers",
version="2.0.0",
version="2.0.0.dev10",
description="Python wrappers for 0x smart contracts",
long_description=README_MD,
long_description_content_type="text/markdown",
Expand All @@ -216,10 +216,10 @@ def run(self):
"ganache": GanacheCommand,
},
install_requires=[
"0x-contract-addresses",
"0x-contract-artifacts",
"0x-json-schemas",
"0x-order-utils",
"0x-contract-addresses==3.0.0.dev3",
"0x-contract-artifacts==3.0.0.dev2",
"0x-json-schemas==2.1.0.dev2",
"0x-order-utils==4.0.0.dev8",
"web3",
"attrs",
"eth_utils",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@
case WETH) that the taker wants to fill. This example fills the order
completely, but partial fills are possible too.
Note that sending value in the fill transaction is a way to pay the protocol
fee. The value to send is a function of the gas price, so we'll need some help
in that determination:
>>> from web3.gas_strategies.rpc import rpc_gas_price_strategy
>>> web3 = Web3(ganache)
>>> web3.eth.setGasPriceStrategy(rpc_gas_price_strategy)
One may wish to first call the method in a read-only way, to ensure that it
will not revert, and to validate that the return data is as expected:
Expand All @@ -186,11 +194,13 @@
... order=order,
... taker_asset_fill_amount=order["takerAssetAmount"],
... signature=maker_signature,
... tx_params=TxParams(from_=taker_address)
... tx_params=TxParams(
... from_=taker_address, value=web3.eth.generateGasPrice() * 150000
... ),
... ))
{'makerAssetFilledAmount': 100000000000000000,
'makerFeePaid': 0,
'protocolFeePaid': 0,
'protocolFeePaid': ...,
'takerAssetFilledAmount': 100000000000000000,
'takerFeePaid': 0}
Expand All @@ -200,7 +210,9 @@
... order=order,
... taker_asset_fill_amount=order["takerAssetAmount"],
... signature=maker_signature,
... tx_params=TxParams(from_=taker_address)
... tx_params=TxParams(
... from_=taker_address, value=web3.eth.generateGasPrice() * 150000
... )
... )
Once the transaction is mined, we can get the details of our exchange through
Expand Down Expand Up @@ -333,7 +345,11 @@
... orders=[order_1, order_2],
... taker_asset_fill_amounts=[1, 2],
... signatures=[signature_1, signature_2],
... tx_params=TxParams(from_=taker_address))
... tx_params=TxParams(
... from_=taker_address,
... value=2*web3.eth.generateGasPrice()*150000
... )
... )
HexBytes('0x...')
Estimating gas consumption
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def rpc_gas_price_strategy():
...
119 changes: 115 additions & 4 deletions python-packages/contract_wrappers/test/test_exchange_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import pytest
from eth_utils import remove_0x_prefix
from web3 import Web3
from web3.gas_strategies.rpc import rpc_gas_price_strategy

from zero_ex.contract_addresses import chain_to_addresses, ChainId
from zero_ex.contract_wrappers import TxParams
Expand Down Expand Up @@ -85,30 +87,128 @@ def test_exchange_wrapper__fill_order(
)
order_signature = sign_hash(ganache_provider, maker, order_hash)

web3 = Web3(ganache_provider)
web3.eth.setGasPriceStrategy( # pylint: disable=no-member
rpc_gas_price_strategy
)

fill_results = exchange_wrapper.fill_order.call(
order=order,
taker_asset_fill_amount=order["takerAssetAmount"],
signature=order_signature,
tx_params=TxParams(from_=taker),
tx_params=TxParams(
from_=taker,
value=web3.eth.generateGasPrice() # pylint: disable=no-member
* 150000,
),
)
assert fill_results["makerAssetFilledAmount"] == 1
assert fill_results["takerAssetFilledAmount"] == 1
assert fill_results["makerFeePaid"] == 0
assert fill_results["takerFeePaid"] == 0
assert fill_results["protocolFeePaid"] == 0
assert (
fill_results["protocolFeePaid"]
== web3.eth.generateGasPrice() * 150000 # pylint: disable=no-member
)

tx_hash = exchange_wrapper.fill_order.send_transaction(
order=order,
taker_asset_fill_amount=order["takerAssetAmount"],
signature=order_signature,
tx_params=TxParams(from_=taker),
tx_params=TxParams(
from_=taker,
value=web3.eth.generateGasPrice() # pylint: disable=no-member
* 150000,
),
)
assert_valid(tx_hash.hex(), "/hexSchema")

fill_event = exchange_wrapper.get_fill_event(tx_hash)
assert_fill_log(fill_event[0].args, maker, taker, order, order_hash)


def test_exchange_wrapper__fill_order__build_then_send(
accounts,
exchange_wrapper, # pylint: disable=redefined-outer-name
ganache_provider,
weth_asset_data,
zrx_asset_data,
):
"""Test filling an order."""
taker = accounts[0]
maker = accounts[1]
exchange_address = exchange_wrapper.contract_address
order = create_test_order(maker, 1, weth_asset_data, 1, zrx_asset_data)
order_hash = generate_order_hash_hex(
order=order, exchange_address=exchange_address, chain_id=1337
)
order_signature = sign_hash(ganache_provider, maker, order_hash)

web3 = Web3(ganache_provider)
web3.eth.setGasPriceStrategy( # pylint: disable=no-member
rpc_gas_price_strategy
)

tx_hash = Web3(ganache_provider).eth.sendTransaction(
exchange_wrapper.fill_order.build_transaction(
order=order,
taker_asset_fill_amount=order["takerAssetAmount"],
signature=order_signature,
tx_params=TxParams(
from_=taker,
value=web3.eth.generateGasPrice() # pylint: disable=no-member
* 150000,
),
)
)

assert_valid(tx_hash.hex(), "/hexSchema")

fill_event = exchange_wrapper.get_fill_event(tx_hash)
assert_fill_log(fill_event[0].args, maker, taker, order, order_hash)


def test_exchange_wrapper__fill_order__without_from_tx_param(
accounts,
exchange_wrapper, # pylint: disable=redefined-outer-name
ganache_provider,
weth_asset_data,
zrx_asset_data,
):
"""Test filling an order."""
maker = accounts[1]
exchange_address = exchange_wrapper.contract_address
order = create_test_order(maker, 1, weth_asset_data, 1, zrx_asset_data)
order_hash = generate_order_hash_hex(
order=order, exchange_address=exchange_address, chain_id=1337
)
order_signature = sign_hash(ganache_provider, maker, order_hash)

web3 = Web3(ganache_provider)
web3.eth.setGasPriceStrategy( # pylint: disable=no-member
rpc_gas_price_strategy
)

exchange_wrapper._web3_eth.defaultAccount = ( # pylint: disable=protected-access
None
)
exchange_wrapper._web3_eth.accounts.clear() # pylint: disable=protected-access

built_tx = exchange_wrapper.fill_order.build_transaction(
order=order,
taker_asset_fill_amount=order["takerAssetAmount"],
signature=order_signature,
tx_params=TxParams(
value=web3.eth.generateGasPrice() # pylint: disable=no-member
* 150000,
),
)
assert (
built_tx["data"][:824]
== "0x9b44d5560000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000003a00000000000000000000000006ecbe1db9ef729cbe972c83fb886247691fb6beb000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005af3107a40000000000000000000000000000000000000000000000000"
)


# pylint: disable=too-many-locals
def test_exchange_wrapper__batch_fill_orders(
accounts,
Expand Down Expand Up @@ -136,11 +236,22 @@ def test_exchange_wrapper__batch_fill_orders(
for order_hash in order_hashes
]
taker_amounts = [order["takerAssetAmount"] for order in orders]

web3 = Web3(ganache_provider)
web3.eth.setGasPriceStrategy( # pylint: disable=no-member
rpc_gas_price_strategy
)

tx_hash = exchange_wrapper.batch_fill_orders.send_transaction(
orders=orders,
taker_asset_fill_amounts=taker_amounts,
signatures=order_signatures,
tx_params=TxParams(from_=taker),
tx_params=TxParams(
from_=taker,
value=2
* web3.eth.generateGasPrice() # pylint: disable=no-member
* 150000,
),
)
assert_valid(tx_hash.hex(), "/hexSchema")

Expand Down
2 changes: 1 addition & 1 deletion python-packages/contract_wrappers/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ commands =
[testenv:run_tests_against_deployment]
setenv = PY_IGNORE_IMPORTMISMATCH = 1
commands =
pip install 0x-contract-wrappers[dev]
pip install --pre 0x-contract-wrappers[dev]
pytest --doctest-modules src test
4 changes: 2 additions & 2 deletions python-packages/json_schemas/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def run(self):

setup(
name="0x-json-schemas",
version="1.1.1",
version="2.1.0.dev2",
description="JSON schemas for 0x applications",
long_description=README_MD,
long_description_content_type="text/markdown",
Expand All @@ -165,7 +165,7 @@ def run(self):
install_requires=["jsonschema", "mypy_extensions", "stringcase"],
extras_require={
"dev": [
"0x-contract-addresses",
"0x-contract-addresses==3.0.0.dev3",
"bandit",
"black",
"coverage",
Expand Down
2 changes: 1 addition & 1 deletion python-packages/json_schemas/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ commands =
[testenv:run_tests_against_deployment]
setenv = PY_IGNORE_IMPORTMISMATCH = 1
commands =
pip install 0x-json-schemas[dev]
pip install --pre 0x-json-schemas[dev]
pytest --doctest-modules src test
2 changes: 1 addition & 1 deletion python-packages/middlewares/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def run(self):

setup(
name="0x-middlewares",
version="1.0.0",
version="1.0.0.dev0",
description="Web3 middlewares for 0x applications",
long_description=README_MD,
long_description_content_type="text/markdown",
Expand Down
5 changes: 3 additions & 2 deletions python-packages/middlewares/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ commands =
pytest test

[testenv:run_tests_against_deployment]
setenv = PY_IGNORE_IMPORTMISMATCH = 1
commands =
pip install 0x-middlewares
pytest test
pip install --pre 0x-middlewares[dev]
pytest --doctest-modules test
8 changes: 4 additions & 4 deletions python-packages/order_utils/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def run(self):

setup(
name="0x-order-utils",
version="4.0.0",
version="4.0.0.dev8",
description="Order utilities for 0x applications",
long_description=README_MD,
long_description_content_type="text/markdown",
Expand All @@ -176,9 +176,9 @@ def run(self):
"ganache": GanacheCommand,
},
install_requires=[
"0x-contract-addresses",
"0x-contract-artifacts",
"0x-json-schemas",
"0x-contract-addresses==3.0.0.dev3",
"0x-contract-artifacts==3.0.0.dev2",
"0x-json-schemas==2.1.0.dev2",
"deprecated",
"web3",
"eth-abi",
Expand Down
2 changes: 1 addition & 1 deletion python-packages/order_utils/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ commands =
[testenv:run_tests_against_deployment]
setenv = PY_IGNORE_IMPORTMISMATCH = 1
commands =
pip install 0x-order-utils[dev]
pip install --pre 0x-order-utils[dev]
pytest --doctest-modules src test
Loading

0 comments on commit 42c4fe5

Please sign in to comment.