Skip to content

Commit

Permalink
fix: use new Fork APIs [APE-1509] (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Nov 3, 2023
1 parent 4df8296 commit 6a81c7b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -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]
Expand Down
5 changes: 2 additions & 3 deletions ape_fantom/__init__.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
25 changes: 12 additions & 13 deletions ape_fantom/ecosystem.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6a81c7b

Please sign in to comment.