Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: provider settings RPC was not being used when it was the default #1919

Merged
merged 3 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ape/managers/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(":")
Expand Down
6 changes: 5 additions & 1 deletion src/ape_geth/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, use no matter what.
return self.provider_settings["uri"]

uri = super().uri
ecosystem = self.network.ecosystem.name
network = self.network.name
Expand All @@ -480,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"]
Expand Down
15 changes: 12 additions & 3 deletions tests/functional/geth/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
TransactionNotFoundError,
)
from ape_ethereum.ecosystem import Block
from ape_ethereum.provider import DEFAULT_SETTINGS
from ape_ethereum.transactions import (
AccessList,
AccessListTransaction,
Expand All @@ -40,22 +41,30 @@ 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
assert cfg["uri"] in PUBLIC_CHAIN_META["ethereum"]["sepolia"]["rpc"]


@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"]
network = ethereum.get_network("mainnet")
provider = network.get_provider("geth", provider_settings={"uri": expected})
assert provider.uri == expected

finally:
geth_provider.provider_settings = settings

Expand Down
Loading