Skip to content

Commit

Permalink
fix: issue where Ape tries starting geth-dev for custom networks w/o …
Browse files Browse the repository at this point in the history
…URIs (ApeWorX#2140)
  • Loading branch information
antazoey committed Jun 14, 2024
1 parent ff3754e commit 941fb4f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/ape_ethereum/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,11 @@ def uri(self) -> str:

config = self.config.model_dump().get(self.network.ecosystem.name, None)
if config is None:
return DEFAULT_SETTINGS["uri"]
if self.network.is_dev:
return DEFAULT_SETTINGS["uri"]

# We have no way of knowing what URL the user wants.
raise ProviderError(f"Please configure a URL for '{self.network_choice}'.")

# Use value from config file
network_config = config.get(self.network.name) or DEFAULT_SETTINGS
Expand Down
18 changes: 17 additions & 1 deletion tests/functional/geth/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
BlockNotFoundError,
ContractLogicError,
NetworkMismatchError,
ProviderError,
TransactionError,
TransactionNotFoundError,
)
Expand All @@ -29,7 +30,7 @@
TransactionStatusEnum,
TransactionType,
)
from ape_node.provider import GethDevProcess, NodeSoftwareNotInstalledError
from ape_node.provider import GethDevProcess, Node, NodeSoftwareNotInstalledError
from tests.conftest import GETH_URI, geth_process_test


Expand Down Expand Up @@ -77,6 +78,21 @@ def test_uri_when_configured(geth_provider, project, ethereum):
assert actual_mainnet_uri == expected


def test_uri_non_dev_and_not_configured(ethereum):
"""
If the URI was not configured and we are not using a dev
network (local or -fork), then it should fail, rather than
use local-host.
"""
network = ethereum.sepolia.model_copy(deep=True)
network.name = "gorillanet"
network.ecosystem.name = "gorillas"
provider = Node.model_construct(network=network, request_header={})

with pytest.raises(ProviderError):
_ = provider.uri


@geth_process_test
def test_repr_connected(geth_provider):
actual = repr(geth_provider)
Expand Down

0 comments on commit 941fb4f

Please sign in to comment.