From 552bb48703267d073252f305e55569bbf4b9eec0 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Fri, 3 Nov 2023 15:32:59 -0500 Subject: [PATCH] fix: host issues --- ape_foundry/provider.py | 15 +++++---------- tests/test_provider.py | 7 +++++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/ape_foundry/provider.py b/ape_foundry/provider.py index 9f4fcae..7d18fe4 100644 --- a/ape_foundry/provider.py +++ b/ape_foundry/provider.py @@ -192,17 +192,9 @@ def project_folder(self) -> Path: @property def uri(self) -> str: if self._host is not None: - if ( - self.settings.host - and self.settings.host.startswith("http") - and self._host - and self._host.startswith("http") - and self.settings.host == self._host - ): - return self._host - # else: was changed in config. + return self._host - if config_host := self.settings.host: + elif config_host := self.settings.host: if config_host == "auto": self._host = "auto" return self._host @@ -213,12 +205,15 @@ def uri(self) -> str: self._host = f"https://{config_host}" else: self._host = config_host + if "127.0.0.1" in config_host or "localhost" in config_host: host_without_http = self._host[7:] if ":" not in host_without_http: self._host = f"{self._host}:{DEFAULT_PORT}" + else: self._host = f"http://127.0.0.1:{DEFAULT_PORT}" + return self._host @property diff --git a/tests/test_provider.py b/tests/test_provider.py index d866a1a..8cb125c 100644 --- a/tests/test_provider.py +++ b/tests/test_provider.py @@ -297,13 +297,16 @@ def test_remote_host(temp_config, networks, no_anvil_bin): def test_remote_host_using_env_var(temp_config, networks, no_anvil_bin): original = os.environ.get("APE_FOUNDRY_HOST") os.environ["APE_FOUNDRY_HOST"] = "https://example2.com" + try: with pytest.raises( FoundryProviderError, match=r"Failed to connect to remote Anvil node at 'https://example2.com'\.", ): - with networks.ethereum.local.use_provider("foundry"): - assert True + with networks.ethereum.local.use_provider("foundry") as provider: + # It shouldn't actually get to the line below, + # but in case it does, this is a helpful debug line. + assert provider.uri == os.environ["APE_FOUNDRY_HOST"], "env var not setting." finally: if original is None: