From 366224256ac3d4c1f36a04138c847aa04a6f7540 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Wed, 7 Feb 2024 13:50:31 -0600 Subject: [PATCH 1/3] fix: issue when running on default --- src/ape/managers/networks.py | 1 + src/ape/utils/misc.py | 1 + src/ape_geth/provider.py | 4 ++++ tests/functional/geth/test_provider.py | 4 ++-- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ape/managers/networks.py b/src/ape/managers/networks.py index c4774e9184..0c5077b33a 100644 --- a/src/ape/managers/networks.py +++ b/src/ape/managers/networks.py @@ -447,6 +447,7 @@ def get_provider_from_choice( return default_network.get_provider(provider_settings=provider_settings) elif _is_custom_network(network_choice): + # Custom network w/o ecosystem & network spec. return self.create_custom_provider(network_choice) selections = network_choice.split(":") diff --git a/src/ape/utils/misc.py b/src/ape/utils/misc.py index 5668c215a8..ea1ecbe313 100644 --- a/src/ape/utils/misc.py +++ b/src/ape/utils/misc.py @@ -14,6 +14,7 @@ from importlib_metadata import PackageNotFoundError, distributions, packages_distributions from importlib_metadata import version as version_metadata from packaging.specifiers import SpecifierSet +from requests import head from tqdm.auto import tqdm # type: ignore from ape.exceptions import APINotImplementedError, ProviderNotConnectedError diff --git a/src/ape_geth/provider.py b/src/ape_geth/provider.py index 88ae5f6fbc..c1ddac80c2 100644 --- a/src/ape_geth/provider.py +++ b/src/ape_geth/provider.py @@ -472,6 +472,10 @@ def build_command(self) -> List[str]: class Geth(EthereumNodeProvider): @property def uri(self) -> str: + if "uri" in self.provider_settings: + # If specifying in Python, user no matter what. + return self.provider_settings["uri"] + uri = super().uri ecosystem = self.network.ecosystem.name network = self.network.name diff --git a/tests/functional/geth/test_provider.py b/tests/functional/geth/test_provider.py index d657ed2f44..63a0776c77 100644 --- a/tests/functional/geth/test_provider.py +++ b/tests/functional/geth/test_provider.py @@ -23,7 +23,7 @@ TransactionStatusEnum, TransactionType, ) -from ape_geth.provider import GethDevProcess, GethNotInstalledError +from ape_geth.provider import GethDevProcess, GethNotInstalledError, _RPCFactory from tests.conftest import GETH_URI, geth_process_test @@ -40,7 +40,7 @@ def test_uri(geth_provider): @geth_process_test -def test_default_public_uri(config): +def test_uri_localhost_not_running_uses_random_default(config): cfg = config.get_config("geth").ethereum.mainnet assert cfg["uri"] in PUBLIC_CHAIN_META["ethereum"]["mainnet"]["rpc"] cfg = config.get_config("geth").ethereum.sepolia From 9fe6f2486add5b2365ea82ce4141a46c0209f9da Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Wed, 7 Feb 2024 15:09:58 -0600 Subject: [PATCH 2/3] refactor: much simpler --- src/ape/utils/misc.py | 1 - src/ape_geth/provider.py | 4 ++-- tests/functional/geth/test_provider.py | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/ape/utils/misc.py b/src/ape/utils/misc.py index ea1ecbe313..5668c215a8 100644 --- a/src/ape/utils/misc.py +++ b/src/ape/utils/misc.py @@ -14,7 +14,6 @@ from importlib_metadata import PackageNotFoundError, distributions, packages_distributions from importlib_metadata import version as version_metadata from packaging.specifiers import SpecifierSet -from requests import head from tqdm.auto import tqdm # type: ignore from ape.exceptions import APINotImplementedError, ProviderNotConnectedError diff --git a/src/ape_geth/provider.py b/src/ape_geth/provider.py index c1ddac80c2..6db89f354f 100644 --- a/src/ape_geth/provider.py +++ b/src/ape_geth/provider.py @@ -473,7 +473,7 @@ class Geth(EthereumNodeProvider): @property def uri(self) -> str: if "uri" in self.provider_settings: - # If specifying in Python, user no matter what. + # If specifying in Python, use no matter what. return self.provider_settings["uri"] uri = super().uri @@ -484,7 +484,7 @@ def uri(self) -> str: if not uri or uri == DEFAULT_SETTINGS["uri"]: # Do not override explicit configuration if ecosystem in self.config: - # Shape of this is odd. Pydantic model containing dicts + # Shape of this is odd. Pydantic model containing dicts if network_config := self.config[ecosystem].get(network): if "uri" in network_config: return network_config["uri"] diff --git a/tests/functional/geth/test_provider.py b/tests/functional/geth/test_provider.py index 63a0776c77..8273ec7583 100644 --- a/tests/functional/geth/test_provider.py +++ b/tests/functional/geth/test_provider.py @@ -17,13 +17,14 @@ TransactionNotFoundError, ) from ape_ethereum.ecosystem import Block +from ape_ethereum.provider import DEFAULT_SETTINGS from ape_ethereum.transactions import ( AccessList, AccessListTransaction, TransactionStatusEnum, TransactionType, ) -from ape_geth.provider import GethDevProcess, GethNotInstalledError, _RPCFactory +from ape_geth.provider import GethDevProcess, GethNotInstalledError from tests.conftest import GETH_URI, geth_process_test @@ -48,14 +49,23 @@ def test_uri_localhost_not_running_uses_random_default(config): @geth_process_test -def test_uri_uses_value_from_config(geth_provider, temp_config): +def test_uri_when_configured(geth_provider, temp_config, ethereum): settings = geth_provider.provider_settings geth_provider.provider_settings = {} value = "https://value/from/config" - config = {"geth": {"ethereum": {"local": {"uri": value}}}} + config = {"geth": {"ethereum": {"local": {"uri": value}, "mainnet": {"uri": value}}}} try: with temp_config(config): + # Assert we use the config value. assert geth_provider.uri == value + + # Assert provider settings takes precedence. + expected = DEFAULT_SETTINGS["uri"] + for name in ("local", "mainnet"): + network = ethereum.get_network(name) + provider = network.get_provider("geth", provider_settings={"uri": expected}) + assert provider.uri == expected + finally: geth_provider.provider_settings = settings From 6e2d0d43adcc0b78b7303a5b0a5690ebe642478d Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Wed, 7 Feb 2024 15:24:42 -0600 Subject: [PATCH 3/3] test: limit to mainnet, all we need --- tests/functional/geth/test_provider.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/functional/geth/test_provider.py b/tests/functional/geth/test_provider.py index 8273ec7583..39497af8fa 100644 --- a/tests/functional/geth/test_provider.py +++ b/tests/functional/geth/test_provider.py @@ -61,10 +61,9 @@ def test_uri_when_configured(geth_provider, temp_config, ethereum): # Assert provider settings takes precedence. expected = DEFAULT_SETTINGS["uri"] - for name in ("local", "mainnet"): - network = ethereum.get_network(name) - provider = network.get_provider("geth", provider_settings={"uri": expected}) - assert provider.uri == expected + network = ethereum.get_network("mainnet") + provider = network.get_provider("geth", provider_settings={"uri": expected}) + assert provider.uri == expected finally: geth_provider.provider_settings = settings