Skip to content

Commit

Permalink
fix: issue connecting to a provider that was once connected but now i…
Browse files Browse the repository at this point in the history
…sn't (#2022)
  • Loading branch information
antazoey authored Apr 23, 2024
1 parent 01d6d73 commit f0d6c05
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/ape/api/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,11 @@ def get_provider(
connection_id = provider.connection_id
if connection_id in ProviderContextManager.connected_providers:
# Likely multi-chain testing or utilizing multiple on-going connections.
return ProviderContextManager.connected_providers[connection_id]
provider = ProviderContextManager.connected_providers[connection_id]
if not provider.is_connected:
provider.connect()

return provider

return provider

Expand Down
13 changes: 13 additions & 0 deletions tests/functional/test_network_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,16 @@ def test_config_networks_from_custom_ecosystem(
cfg_by_get = ethereum_config.get("apenet")
assert cfg_by_get is not None
assert cfg_by_get.default_transaction_type == TransactionType.STATIC


def test_use_provider_using_provider_instance(eth_tester_provider):
network = eth_tester_provider.network
with network.use_provider(eth_tester_provider) as provider:
assert id(provider) == id(eth_tester_provider)


def test_use_provider_previously_used_and_not_connected(eth_tester_provider):
network = eth_tester_provider.network
eth_tester_provider.disconnect()
with network.use_provider("test") as provider:
assert provider.is_connected
6 changes: 0 additions & 6 deletions tests/functional/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,6 @@ def test_no_comma_in_rpc_url():
assert "," not in sanitised_url


def test_use_provider_using_provider_instance(eth_tester_provider):
network = eth_tester_provider.network
with network.use_provider(eth_tester_provider) as provider:
assert id(provider) == id(eth_tester_provider)


def test_send_transaction_when_no_error_and_receipt_fails(
mock_transaction, mock_web3, eth_tester_provider, owner, vyper_contract_instance
):
Expand Down

0 comments on commit f0d6c05

Please sign in to comment.