Skip to content

Commit

Permalink
refactor: upgrade web3
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Sep 3, 2024
1 parent d97fff0 commit 16c58ec
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 15 deletions.
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@
# All version pins dependent on web3[tester]
"eth-abi",
"eth-account",
"eth-tester",
"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",
"py-geth",
"trie", # Peer: stricter pin needed for uv support.
"web3>=7.0.0b9,<8",
# ** Dependencies maintained by ApeWorX **
"eip712>=0.2.10,<0.3",
"ethpm-types>=0.6.17,<0.7",
Expand Down
4 changes: 2 additions & 2 deletions src/ape_accounts/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/ape_ethereum/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
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 import HTTPProvider, IPCProvider, Web3, WebSocketProvider
from web3._utils.http import construct_user_agent
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
Expand Down Expand Up @@ -1010,7 +1010,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
)
Expand Down
2 changes: 1 addition & 1 deletion src/ape_node/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ape_test/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/geth/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/geth/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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\],
│ \[
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/test_ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}
]
Expand Down

0 comments on commit 16c58ec

Please sign in to comment.