Skip to content

Commit

Permalink
test: add tesT
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Aug 2, 2024
1 parent e61e1a4 commit d05f5a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/ape_ethereum/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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})
)
Expand Down
8 changes: 8 additions & 0 deletions tests/functional/geth/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit d05f5a9

Please sign in to comment.