From 17c61205bb424f5a4f33384f49363bba066fff2f Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Wed, 7 Feb 2024 15:09:58 -0600 Subject: [PATCH] refactor: much simpler --- src/ape/utils/misc.py | 1 - src/ape_geth/provider.py | 2 +- tests/functional/geth/test_provider.py | 16 +++++++++++++--- 3 files changed, 14 insertions(+), 5 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..9368df475a 100644 --- a/src/ape_geth/provider.py +++ b/src/ape_geth/provider.py @@ -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