From 10c7ad92f9b62538a7c792041143b5a7f04d6a83 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Mon, 19 Aug 2024 14:36:37 -0500 Subject: [PATCH] refactor: upgrade web3 --- setup.py | 18 +++++++++--------- src/ape_accounts/accounts.py | 4 ++-- src/ape_ethereum/provider.py | 13 +++++-------- src/ape_node/provider.py | 2 +- src/ape_test/accounts.py | 2 +- tests/functional/geth/test_provider.py | 2 +- tests/functional/geth/test_trace.py | 2 +- tests/functional/test_ecosystem.py | 4 ++-- 8 files changed, 22 insertions(+), 25 deletions(-) diff --git a/setup.py b/setup.py index f064c4f0b2..437ae54b00 100644 --- a/setup.py +++ b/setup.py @@ -115,15 +115,15 @@ "urllib3>=2.0.0,<3", "watchdog>=3.0,<4", # ** Dependencies maintained by Ethereum Foundation ** - # All version pins dependent on web3[tester] - "eth-abi", - "eth-account", - "eth-typing", - "eth-utils", - "hexbytes", - "py-geth>=5.0.0-beta.2,<6", - "trie>=3.0.1,<4", # Peer: stricter pin needed for uv support. - "web3[tester]>=6.17.2,<7", + "eth-abi>=5.1.0,<6", + "eth-account>=0.13.3,<0.14", + "eth-tester>=0.12.0b1", + "eth-typing>=5.0.0,<6", + "eth-utils>=5.0.0,<6", + "hexbytes>=1.2.1,<2", + "py-geth>=5.0.0,<6", + "trie>=3.0.1,<4", + "web3>=7.2.0,<8", # ** Dependencies maintained by ApeWorX ** "eip712>=0.2.10,<0.3", "ethpm-types>=0.6.17,<0.7", diff --git a/src/ape_accounts/accounts.py b/src/ape_accounts/accounts.py index b07ff301a3..ff539a9d12 100644 --- a/src/ape_accounts/accounts.py +++ b/src/ape_accounts/accounts.py @@ -241,14 +241,14 @@ def sign_raw_msghash(self, msghash: HexBytes) -> Optional[MessageSignature]: ) # NOTE: Signing a raw hash is so dangerous, we don't want to allow autosigning it - if not click.confirm("Please confirm you wish to sign using `EthAccount.signHash`"): + if not click.confirm("Please confirm you wish to sign using `EthAccount.unsafe_sign_hash`"): return None # Ignoring misleading deprecated warning from web3.py. # Also, we have already warned the user about the safety. with warnings.catch_warnings(): warnings.simplefilter("ignore") - signed_msg = EthAccount.signHash(msghash, self.__key) + signed_msg = EthAccount.unsafe_sign_hash(msghash, self.__key) return MessageSignature( v=signed_msg.v, diff --git a/src/ape_ethereum/provider.py b/src/ape_ethereum/provider.py index 89aee224f8..af1d97f5ea 100644 --- a/src/ape_ethereum/provider.py +++ b/src/ape_ethereum/provider.py @@ -20,18 +20,17 @@ from evmchains import get_random_rpc from pydantic.dataclasses import dataclass from requests import HTTPError -from web3 import HTTPProvider, IPCProvider, Web3 -from web3 import WebsocketProvider as WebSocketProvider -from web3._utils.http import construct_user_agent +from web3 import HTTPProvider, IPCProvider, Web3, WebSocketProvider from web3.exceptions import ContractLogicError as Web3ContractLogicError from web3.exceptions import ( ExtraDataLengthError, MethodUnavailable, TimeExhausted, TransactionNotFound, + Web3RPCError, ) from web3.gas_strategies.rpc import rpc_gas_price_strategy -from web3.middleware import geth_poa_middleware as ExtraDataToPOAMiddleware +from web3.middleware import ExtraDataToPOAMiddleware from web3.middleware.validation import MAX_EXTRADATA_LENGTH from web3.providers import AutoProvider from web3.providers.auto import load_provider_from_environment @@ -1027,7 +1026,7 @@ def send_transaction(self, txn: TransactionAPI) -> ReceiptAPI: if txn_hash is None: txn_hash = to_hex(self.web3.eth.send_raw_transaction(txn.serialize_transaction())) - except (ValueError, Web3ContractLogicError) as err: + except (ValueError, Web3ContractLogicError, Web3RPCError) as err: vm_err = self.get_virtual_machine_error( err, txn=txn, set_ape_traceback=txn.raise_on_revert ) @@ -1316,9 +1315,7 @@ class EthereumNodeProvider(Web3Provider, ABC): name: str = "node" # NOTE: Appends user-agent to base User-Agent string. - request_header: dict = { - "User-Agent": construct_user_agent(str(HTTPProvider)), - } + request_header: dict = HTTPProvider.get_request_headers() @property def uri(self) -> str: diff --git a/src/ape_node/provider.py b/src/ape_node/provider.py index 44581963b3..3753b54e9f 100644 --- a/src/ape_node/provider.py +++ b/src/ape_node/provider.py @@ -13,7 +13,7 @@ from pydantic import field_validator from pydantic_settings import SettingsConfigDict from requests.exceptions import ConnectionError -from web3.middleware import geth_poa_middleware as ExtraDataToPOAMiddleware +from web3.middleware import ExtraDataToPOAMiddleware from yarl import URL from ape.api import PluginConfig, SubprocessProvider, TestAccountAPI, TestProviderAPI diff --git a/src/ape_test/accounts.py b/src/ape_test/accounts.py index 690fb4f1b7..0029aaa972 100644 --- a/src/ape_test/accounts.py +++ b/src/ape_test/accounts.py @@ -158,7 +158,7 @@ def sign_transaction(self, txn: TransactionAPI, **signer_options) -> Optional[Tr def sign_raw_msghash(self, msghash: HexBytes) -> MessageSignature: with warnings.catch_warnings(): warnings.simplefilter("ignore") - signed_msg = EthAccount.signHash(msghash, self.private_key) + signed_msg = EthAccount.unsafe_sign_hash(msghash, self.private_key) return MessageSignature( v=signed_msg.v, diff --git a/tests/functional/geth/test_provider.py b/tests/functional/geth/test_provider.py index 43b68b6e93..27ad94e4bf 100644 --- a/tests/functional/geth/test_provider.py +++ b/tests/functional/geth/test_provider.py @@ -10,7 +10,7 @@ from web3 import AutoProvider, Web3 from web3.exceptions import ContractLogicError as Web3ContractLogicError from web3.exceptions import ExtraDataLengthError -from web3.middleware import geth_poa_middleware as ExtraDataToPOAMiddleware +from web3.middleware import ExtraDataToPOAMiddleware from web3.providers import HTTPProvider from ape.exceptions import ( diff --git a/tests/functional/geth/test_trace.py b/tests/functional/geth/test_trace.py index 7224f72ceb..45a96f2257 100644 --- a/tests/functional/geth/test_trace.py +++ b/tests/functional/geth/test_trace.py @@ -13,7 +13,7 @@ LOCAL_TRACE = r""" Call trace for '0x([A-Fa-f0-9]{64})' tx\.origin=0x[a-fA-F0-9]{40} -ContractA\.methodWithoutArguments\(\) -> 0x[A-Fa-f0-9]{2,}..[A-Fa-f0-9]{4} \[\d+ gas\] +ContractA\.methodWithoutArguments\(\) -> 0x[A-Fa-f0-9]{4}..[A-Fa-f0-9]{4} \[\d+ gas\] ├── SYMBOL\.supercluster\(x=234444\) -> \[ │ \[23523523235235, 11111111111, 234444\], │ \[ diff --git a/tests/functional/test_ecosystem.py b/tests/functional/test_ecosystem.py index 86e78a3799..a4efd90040 100644 --- a/tests/functional/test_ecosystem.py +++ b/tests/functional/test_ecosystem.py @@ -1153,11 +1153,11 @@ def get_calltree(self) -> CallTreeNode: { "name": "NumberChange", "calldata": { - "b": "0x3e..404b", + "b": "0x3ee0..404b", "prevNum": 0, "dynData": '"Dynamic"', "newNum": 123, - "dynIndexed": "0x9f..a94d", + "dynIndexed": "0x9f3d..a94d", }, } ]