diff --git a/src/ape/api/networks.py b/src/ape/api/networks.py index 56d7644921..a3cf0d81bf 100644 --- a/src/ape/api/networks.py +++ b/src/ape/api/networks.py @@ -1,6 +1,7 @@ import copy +from abc import abstractmethod from collections.abc import Collection, Iterator, Sequence -from functools import partial +from functools import cached_property, partial from pathlib import Path from typing import TYPE_CHECKING, Any, ClassVar, Optional, Union @@ -25,19 +26,21 @@ SignatureError, ) from ape.logging import logger -from ape.types import AddressType, AutoGasLimit, ContractLog, GasLimit, RawAddress -from ape.utils import ( - DEFAULT_TRANSACTION_ACCEPTANCE_TIMEOUT, +from ape.types import AutoGasLimit, ContractLog, GasLimit +from ape.types.address import AddressType, RawAddress +from ape.utils.basemodel import ( BaseInterfaceModel, ExtraAttributesMixin, ExtraModelAttributes, ManagerAccessMixin, - RPCHeaders, - abstractmethod, - cached_property, +) +from ape.utils.misc import ( + DEFAULT_TRANSACTION_ACCEPTANCE_TIMEOUT, + LOCAL_NETWORK_NAME, log_instead_of_fail, raises_not_implemented, ) +from ape.utils.rpc import RPCHeaders from .config import PluginConfig @@ -48,9 +51,6 @@ from .transactions import ReceiptAPI, TransactionAPI -LOCAL_NETWORK_NAME = "local" - - class ProxyInfoAPI(BaseModel): """ Information about a proxy contract. @@ -1395,3 +1395,15 @@ def network_id(self) -> int: return network_id return network_def + + +# TODO: Can remove in 0.9 since `LOCAL_NETWORK_NAME` doesn't need to be here. +__all__ = [ + "create_network_type", + "EcosystemAPI", + "LOCAL_NETWORK_NAME", # Have to leave for backwards compat. + "ForkedNetworkAPI", + "NetworkAPI", + "ProviderContextManager", + "ProxyInfoAPI", +] diff --git a/src/ape/utils/misc.py b/src/ape/utils/misc.py index a068786e87..281900bf79 100644 --- a/src/ape/utils/misc.py +++ b/src/ape/utils/misc.py @@ -40,6 +40,7 @@ DEFAULT_LIVE_NETWORK_BASE_FEE_MULTIPLIER = 1.4 DEFAULT_TRANSACTION_TYPE = 0 DEFAULT_MAX_RETRIES_TX = 20 +LOCAL_NETWORK_NAME = "local" SOURCE_EXCLUDE_PATTERNS = ( ".build", ".cache", diff --git a/src/ape_cache/query.py b/src/ape_cache/query.py index a6eec04d1d..81da0fe87a 100644 --- a/src/ape_cache/query.py +++ b/src/ape_cache/query.py @@ -1,4 +1,5 @@ from collections.abc import Iterator +from functools import singledispatchmethod from pathlib import Path from typing import Any, Optional, cast @@ -7,13 +8,20 @@ from sqlalchemy.sql import column, insert, select from sqlalchemy.sql.expression import Insert, Select -from ape.api import BlockAPI, QueryAPI, QueryType, TransactionAPI -from ape.api.networks import LOCAL_NETWORK_NAME -from ape.api.query import BaseInterfaceModel, BlockQuery, BlockTransactionQuery, ContractEventQuery +from ape.api.providers import BlockAPI +from ape.api.query import ( + BaseInterfaceModel, + BlockQuery, + BlockTransactionQuery, + ContractEventQuery, + QueryAPI, + QueryType, +) +from ape.api.transactions import TransactionAPI from ape.exceptions import QueryEngineError from ape.logging import logger from ape.types import ContractLog -from ape.utils import singledispatchmethod +from ape.utils.misc import LOCAL_NETWORK_NAME from . import models from .models import Blocks, ContractEvents, Transactions diff --git a/src/ape_ethereum/__init__.py b/src/ape_ethereum/__init__.py index 41dbf86131..599936f191 100644 --- a/src/ape_ethereum/__init__.py +++ b/src/ape_ethereum/__init__.py @@ -1,6 +1,6 @@ from ape import plugins -from ape.api import ForkedNetworkAPI, NetworkAPI, create_network_type -from ape.api.networks import LOCAL_NETWORK_NAME +from ape.api.networks import ForkedNetworkAPI, NetworkAPI, create_network_type +from ape.utils.misc import LOCAL_NETWORK_NAME from ._converters import WeiConversions from .ecosystem import ( diff --git a/src/ape_ethereum/ecosystem.py b/src/ape_ethereum/ecosystem.py index bf18706f85..1176f49041 100644 --- a/src/ape_ethereum/ecosystem.py +++ b/src/ape_ethereum/ecosystem.py @@ -25,8 +25,11 @@ from pydantic import Field, computed_field, field_validator, model_validator from pydantic_settings import SettingsConfigDict -from ape.api import BlockAPI, EcosystemAPI, PluginConfig, ReceiptAPI, TraceAPI, TransactionAPI -from ape.api.networks import LOCAL_NETWORK_NAME +from ape.api.config import PluginConfig +from ape.api.networks import EcosystemAPI +from ape.api.providers import BlockAPI +from ape.api.trace import TraceAPI +from ape.api.transactions import ReceiptAPI, TransactionAPI from ape.contracts.base import ContractCall from ape.exceptions import ( ApeException, @@ -49,20 +52,18 @@ RawAddress, TransactionSignature, ) -from ape.utils import ( +from ape.utils.abi import LogInputABICollection, Struct, StructParser, is_array, returns_array +from ape.utils.basemodel import _assert_not_ipython_check, only_raise_attribute_error +from ape.utils.misc import ( DEFAULT_LIVE_NETWORK_BASE_FEE_MULTIPLIER, DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT, + DEFAULT_MAX_RETRIES_TX, DEFAULT_TRANSACTION_ACCEPTANCE_TIMEOUT, + DEFAULT_TRANSACTION_TYPE, EMPTY_BYTES32, + LOCAL_NETWORK_NAME, ZERO_ADDRESS, - LogInputABICollection, - Struct, - StructParser, - is_array, - returns_array, ) -from ape.utils.basemodel import _assert_not_ipython_check, only_raise_attribute_error -from ape.utils.misc import DEFAULT_MAX_RETRIES_TX, DEFAULT_TRANSACTION_TYPE from ape_ethereum.proxies import ( IMPLEMENTATION_ABI, MASTER_COPY_ABI, diff --git a/src/ape_node/__init__.py b/src/ape_node/__init__.py index 0fa660812d..f76e94a7c0 100644 --- a/src/ape_node/__init__.py +++ b/src/ape_node/__init__.py @@ -1,5 +1,4 @@ from ape import plugins -from ape.api.networks import LOCAL_NETWORK_NAME from .provider import EthereumNetworkConfig, EthereumNodeConfig, GethDev, Node from .query import OtterscanQueryEngine @@ -13,11 +12,11 @@ def config_class(): @plugins.register(plugins.ProviderPlugin) def providers(): networks_dict = EthereumNetworkConfig().model_dump() - networks_dict.pop(LOCAL_NETWORK_NAME) + networks_dict.pop("local") for network_name in networks_dict: yield "ethereum", network_name, Node - yield "ethereum", LOCAL_NETWORK_NAME, GethDev + yield "ethereum", "local", GethDev @plugins.register(plugins.QueryPlugin) diff --git a/src/ape_test/__init__.py b/src/ape_test/__init__.py index 71e0297c19..9a8a665338 100644 --- a/src/ape_test/__init__.py +++ b/src/ape_test/__init__.py @@ -3,8 +3,7 @@ from pydantic import NonNegativeInt, field_validator from ape import plugins -from ape.api import PluginConfig -from ape.api.networks import LOCAL_NETWORK_NAME +from ape.api.config import PluginConfig from ape.utils.basemodel import ManagerAccessMixin from ape.utils.testing import ( DEFAULT_NUMBER_OF_TEST_ACCOUNTS, @@ -178,7 +177,7 @@ def account_types(): @plugins.register(plugins.ProviderPlugin) def providers(): - yield "ethereum", LOCAL_NETWORK_NAME, LocalProvider + yield "ethereum", "local", LocalProvider __all__ = [ diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py index 580bdc807a..75528f15ee 100644 --- a/tests/functional/conftest.py +++ b/tests/functional/conftest.py @@ -12,13 +12,13 @@ from ethpm_types.abi import ABIType import ape -from ape.api.networks import LOCAL_NETWORK_NAME from ape.contracts import ContractContainer, ContractInstance from ape.contracts.base import ContractCallHandler from ape.exceptions import ChainError, ContractLogicError, ProviderError from ape.logging import LogLevel from ape.logging import logger as _logger from ape.types import AddressType, ContractLog +from ape.utils.misc import LOCAL_NETWORK_NAME from ape_ethereum.proxies import minimal_proxy as _minimal_proxy_container ALIAS_2 = "__FUNCTIONAL_TESTS_ALIAS_2__" diff --git a/tests/functional/geth/test_network_manager.py b/tests/functional/geth/test_network_manager.py index e60220b221..18d5274f6e 100644 --- a/tests/functional/geth/test_network_manager.py +++ b/tests/functional/geth/test_network_manager.py @@ -1,6 +1,6 @@ import pytest -from ape.api.networks import LOCAL_NETWORK_NAME +from ape.utils.misc import LOCAL_NETWORK_NAME from tests.conftest import geth_process_test diff --git a/tests/functional/test_ecosystem.py b/tests/functional/test_ecosystem.py index 86e78a3799..474b8d89c3 100644 --- a/tests/functional/test_ecosystem.py +++ b/tests/functional/test_ecosystem.py @@ -9,10 +9,10 @@ from ethpm_types.abi import ABIType, EventABI, MethodABI from evm_trace import CallTreeNode, CallType -from ape.api.networks import LOCAL_NETWORK_NAME, ForkedNetworkAPI, NetworkAPI +from ape.api.networks import ForkedNetworkAPI, NetworkAPI from ape.exceptions import CustomError, DecodingError, NetworkError, NetworkNotFoundError from ape.types import AddressType, CurrencyValueComparable -from ape.utils import DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT +from ape.utils.misc import DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT, LOCAL_NETWORK_NAME from ape_ethereum import TransactionTrace from ape_ethereum.ecosystem import BLUEPRINT_HEADER, BaseEthereumConfig, Block, Ethereum from ape_ethereum.transactions import ( diff --git a/tests/functional/test_exceptions.py b/tests/functional/test_exceptions.py index cda512b95f..907c072ca4 100644 --- a/tests/functional/test_exceptions.py +++ b/tests/functional/test_exceptions.py @@ -4,8 +4,7 @@ import pytest -from ape.api import ReceiptAPI -from ape.api.networks import LOCAL_NETWORK_NAME +from ape.api.transactions import ReceiptAPI from ape.exceptions import ( Abort, ContractLogicError, @@ -15,7 +14,7 @@ handle_ape_exception, ) from ape.types import SourceTraceback -from ape.utils import ZERO_ADDRESS +from ape.utils.misc import LOCAL_NETWORK_NAME, ZERO_ADDRESS from ape_ethereum.transactions import DynamicFeeTransaction, Receipt diff --git a/tests/functional/test_network_manager.py b/tests/functional/test_network_manager.py index daf5215e7b..73b1acd86f 100644 --- a/tests/functional/test_network_manager.py +++ b/tests/functional/test_network_manager.py @@ -4,10 +4,10 @@ import pytest import ape -from ape.api import EcosystemAPI -from ape.api.networks import LOCAL_NETWORK_NAME +from ape.api.networks import EcosystemAPI from ape.exceptions import NetworkError, ProviderNotFoundError -from ape.utils import DEFAULT_TEST_CHAIN_ID +from ape.utils.misc import LOCAL_NETWORK_NAME +from ape.utils.testing import DEFAULT_TEST_CHAIN_ID class NewChainID: diff --git a/tests/integration/cli/test_networks.py b/tests/integration/cli/test_networks.py index b9578dd6e2..c300c80307 100644 --- a/tests/integration/cli/test_networks.py +++ b/tests/integration/cli/test_networks.py @@ -1,6 +1,6 @@ import pytest -from ape.api.networks import LOCAL_NETWORK_NAME +from ape.utils.misc import LOCAL_NETWORK_NAME from tests.conftest import ApeSubprocessRunner, geth_process_test from .utils import run_once, skip_projects_except