diff --git a/src/ape_ethereum/provider.py b/src/ape_ethereum/provider.py index 8359729a09..58bba04dde 100644 --- a/src/ape_ethereum/provider.py +++ b/src/ape_ethereum/provider.py @@ -1340,7 +1340,7 @@ def uri(self) -> str: else: raise TypeError(f"Not an URI: {uri}") - config = self.config.model_dump().get(self.network.ecosystem.name, None) + config: dict = self.config.get(self.network.ecosystem.name, None) if config is None: if rpc := self._get_random_rpc(): return rpc @@ -1351,7 +1351,7 @@ def uri(self) -> str: 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 + network_config: dict = (config or {}).get(self.network.name) or DEFAULT_SETTINGS if "url" in network_config: raise ConfigError("Unknown provider setting 'url'. Did you mean 'uri'?") @@ -1370,10 +1370,11 @@ def uri(self) -> str: settings_uri = network_config.get(key, DEFAULT_SETTINGS["uri"]) if _is_uri(settings_uri): + # Is true if HTTP, WS, or IPC. return settings_uri - # Likely was an IPC Path (or websockets) and will connect that way. - return super().http_uri or "" + # Is not HTTP, WS, or IPC. Raise an error. + raise ConfigError(f"Invalid URI (not HTTP, WS, or IPC): {settings_uri}") @property def http_uri(self) -> Optional[str]: diff --git a/tests/functional/geth/test_provider.py b/tests/functional/geth/test_provider.py index 57cb676451..93e8c550ca 100644 --- a/tests/functional/geth/test_provider.py +++ b/tests/functional/geth/test_provider.py @@ -1,3 +1,4 @@ +import re from pathlib import Path from typing import cast @@ -16,6 +17,7 @@ from ape.exceptions import ( APINotImplementedError, BlockNotFoundError, + ConfigError, ContractLogicError, NetworkMismatchError, ProviderError, @@ -127,6 +129,23 @@ def test_uri_non_dev_and_not_configured(mocker, ethereum): assert actual == expected +def test_uri_invalid(geth_provider, project, ethereum): + settings = geth_provider.provider_settings + geth_provider.provider_settings = {} + value = "I AM NOT A URI OF ANY KIND!" + config = {"node": {"ethereum": {"local": {"uri": value}}}} + + try: + with project.temp_config(**config): + # Assert we use the config value. + expected = rf"Invalid URI \(not HTTP, WS, or IPC\): {re.escape(value)}" + with pytest.raises(ConfigError, match=expected): + _ = geth_provider.uri + + finally: + geth_provider.provider_settings = settings + + @geth_process_test def test_repr_connected(geth_provider): actual = repr(geth_provider)