Skip to content

Commit

Permalink
refactor: use new fork tools
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Nov 3, 2023
1 parent de58e2e commit 8711a7a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-yaml

Expand All @@ -10,7 +10,7 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.10.1
hooks:
- id: black
name: black
Expand All @@ -21,7 +21,7 @@ repos:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
rev: v1.6.1
hooks:
- id: mypy
additional_dependencies: [types-PyYAML, types-requests, types-setuptools, pydantic]
Expand Down
40 changes: 20 additions & 20 deletions ape_foundry/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from ape.api import (
BlockAPI,
ForkedNetworkAPI,
PluginConfig,
ReceiptAPI,
SubprocessProvider,
Expand Down Expand Up @@ -906,32 +907,31 @@ def _fork_config(self) -> FoundryForkConfig:

return config.fork[ecosystem_name][network_name]

@cached_property
def _upstream_provider(self) -> UpstreamProvider:
upstream_network = self.network.ecosystem.networks[self._upstream_network_name]
upstream_provider_name = self._fork_config.upstream_provider
# NOTE: if 'upstream_provider_name' is 'None', this gets the default upstream provider.
return upstream_network.get_provider(provider_name=upstream_provider_name)
@property
def forked_network(self) -> ForkedNetworkAPI:
return cast(ForkedNetworkAPI, self.network)

def connect(self):
super().connect()

# Verify that we're connected to a Foundry node with fork mode.
upstream_provider = self._upstream_provider
upstream_provider.connect()
try:
upstream_genesis_block_hash = upstream_provider.get_block(0).hash
except ExtraDataLengthError as err:
if isinstance(upstream_provider, Web3Provider):
logger.error(
f"Upstream provider '{upstream_provider.name}' missing Geth PoA middleware."
)
upstream_provider.web3.middleware_onion.inject(geth_poa_middleware, layer=0)
# If using the provider config for upstream_provider,
# set the network one in this session, so other features work in core.
if upstream_name := self._fork_config.upstream_provider:
self.forked_network.network_config.upstream_provider = upstream_name

with self.forked_network.use_upstream_provider() as upstream_provider:
try:
upstream_genesis_block_hash = upstream_provider.get_block(0).hash
else:
raise FoundryProviderError(f"Unable to get genesis block: {err}.") from err
except ExtraDataLengthError as err:
if isinstance(upstream_provider, Web3Provider):
logger.error(
f"Upstream provider '{upstream_provider.name}' missing Geth PoA middleware."
)
upstream_provider.web3.middleware_onion.inject(geth_poa_middleware, layer=0)
upstream_genesis_block_hash = upstream_provider.get_block(0).hash
else:
raise FoundryProviderError(f"Unable to get genesis block: {err}.") from err

upstream_provider.disconnect()
if self.get_block(0).hash != upstream_genesis_block_hash:
logger.warning(
"Upstream network has mismatching genesis block. "
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"ape-polygon", # For running polygon fork tests
],
"lint": [
"black>=23.7.0,<24", # auto-formatter and linter
"mypy>=1.5.1,<2", # Static type analyzer
"black>=23.10.1,<24", # auto-formatter and linter
"mypy>=1.6.1,<2", # Static type analyzer
"types-requests", # Needed due to mypy typeshed
"types-setuptools", # Needed due to mypy typeshed
"types-PyYAML", # Needed due to mypy typeshed
Expand Down Expand Up @@ -69,7 +69,7 @@
url="https://github.com/ApeWorX/ape-foundry",
include_package_data=True,
install_requires=[
"eth-ape>=0.6.12,<0.7",
"eth-ape>=0.6.23,<0.7",
"evm-trace", # Use same version as ape
"hexbytes", # Use same version as ape
"web3", # Use same version as ape
Expand Down

0 comments on commit 8711a7a

Please sign in to comment.