Skip to content

Commit

Permalink
fix: include URI in provider.network_choice (#2449)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Jan 1, 2025
1 parent 11f93d0 commit 309d0c7
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 167 deletions.
13 changes: 6 additions & 7 deletions src/ape/api/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,6 @@ def empty(self) -> bool:
"""
``True`` when there are no providers in the context.
"""

return not self.connected_providers or not self.provider_stack

def __enter__(self, *args, **kwargs):
Expand Down Expand Up @@ -895,7 +894,7 @@ def disconnect_all(self):
self.connected_providers = {}


def _set_provider(provider: "ProviderAPI") -> "ProviderAPI":
def _connect_provider(provider: "ProviderAPI") -> "ProviderAPI":
connection_id = provider.connection_id
if connection_id in ProviderContextManager.connected_providers:
# Likely multi-chain testing or utilizing multiple on-going connections.
Expand Down Expand Up @@ -1194,6 +1193,7 @@ def get_provider(
self,
provider_name: Optional[str] = None,
provider_settings: Optional[dict] = None,
connect: bool = False,
):
"""
Get a provider for the given name. If given ``None``, returns the default provider.
Expand All @@ -1203,6 +1203,7 @@ def get_provider(
When ``None``, returns the default provider.
provider_settings (dict, optional): Settings to apply to the provider. Defaults to
``None``.
connect (bool): Set to ``True`` when you also want the provider to connect.
Returns:
:class:`~ape.api.providers.ProviderAPI`
Expand All @@ -1215,7 +1216,6 @@ def get_provider(
f"\n {self.name}:"
"\n default_provider: <DEFAULT_PROVIDER>"
)

provider_settings = provider_settings or {}
if ":" in provider_name:
# NOTE: Shortcut that allows `--network ecosystem:network:http://...` to work
Expand All @@ -1228,7 +1228,7 @@ def get_provider(

if provider_name in self.providers:
provider = self.providers[provider_name](provider_settings=provider_settings)
return _set_provider(provider)
return _connect_provider(provider) if connect else provider

elif self.is_fork:
# If it can fork Ethereum (and we are asking for it) assume it can fork this one.
Expand All @@ -1239,7 +1239,7 @@ def get_provider(
provider_settings=provider_settings,
network=self,
)
return _set_provider(provider)
return _connect_provider(provider) if connect else provider

raise ProviderNotFoundError(
provider_name,
Expand Down Expand Up @@ -1288,7 +1288,7 @@ def use_provider(
# NOTE: The main reason we allow a provider instance here is to avoid unnecessarily
# re-initializing the class.
provider_obj = (
self.get_provider(provider_name=provider, provider_settings=settings)
self.get_provider(provider_name=provider, provider_settings=settings, connect=True)
if isinstance(provider, str)
else provider
)
Expand Down Expand Up @@ -1448,7 +1448,6 @@ def upstream_provider(self) -> "UpstreamProvider":
When not set, will attempt to use the default provider, if one
exists.
"""

config_choice: str = self.config.get("upstream_provider")
if provider_name := config_choice or self.upstream_network.default_provider_name:
return self.upstream_network.get_provider(provider_name)
Expand Down
3 changes: 1 addition & 2 deletions src/ape_ethereum/ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
ConversionError,
CustomError,
DecodingError,
ProviderError,
SignatureError,
)
from ape.logging import logger
Expand Down Expand Up @@ -1459,7 +1458,7 @@ def decode_custom_error(
try:
if not (last_addr := next(trace.get_addresses_used(reverse=True), None)):
return None
except ProviderError:
except Exception:
# When unable to get trace-frames properly, such as eth-tester.
return None

Expand Down
Loading

0 comments on commit 309d0c7

Please sign in to comment.