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

Commit

Permalink
Migrate from Web3.py 4.x to 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
feuGeneA committed Aug 7, 2019
1 parent 1d7a9fd commit 4295625
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 39 deletions.
4 changes: 1 addition & 3 deletions python-packages/contract_wrappers/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,9 @@ def run(self):
"0x-contract-artifacts",
"0x-json-schemas",
"0x-order-utils",
"0x-web3",
"web3",
"attrs",
"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",
],
extras_require={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
>>> from web3 import Web3
>>> accounts = Web3(ganache).eth.accounts
>>> maker_address = accounts[0].lower()
>>> taker_address = accounts[1].lower()
>>> maker_address = accounts[0]
>>> taker_address = accounts[1]
In the examples below, we'll use the optional `tx_params`:code: parameter to
the contract calls, in order to specify which account each transaction is to
Expand Down
4 changes: 2 additions & 2 deletions python-packages/contract_wrappers/stubs/web3/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from typing import Any, Callable, Dict, List, Optional, Union
from hexbytes import HexBytes
from eth_account.local import LocalAccount
from web3 import datastructures
from web3.utils import datatypes
from web3.contract import Contract
from web3.providers.base import BaseProvider


Expand Down Expand Up @@ -47,7 +47,7 @@ class Web3:
def getTransactionReceipt(tx_hash: Union[HexBytes, bytes]) -> Any: ...

@staticmethod
def contract(address: str, abi: Dict) -> datatypes.Contract: ...
def contract(address: str, abi: Dict) -> Contract: ...
...

@staticmethod
Expand Down
12 changes: 12 additions & 0 deletions python-packages/contract_wrappers/stubs/web3/contract.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
from typing import Any


class Contract:
def call(self): ...

functions: Any

events: Any
...


class ContractFunction:
def __call__(self, *args, **kwargs):
...
Expand Down
10 changes: 0 additions & 10 deletions python-packages/contract_wrappers/stubs/web3/utils/datatypes.pyi

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create_test_order(
):
"""Create a test order."""
order = Order(
makerAddress=maker_address.lower(),
makerAddress=maker_address,
takerAddress="0x0000000000000000000000000000000000000000",
feeRecipientAddress="0x0000000000000000000000000000000000000000",
senderAddress="0x0000000000000000000000000000000000000000",
Expand Down
4 changes: 1 addition & 3 deletions python-packages/middlewares/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,13 @@ def run(self):
"eth-account",
"eth-keys",
"hexbytes",
"hypothesis>=3.31.2", # HACK! this is web3's dependency!
# above works around https://github.com/ethereum/web3.py/issues/1179
"mypy_extensions",
],
extras_require={
"dev": [
"0x-contract-addresses",
"0x-order-utils",
"0x-web3",
"web3",
"bandit",
"black",
"coverage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from functools import singledispatch
from typing import Dict, List, Set, Tuple, Union
from eth_account import Account, messages
from eth_account.local import LocalAccount
from eth_account.signers.local import LocalAccount
from eth_keys.datatypes import PrivateKey
from hexbytes import HexBytes

Expand Down Expand Up @@ -71,7 +71,7 @@ def construct_local_message_signer(
>>> from web3 import Web3, HTTPProvider
>>> Web3(
... HTTPProvider("https://mainnet.infura.io/v3/API_KEY")
... ).middleware_stack.add(
... ).middleware_onion.add(
... construct_local_message_signer(private_key)
... )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_local_message_signer__sign_order():
)
ganache = HTTPProvider("http://127.0.0.1:8545")
web3_instance = Web3(ganache)
web3_instance.middleware_stack.add(
web3_instance.middleware_onion.add(
construct_local_message_signer(private_key)
)
order = {
Expand Down
6 changes: 2 additions & 4 deletions python-packages/order_utils/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,9 @@ def run(self):
"0x-contract-addresses",
"0x-contract-artifacts",
"0x-json-schemas",
"0x-web3",
"eth-abi<2.0.0",
"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",
],
extras_require={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from web3 import Web3
import web3.exceptions
from web3.providers.base import BaseProvider
from web3.utils import datatypes
from web3.contract import Contract

from zero_ex.contract_addresses import NETWORK_TO_ADDRESSES, NetworkId
import zero_ex.contract_artifacts
Expand Down Expand Up @@ -186,7 +186,7 @@ def is_valid_signature(
NetworkId(int(web3_instance.net.version))
].exchange
# false positive from pylint: disable=no-member
contract: datatypes.Contract = web3_instance.eth.contract(
contract: Contract = web3_instance.eth.contract(
address=to_checksum_address(contract_address),
abi=zero_ex.contract_artifacts.abi_by_name("Exchange"),
)
Expand Down Expand Up @@ -285,7 +285,7 @@ def sign_hash(
>>> provider = Web3.HTTPProvider("http://127.0.0.1:8545")
>>> sign_hash(
... provider,
... Web3(provider).personal.listAccounts[0],
... Web3(provider).geth.personal.listAccounts()[0],
... '0x34decbedc118904df65f379a175bb39ca18209d6ce41d5ed549d54e6e0a95004',
... )
'0x1b117902c86dfb95fe0d1badd983ee166ad259b27acb220174cbb4460d872871137feabdfe76e05924b484789f79af4ee7fa29ec006cedce1bbf369320d034e10b03'
Expand Down Expand Up @@ -355,7 +355,7 @@ def sign_hash_to_bytes(
>>> provider = Web3.HTTPProvider("http://127.0.0.1:8545")
>>> sign_hash_to_bytes(
... provider,
... Web3(provider).personal.listAccounts[0],
... Web3(provider).geth.personal.listAccounts()[0],
... '0x34decbedc118904df65f379a175bb39ca18209d6ce41d5ed549d54e6e0a95004',
... ).decode(encoding='utf_8')
'1b117902c86dfb95fe0d1badd983ee166ad259b27acb220174cbb4460d872871137feabdfe76e05924b484789f79af4ee7fa29ec006cedce1bbf369320d034e10b03'
Expand Down
15 changes: 12 additions & 3 deletions python-packages/order_utils/stubs/web3/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Dict, Optional, Union
from typing import Dict, List, Optional, Union

from web3.utils import datatypes
from web3.contract import Contract
from web3.providers.base import BaseProvider


Expand All @@ -23,6 +23,15 @@ class Web3:

class eth:
@staticmethod
def contract(address: str, abi: Dict) -> datatypes.Contract: ...
def contract(address: str, abi: Dict) -> Contract: ...
...

class geth:
class personal:
@staticmethod
def listAccounts() -> List[str]:
...
...
...

...
Empty file.
4 changes: 3 additions & 1 deletion python-packages/order_utils/test/test_signature_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ def test_sign_hash_to_bytes__golden_path():
provider = Web3.HTTPProvider("http://127.0.0.1:8545")
signature = sign_hash_to_bytes(
provider,
Web3(provider).personal.listAccounts[0], # pylint: disable=no-member
Web3( # pylint: disable=no-member
provider
).geth.personal.listAccounts()[0],
"0x34decbedc118904df65f379a175bb39ca18209d6ce41d5ed549d54e6e0a95004",
)
assert (
Expand Down
2 changes: 1 addition & 1 deletion python-packages/sra_client/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def run(self):
"0x-contract-artifacts",
"0x-contract-addresses",
"0x-order-utils",
"0x-web3",
"web3",
"bandit",
"black",
"coverage",
Expand Down
4 changes: 2 additions & 2 deletions python-packages/sra_client/src/zero_ex/sra_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
For our Maker role, we'll just use the first address available in the node:
>>> maker_address = Web3(eth_node).eth.accounts[0].lower()
>>> maker_address = Web3(eth_node).eth.accounts[0]
The 0x Ganache snapshot loaded into our eth_node has a pre-loaded ZRX balance
for this account, so the example orders below have the maker trading away ZRX.
Expand Down Expand Up @@ -284,7 +284,7 @@
Filling
^^^^^^^
>>> taker_address = Web3(eth_node).eth.accounts[1].lower()
>>> taker_address = Web3(eth_node).eth.accounts[1]
Our taker will take a ZRX/WETH order, but it doesn't have any WETH yet. By
depositing some ether into the WETH contract, it will be given some WETH to
Expand Down

0 comments on commit 4295625

Please sign in to comment.