From b51c7b1e9c196320d8cd31e2f9c4b34439ce055b Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Fri, 13 Oct 2023 17:11:55 -0500 Subject: [PATCH] fix: fix in ape test and subprocess --- src/ape/api/providers.py | 5 +++++ src/ape_geth/provider.py | 24 ++++++++++-------------- src/ape_test/provider.py | 15 +++++++++++---- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/ape/api/providers.py b/src/ape/api/providers.py index ca34225855..988d4c4af2 100644 --- a/src/ape/api/providers.py +++ b/src/ape/api/providers.py @@ -1744,6 +1744,11 @@ def _stdout_logger(self) -> Logger: def _stderr_logger(self) -> Logger: return self._get_process_output_logger("stderr", self.stderr_logs_path) + @property + def connection_id(self) -> Optional[str]: + cmd_id = ",".join(self.build_command()) + return f"{self.network_choice}:-{cmd_id}" + def _get_process_output_logger(self, name: str, path: Path): logger = getLogger(f"{self.name}_{name}_subprocessProviderLogger") path.parent.mkdir(parents=True, exist_ok=True) diff --git a/src/ape_geth/provider.py b/src/ape_geth/provider.py index 872a85a879..8c371ac59d 100644 --- a/src/ape_geth/provider.py +++ b/src/ape_geth/provider.py @@ -7,7 +7,7 @@ from itertools import tee from pathlib import Path from subprocess import DEVNULL, PIPE, Popen -from typing import Any, Dict, Iterator, List, Optional, Tuple, Union, cast +from typing import Any, Dict, Iterator, List, Optional, Tuple, Union import ijson # type: ignore import requests @@ -267,7 +267,7 @@ def uri(self) -> str: # Use adhoc, scripted value return self.provider_settings["uri"] - config = self.config.dict().get(self.network.ecosystem.name, None) + config = self.settings.dict().get(self.network.ecosystem.name, None) if config is None: return DEFAULT_SETTINGS["uri"] @@ -275,10 +275,6 @@ def uri(self) -> str: network_config = config.get(self.network.name) or DEFAULT_SETTINGS return network_config.get("uri", DEFAULT_SETTINGS["uri"]) - @property - def geth_config(self) -> GethConfig: - return cast(GethConfig, self.config_manager.get_config("geth")) - @property def _clean_uri(self) -> str: url = URL(self.uri).with_user(None).with_password(None) @@ -288,12 +284,12 @@ def _clean_uri(self) -> str: @property def ipc_path(self) -> Path: - return self.geth_config.ipc_path or self.data_dir / "geth.ipc" + return self.settings.ipc_path or self.data_dir / "geth.ipc" @property def data_dir(self) -> Path: - if self.geth_config.data_dir: - return self.geth_config.data_dir.expanduser() + if self.settings.data_dir: + return self.settings.data_dir.expanduser() return _get_default_data_dir() @@ -481,12 +477,12 @@ def process_name(self) -> str: @property def chain_id(self) -> int: - return self.geth_config.ethereum.local.get("chain_id", DEFAULT_TEST_CHAIN_ID) + return self.settings.ethereum.local.get("chain_id", DEFAULT_TEST_CHAIN_ID) @property def data_dir(self) -> Path: # Overridden from BaseGeth class for placing debug logs in ape data folder. - return self.geth_config.data_dir or self.data_folder / self.name + return self.settings.data_dir or self.data_folder / self.name def __repr__(self): try: @@ -505,8 +501,8 @@ def start(self, timeout: int = 20): test_config = self.config_manager.get_config("test").dict() # Allow configuring a custom executable besides your $PATH geth. - if self.geth_config.executable is not None: - test_config["executable"] = self.geth_config.executable + if self.settings.executable is not None: + test_config["executable"] = self.settings.executable test_config["ipc_path"] = self.ipc_path test_config["auto_disconnect"] = self._test_runner is None or test_config.get( @@ -514,7 +510,7 @@ def start(self, timeout: int = 20): ) # Include extra accounts to allocated funds to at genesis. - extra_accounts = self.geth_config.ethereum.local.get("extra_funded_accounts", []) + extra_accounts = self.settings.ethereum.local.get("extra_funded_accounts", []) extra_accounts.extend(self.provider_settings.get("extra_funded_accounts", [])) extra_accounts = list(set([HexBytes(a).hex().lower() for a in extra_accounts])) test_config["extra_funded_accounts"] = extra_accounts diff --git a/src/ape_test/provider.py b/src/ape_test/provider.py index 3cbb5e7db1..655321516a 100644 --- a/src/ape_test/provider.py +++ b/src/ape_test/provider.py @@ -45,7 +45,7 @@ def evm_backend(self) -> PyEVMBackend: return self._evm_backend def connect(self): - chain_id = self.provider_settings.get("chain_id", self.config.provider.chain_id) + chain_id = self.settings.chain_id if self._web3 is not None: connected_chain_id = self.chain_id if connected_chain_id == chain_id: @@ -53,8 +53,8 @@ def connect(self): return self._evm_backend = PyEVMBackend.from_mnemonic( - mnemonic=self.config["mnemonic"], - num_accounts=self.config["number_of_accounts"], + mnemonic=self.config.mnemonic, + num_accounts=self.config.number_of_accounts, ) endpoints = {**API_ENDPOINTS} endpoints["eth"]["chainId"] = static_return(chain_id) @@ -108,6 +108,13 @@ def estimate_gas_cost(self, txn: TransactionAPI, **kwargs) -> int: message, base_err=ape_err, txn=txn, source_traceback=ape_err.source_traceback ) from ape_err + @property + def settings(self) -> EthTesterProviderConfig: + self.config.provider = EthTesterProviderConfig.parse_obj( + {**self.config.provider.dict(), **self.provider_settings} + ) + return self.config.provider + @property def chain_id(self) -> int: if self.cached_chain_id: @@ -116,7 +123,7 @@ def chain_id(self) -> int: try: result = self._make_request("eth_chainId", []) except ProviderNotConnectedError: - result = self.provider_settings.get("chain_id", self.config.provider.chain_id) + result = self.settings.chain_id self.cached_chain_id = result return result