From 6a81c7b9757183af0663c36575904b76fa5bb75e Mon Sep 17 00:00:00 2001 From: antazoey Date: Fri, 3 Nov 2023 15:00:43 -0500 Subject: [PATCH] fix: use new Fork APIs [APE-1509] (#22) --- .pre-commit-config.yaml | 6 +++--- ape_fantom/__init__.py | 5 ++--- ape_fantom/ecosystem.py | 25 ++++++++++++------------- setup.py | 4 ++-- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9cc7305..b82e384 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-yaml @@ -10,7 +10,7 @@ repos: - id: isort - repo: https://github.com/psf/black - rev: 23.9.1 + rev: 23.10.1 hooks: - id: black name: black @@ -21,7 +21,7 @@ repos: - id: flake8 - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.5.1 + rev: v1.6.1 hooks: - id: mypy additional_dependencies: [types-setuptools, pydantic] diff --git a/ape_fantom/__init__.py b/ape_fantom/__init__.py index 045912c..a8a4a47 100644 --- a/ape_fantom/__init__.py +++ b/ape_fantom/__init__.py @@ -1,6 +1,5 @@ from ape import plugins -from ape.api import NetworkAPI, create_network_type -from ape.api.networks import LOCAL_NETWORK_NAME +from ape.api.networks import LOCAL_NETWORK_NAME, ForkedNetworkAPI, NetworkAPI, create_network_type from ape_geth import GethProvider from ape_test import LocalProvider @@ -21,7 +20,7 @@ def ecosystems(): def networks(): for network_name, network_params in NETWORKS.items(): yield "fantom", network_name, create_network_type(*network_params) - yield "fantom", f"{network_name}-fork", NetworkAPI + yield "fantom", f"{network_name}-fork", ForkedNetworkAPI # NOTE: This works for development providers, as they get chain_id from themselves yield "fantom", LOCAL_NETWORK_NAME, NetworkAPI diff --git a/ape_fantom/ecosystem.py b/ape_fantom/ecosystem.py index 11f1aa1..f3d1a20 100644 --- a/ape_fantom/ecosystem.py +++ b/ape_fantom/ecosystem.py @@ -1,9 +1,9 @@ -from typing import Optional, cast +from typing import Optional, Type, cast from ape.api.config import PluginConfig from ape.api.networks import LOCAL_NETWORK_NAME from ape.utils import DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT -from ape_ethereum.ecosystem import Ethereum, NetworkConfig +from ape_ethereum.ecosystem import Ethereum, ForkedNetworkConfig, NetworkConfig NETWORKS = { # chain_id, network_id @@ -12,30 +12,29 @@ } -def _create_network_config( - required_confirmations: int = 1, block_time: int = 1, **kwargs +def _create_config( + required_confirmations: int = 1, block_time: int = 1, cls: Type = NetworkConfig, **kwargs ) -> NetworkConfig: - return NetworkConfig( - required_confirmations=required_confirmations, block_time=block_time, **kwargs - ) + return cls(required_confirmations=required_confirmations, block_time=block_time, **kwargs) -def _create_local_config(default_provider: Optional[str] = None, **kwargs) -> NetworkConfig: - return _create_network_config( +def _create_local_config(default_provider: Optional[str] = None, use_fork: bool = False, **kwargs): + return _create_config( block_time=0, default_provider=default_provider, gas_limit="max", required_confirmations=0, transaction_acceptance_timeout=DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT, + cls=ForkedNetworkConfig if use_fork else NetworkConfig, **kwargs, ) class FantomConfig(PluginConfig): - opera: NetworkConfig = _create_network_config() - opera_fork: NetworkConfig = _create_local_config() - testnet: NetworkConfig = _create_network_config() - testnet_fork: NetworkConfig = _create_local_config() + opera: NetworkConfig = _create_config() + opera_fork: ForkedNetworkConfig = _create_local_config(use_fork=True) + testnet: NetworkConfig = _create_config() + testnet_fork: ForkedNetworkConfig = _create_local_config(use_fork=True) local: NetworkConfig = _create_local_config(default_provider="test") default_network: str = LOCAL_NETWORK_NAME diff --git a/setup.py b/setup.py index 673c70a..9b9086c 100644 --- a/setup.py +++ b/setup.py @@ -10,8 +10,8 @@ "hypothesis>=6.2.0,<7", # Strategy-based fuzzer ], "lint": [ - "black>=23.9.1,<24", # auto-formatter and linter - "mypy>=1.5.1,<2", # Static type analyzer + "black>=23.10.1,<24", # auto-formatter and linter + "mypy>=1.6.1,<2", # Static type analyzer "flake8>=6.1.0,<7", # Style linter "isort>=5.10.1,<6", # Import sorting linter "types-setuptools", # Needed due to mypy typeshed