Skip to content

Commit

Permalink
Merge branch 'main' into perf/manager-injections
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Oct 23, 2024
2 parents 8c55809 + 2ef3892 commit 9b3c6bf
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 43 deletions.
32 changes: 22 additions & 10 deletions src/ape/api/networks.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand All @@ -48,9 +51,6 @@
from .transactions import ReceiptAPI, TransactionAPI


LOCAL_NETWORK_NAME = "local"


class ProxyInfoAPI(BaseModel):
"""
Information about a proxy contract.
Expand Down Expand Up @@ -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",
]
1 change: 1 addition & 0 deletions src/ape/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 12 additions & 4 deletions src/ape_cache/query.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections.abc import Iterator
from functools import singledispatchmethod
from pathlib import Path
from typing import Any, Optional, cast

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/ape_ethereum/__init__.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
21 changes: 11 additions & 10 deletions src/ape_ethereum/ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions src/ape_node/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions src/ape_test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -178,7 +177,7 @@ def account_types():

@plugins.register(plugins.ProviderPlugin)
def providers():
yield "ethereum", LOCAL_NETWORK_NAME, LocalProvider
yield "ethereum", "local", LocalProvider


__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__"
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/geth/test_network_manager.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
4 changes: 2 additions & 2 deletions tests/functional/test_ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
5 changes: 2 additions & 3 deletions tests/functional/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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


Expand Down
6 changes: 3 additions & 3 deletions tests/functional/test_network_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cli/test_networks.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 9b3c6bf

Please sign in to comment.