Skip to content

Commit

Permalink
fix: allow forking a fork
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Oct 27, 2024
1 parent 4199cac commit b437844
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ape/api/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ def pop_provider(self):
current_id = self.provider_stack.pop()

# Disconnect the provider in same cases.
if self.disconnect_map[current_id]:
if self.disconnect_map.get(current_id):
if provider := self.network_manager.active_provider:
provider.disconnect()

Expand Down
8 changes: 6 additions & 2 deletions src/ape/managers/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,14 @@ def fork(
Returns:
:class:`~ape.api.networks.ProviderContextManager`
"""
network_name = self.network.name
forked_network_name = (
network_name if network_name.endswith("-fork") else f"{network_name}-fork"
)
try:
forked_network = self.ecosystem.get_network(f"{self.network.name}-fork")
forked_network = self.ecosystem.get_network(forked_network_name)
except NetworkNotFoundError as err:
raise NetworkError(f"Unable to fork network '{self.network.name}'.") from err
raise NetworkError(f"Unable to fork network '{network_name}'.") from err

provider_settings = provider_settings or {}
fork_settings = {}
Expand Down
5 changes: 5 additions & 0 deletions tests/functional/test_network_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ def test_fork(networks, mock_sepolia, mock_fork_provider):
with ctx as provider:
assert provider.name == "mock"
assert provider.network.name == "sepolia-fork"
# Fork the fork.
ctx2 = networks.fork()
with ctx2 as provider2:
assert provider2.name == "mock"
assert provider2.network.name == "sepolia-fork"


def test_fork_specify_provider(networks, mock_sepolia, mock_fork_provider):
Expand Down

0 comments on commit b437844

Please sign in to comment.