Skip to content

Commit

Permalink
chore: more issues
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Aug 19, 2024
1 parent a8f5c38 commit a4d7db9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/ape/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import TYPE_CHECKING, Any, Callable, Optional, Union, cast

import click
from eth_typing import Hash32
from eth_typing import Hash32, HexStr
from eth_utils import humanize_hash, to_hex
from ethpm_types import ContractType
from ethpm_types.abi import ConstructorABI, ErrorABI, MethodABI
Expand Down Expand Up @@ -522,7 +522,7 @@ def __init__(self, block_id: "BlockID", reason: Optional[str] = None):
if isinstance(block_id, bytes):
block_id_str = to_hex(block_id)
else:
block_id_str = str(block_id)
block_id_str = HexStr(str(block_id))

message = (
"Missing latest block."
Expand Down
10 changes: 5 additions & 5 deletions src/ape_accounts/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class KeyfileAccount(AccountAPI):
keyfile_path: Path
locked: bool = True
__autosign: bool = False
__cached_key: Optional[HexBytes] = None
__cached_key: Optional[bytes] = None

@log_instead_of_fail(default="<KeyfileAccount>")
def __repr__(self) -> str:
Expand All @@ -85,7 +85,7 @@ def address(self) -> AddressType:
return self.network_manager.ethereum.decode_address(self.keyfile["address"])

@property
def __key(self) -> HexBytes:
def __key(self) -> bytes:
if self.__cached_key is not None:
if not self.locked:
logger.warning("Using cached key for %s", self.alias)
Expand Down 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 Expand Up @@ -283,7 +283,7 @@ def _prompt_for_passphrase(self, message: Optional[str] = None, **kwargs) -> str
**kwargs,
)

def __decrypt_keyfile(self, passphrase: str) -> HexBytes:
def __decrypt_keyfile(self, passphrase: str) -> bytes:
try:
return EthAccount.decrypt(self.keyfile, passphrase)
except ValueError as err:
Expand Down
10 changes: 5 additions & 5 deletions src/ape_ethereum/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from evmchains import get_random_rpc
from pydantic.dataclasses import dataclass
from requests import HTTPError
from web3 import HTTPProvider, IPCProvider, Web3, WebsocketProvider
from web3 import HTTPProvider, IPCProvider, Web3, WebSocketProvider
from web3.exceptions import ContractLogicError as Web3ContractLogicError
from web3.exceptions import (
ExtraDataLengthError,
Expand All @@ -28,7 +28,7 @@
TransactionNotFound,
)
from web3.gas_strategies.rpc import rpc_gas_price_strategy
from web3.middleware import geth_poa_middleware
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 @@ -1489,8 +1489,8 @@ def _complete_connect(self):
if is_likely_poa:
break

if is_likely_poa and geth_poa_middleware not in self.web3.middleware_onion:
self.web3.middleware_onion.inject(geth_poa_middleware, layer=0)
if is_likely_poa and ExtraDataToPOAMiddleware not in self.web3.middleware_onion:
self.web3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)

self.network.verify_chain_id(chain_id)

Expand Down Expand Up @@ -1549,7 +1549,7 @@ def _create_web3(
lambda: HTTPProvider(endpoint_uri=http, request_kwargs={"timeout": 30 * 60})
)
if ws := ws_uri:
providers.append(lambda: WebsocketProvider(endpoint_uri=ws))
providers.append(lambda: WebSocketProvider(endpoint_uri=ws))

provider = AutoProvider(potential_providers=providers)
return Web3(provider)
Expand Down
4 changes: 2 additions & 2 deletions 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
from web3.middleware import ExtraDataToPOAMiddleware
from yarl import URL

from ape.api import PluginConfig, SubprocessProvider, TestAccountAPI, TestProviderAPI
Expand Down Expand Up @@ -328,7 +328,7 @@ def start(self, timeout: int = 20):
geth_dev.disconnect()
raise ConnectionError("Unable to connect to locally running geth.")
else:
self.web3.middleware_onion.inject(geth_poa_middleware, layer=0)
self.web3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)

self._process = geth_dev

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
4 changes: 2 additions & 2 deletions tests/functional/geth/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from hexbytes import HexBytes
from web3.exceptions import ContractLogicError as Web3ContractLogicError
from web3.exceptions import ExtraDataLengthError
from web3.middleware import geth_poa_middleware
from web3.middleware import ExtraDataToPOAMiddleware

from ape.exceptions import (
APINotImplementedError,
Expand Down Expand Up @@ -228,7 +228,7 @@ def test_connect_to_chain_that_started_poa(mock_web3, web3_factory, ethereum):
provider.connect()

# Verify PoA middleware was added.
assert mock_web3.middleware_onion.inject.call_args[0] == (geth_poa_middleware,)
assert mock_web3.middleware_onion.inject.call_args[0] == (ExtraDataToPOAMiddleware,)
assert mock_web3.middleware_onion.inject.call_args[1] == {"layer": 0}


Expand Down

0 comments on commit a4d7db9

Please sign in to comment.