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: custom network would sometimes use the wrong provider class #2466

Merged
merged 2 commits into from
Jan 13, 2025
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
10 changes: 9 additions & 1 deletion src/ape/api/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ def custom_network(self) -> "NetworkAPI":
A :class:`~ape.api.networks.NetworkAPI` for custom networks where the
network is either not known, unspecified, or does not have an Ape plugin.
"""

ethereum_class = None
for plugin_name, ecosystem_class in self.plugin_manager.ecosystems:
if plugin_name == "ethereum":
Expand Down Expand Up @@ -1130,6 +1129,13 @@ def is_adhoc(self) -> bool:
"""
return self.name == "custom" and not self._is_custom

@property
def is_custom(self) -> bool:
"""
True when this network is a configured custom network.
"""
return self._is_custom

@cached_property
def providers(self): # -> dict[str, Partial[ProviderAPI]]
"""
Expand Down Expand Up @@ -1161,6 +1167,8 @@ def providers(self): # -> dict[str, Partial[ProviderAPI]]
(self.is_fork and "Fork" in provider_class.__name__)
or (not self.is_fork and "Fork" not in provider_class.__name__)
)
and provider_class.__name__
== "Node" # Ensure uses Node class instead of GethDev
)
):
# NOTE: Lazily load provider config
Expand Down
2 changes: 1 addition & 1 deletion src/ape/managers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def get_custom_error(self, err: ContractLogicError) -> Optional[CustomError]:
"""
Get a custom error for the given contract logic error using the contract-type
found from address-data in the error. Returns ``None`` if the given error is
not a custom-error or it is not able to find the associated contract type or
not a custom-error, or it is not able to find the associated contract type or
address.

Args:
Expand Down
6 changes: 3 additions & 3 deletions src/ape/managers/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def get_provider_from_choice(
default_network = self.default_ecosystem.default_network
return default_network.get_provider(provider_settings=provider_settings)

elif _is_custom_network(network_choice):
elif _is_adhoc_url(network_choice):
# Custom network w/o ecosystem & network spec.
return self.create_custom_provider(network_choice)

Expand All @@ -568,7 +568,7 @@ def get_provider_from_choice(
provider_value = ":".join(selections[2:])
selections[2] = provider_value
selections = selections[:3]
if _is_custom_network(provider_value):
if _is_adhoc_url(provider_value):
selections[1] = selections[1] or "custom"

if selections == network_choice or len(selections) == 1:
Expand Down Expand Up @@ -754,7 +754,7 @@ def _validate_filter(arg: Optional[Union[list[str], str]], options: set[str]):
return filters


def _is_custom_network(value: str) -> bool:
def _is_adhoc_url(value: str) -> bool:
return (
value.startswith("http://")
or value.startswith("https://")
Expand Down
7 changes: 4 additions & 3 deletions src/ape_ethereum/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,9 @@ def estimate_gas_cost(self, txn: TransactionAPI, block_id: Optional["BlockID"] =
@cached_property
def chain_id(self) -> int:
default_chain_id = None
if self.network.name not in ("adhoc", "custom") and not self.network.is_dev:
# If using a live plugin-based network, the chain ID is hardcoded.

if self.network.is_custom or not self.network.is_dev:
# If using a live network, the chain ID is hardcoded.
default_chain_id = self.network.chain_id

try:
Expand Down Expand Up @@ -1631,7 +1632,7 @@ def _complete_connect(self):

except Exception:
# Some chains are "light" and we may not be able to detect
# if it need PoA middleware.
# if it needs PoA middleware.
continue

else:
Expand Down
5 changes: 5 additions & 0 deletions tests/functional/test_network_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ def test_providers_custom_network(project, custom_networks_config_dict, ethereum
network = ethereum.apenet
actual = network.providers
assert "node" in actual
node = actual["node"]
# NOTE: There was a bug where sometimes it would use the GethDev class
# and sometimes it would use the Node class. Node is what we want.
assert "Node" in repr(node.func)
assert "GethDev" not in repr(node.func)


def test_providers_custom_non_fork_network_does_not_use_fork_provider(
Expand Down
Loading