Skip to content

Commit

Permalink
fix: host issues
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Nov 3, 2023
1 parent 6958796 commit 552bb48
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
15 changes: 5 additions & 10 deletions ape_foundry/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 552bb48

Please sign in to comment.