diff --git a/src/ape/api/networks.py b/src/ape/api/networks.py index b372de6cde..c37386ffd4 100644 --- a/src/ape/api/networks.py +++ b/src/ape/api/networks.py @@ -817,6 +817,27 @@ def explorer(self) -> Optional["ExplorerAPI"]: return None # May not have an block explorer + @property + def is_fork(self) -> bool: + """ + True when using a forked network. + """ + return self.name.endswith("-fork") + + @property + def is_local(self) -> bool: + """ + True when using the local network. + """ + return self.name == LOCAL_NETWORK_NAME + + @property + def is_dev(self) -> bool: + """ + True when using a local network, including forks. + """ + return self.is_local or self.is_fork + @cached_property def providers(self): # -> Dict[str, Partial[ProviderAPI]] """ diff --git a/src/ape/api/providers.py b/src/ape/api/providers.py index 8ab58adb86..cb7fe5bfac 100644 --- a/src/ape/api/providers.py +++ b/src/ape/api/providers.py @@ -496,7 +496,7 @@ def send_private_transaction(self, txn: TransactionAPI, **kwargs) -> ReceiptAPI: Returns: :class:`~ape.api.transactions.ReceiptAPI` """ - if self.network.name == LOCAL_NETWORK_NAME or self.network.name.endswith("-fork"): + if self.network.is_dev: # Send the transaction as normal so testers can verify private=True # and the txn still goes through. logger.warning( @@ -944,10 +944,14 @@ def estimate_gas_cost(self, txn: TransactionAPI, **kwargs) -> int: @cached_property def chain_id(self) -> int: default_chain_id = None - if self.network.name not in ( - "adhoc", - LOCAL_NETWORK_NAME, - ) and not self.network.name.endswith("-fork"): + if ( + self.network.name + not in ( + "adhoc", + LOCAL_NETWORK_NAME, + ) + and not self.network.is_fork + ): # If using a live network, the chain ID is hardcoded. default_chain_id = self.network.chain_id diff --git a/src/ape/managers/chain.py b/src/ape/managers/chain.py index f46dea2726..42fcaad0d2 100644 --- a/src/ape/managers/chain.py +++ b/src/ape/managers/chain.py @@ -13,7 +13,7 @@ from ape.api import BlockAPI, ReceiptAPI from ape.api.address import BaseAddress -from ape.api.networks import LOCAL_NETWORK_NAME, NetworkAPI, ProxyInfoAPI +from ape.api.networks import NetworkAPI, ProxyInfoAPI from ape.api.query import ( AccountTransactionQuery, BlockQuery, @@ -271,14 +271,9 @@ def poll_blocks( Returns: Iterator[:class:`~ape.api.providers.BlockAPI`] """ - network_name = self.provider.network.name block_time = self.provider.network.block_time timeout = ( - ( - 10.0 - if network_name == LOCAL_NETWORK_NAME or network_name.endswith("-fork") - else 50 * block_time - ) + (10.0 if self.provider.network.is_dev else 50 * block_time) if new_block_timeout is None else new_block_timeout ) @@ -316,10 +311,7 @@ def _try_timeout(): if time.time() - time_since_last > timeout: time_waited = round(time.time() - time_since_last, 4) message = f"Timed out waiting for new block (time_waited={time_waited})." - if ( - self.provider.network.name == LOCAL_NETWORK_NAME - or self.provider.network.name.endswith("-fork") - ): + if self.provider.network.is_dev: message += ( " If using a local network, try configuring mining to mine on an interval " "or adjusting the block time." @@ -735,7 +727,7 @@ def _is_live_network(self) -> bool: if not self.network_manager.active_provider: return False - return self._network.name != LOCAL_NETWORK_NAME and not self._network.name.endswith("-fork") + return not self._network.is_dev @property def _data_network_name(self) -> str: @@ -1103,7 +1095,7 @@ def get( return contract_type - if self._network.name == LOCAL_NETWORK_NAME: + if self._network.is_local: # Don't check disk-cache or explorer when using local if default: self._local_contract_types[address_key] = default diff --git a/src/ape/managers/project/manager.py b/src/ape/managers/project/manager.py index 31a3dc4725..e79a0e72ea 100644 --- a/src/ape/managers/project/manager.py +++ b/src/ape/managers/project/manager.py @@ -10,7 +10,6 @@ from ethpm_types.utils import AnyUrl, Hex from ape.api import DependencyAPI, ProjectAPI -from ape.api.networks import LOCAL_NETWORK_NAME from ape.contracts import ContractContainer, ContractInstance, ContractNamespace from ape.exceptions import ApeAttributeError, APINotImplementedError, ChainError, ProjectError from ape.logging import logger @@ -698,8 +697,7 @@ def track_deployment(self, contract: ContractInstance): to track as a deployment of the project. """ - network = self.provider.network.name - if network == LOCAL_NETWORK_NAME or network.endswith("-fork"): + if self.provider.network.is_dev: raise ProjectError("Can only publish deployments on a live network.") if not (contract_name := contract.contract_type.name): diff --git a/src/ape_cache/query.py b/src/ape_cache/query.py index 8cca70eee1..59d11d8b7c 100644 --- a/src/ape_cache/query.py +++ b/src/ape_cache/query.py @@ -117,7 +117,7 @@ def database_connection(self): Returns: Optional[`sqlalchemy.engine.Connection`] """ - if self.provider.network.name == LOCAL_NETWORK_NAME: + if self.provider.network.is_local: return None if not self.network_manager.active_provider: