From d05f5a9844bc9903d7d943c97c6b966098965051 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Fri, 2 Aug 2024 10:23:50 -0500 Subject: [PATCH] test: add tesT --- src/ape_ethereum/provider.py | 10 +++++++--- tests/functional/geth/test_provider.py | 8 ++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/ape_ethereum/provider.py b/src/ape_ethereum/provider.py index f95b69698a..9364bb6706 100644 --- a/src/ape_ethereum/provider.py +++ b/src/ape_ethereum/provider.py @@ -1382,7 +1382,9 @@ def _ots_api_level(self) -> Optional[int]: def _set_web3(self): # Clear cached version when connecting to another URI. self._client_version = None - self._web3 = _create_web3(http_uri=self.http_uri, ipc_path=self.ipc_path, ws_uri=self.ws_uri) + self._web3 = _create_web3( + http_uri=self.http_uri, ipc_path=self.ipc_path, ws_uri=self.ws_uri + ) def _complete_connect(self): client_version = self.client_version.lower() @@ -1477,13 +1479,15 @@ def connect(self): self._complete_connect() -def _create_web3(http_uri: Optional[str] = None, ipc_path: Optional[Path] = None, ws_uri: Optional[str] = None): +def _create_web3( + http_uri: Optional[str] = None, ipc_path: Optional[Path] = None, ws_uri: Optional[str] = None +): # NOTE: This list is ordered by try-attempt. # Try ENV, then IPC, and then HTTP last. providers: list = [load_provider_from_environment] if ipc := ipc_path: providers.append(lambda: IPCProvider(ipc_path=ipc)) - if http := http_uri : + if http := http_uri: providers.append( lambda: HTTPProvider(endpoint_uri=http, request_kwargs={"timeout": 30 * 60}) ) diff --git a/tests/functional/geth/test_provider.py b/tests/functional/geth/test_provider.py index ddd8622aa6..c7ecc5d314 100644 --- a/tests/functional/geth/test_provider.py +++ b/tests/functional/geth/test_provider.py @@ -216,6 +216,14 @@ def test_connect_to_chain_that_started_poa(mock_web3, web3_factory, ethereum): assert mock_web3.middleware_onion.inject.call_args[1] == {"layer": 0} +@geth_process_test +def test_connect_using_only_ipc_for_uri(project, networks, geth_provider): + ipc_path = geth_provider.ipc_path + with project.temp_config(node={"ethereum": {"local": {"uri": f"{ipc_path}"}}}): + with networks.ethereum.local.use_provider("node") as node: + assert node.uri == f"{ipc_path}" + + @geth_process_test @pytest.mark.parametrize("block_id", (0, "0", "0x0", HexStr("0x0"))) def test_get_block(geth_provider, block_id):