diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e15dfcf..023c2fc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,18 +10,18 @@ repos: - id: isort - repo: https://github.com/psf/black - rev: 23.12.0 + rev: 23.12.1 hooks: - id: black name: black - repo: https://github.com/pycqa/flake8 - rev: 6.1.0 + rev: 7.0.0 hooks: - id: flake8 - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.7.1 + rev: v1.8.0 hooks: - id: mypy additional_dependencies: [types-setuptools, pydantic] diff --git a/ape_polygon/ecosystem.py b/ape_polygon/ecosystem.py index 522c973..a371f1c 100644 --- a/ape_polygon/ecosystem.py +++ b/ape_polygon/ecosystem.py @@ -1,9 +1,11 @@ -from typing import Type, cast +from typing import ClassVar, Dict, Tuple, 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, ForkedNetworkConfig, NetworkConfig +from ape_ethereum.ecosystem import ( + BaseEthereumConfig, + Ethereum, + NetworkConfig, + create_network_config, +) NETWORKS = { # chain_id, network_id @@ -12,34 +14,10 @@ } -def _create_config( - required_confirmations: int = 1, - block_time: int = 2, - cls: Type[NetworkConfig] = NetworkConfig, - **kwargs, -) -> NetworkConfig: - return cls(required_confirmations=required_confirmations, block_time=block_time, **kwargs) - - -def _create_local_config(**kwargs): - return _create_config( - block_time=0, - default_provider=kwargs.pop("default_provider", None), - gas_limit="max", - required_confirmations=0, - transaction_acceptance_timeout=DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT, - cls=ForkedNetworkConfig if kwargs.pop("use_fork", False) else NetworkConfig, - **kwargs, - ) - - -class PolygonConfig(PluginConfig): - mainnet: NetworkConfig = _create_config() - mainnet_fork: ForkedNetworkConfig = _create_local_config(use_fork=True) - mumbai: NetworkConfig = _create_config() - mumbai_fork: ForkedNetworkConfig = _create_local_config(use_fork=True) - local: NetworkConfig = _create_local_config(default_provider="test") - default_network: str = LOCAL_NETWORK_NAME +class PolygonConfig(BaseEthereumConfig): + NETWORKS: ClassVar[Dict[str, Tuple[int, int]]] = NETWORKS + mainnet: NetworkConfig = create_network_config(block_time=2, required_confirmations=1) + mumbai: NetworkConfig = create_network_config(block_time=2, required_confirmations=1) class Polygon(Ethereum): diff --git a/setup.py b/setup.py index 3716e51..9945052 100644 --- a/setup.py +++ b/setup.py @@ -10,10 +10,10 @@ "hypothesis>=6.2.0,<7", # Strategy-based fuzzer ], "lint": [ - "black>=23.12.0,<24", # Auto-formatter and linter - "mypy>=1.7.1,<2", # Static type analyzer + "black>=23.12.1,<24", # Auto-formatter and linter + "mypy>=1.8.0,<2", # Static type analyzer "types-setuptools", # Needed for mypy type shed - "flake8>=6.1.0,<7", # Style linter + "flake8>=7.0.0,<8", # Style linter "flake8-breakpoint>=1.1.0,<2", # Detect breakpoints left in code "flake8-print>=5.0.0,<6", # Detect print statements left in code "isort>=5.10.1,<6", # Import sorting linter @@ -60,7 +60,7 @@ url="https://github.com/ApeWorX/ape-polygon", include_package_data=True, install_requires=[ - "eth-ape>=0.7.0,<0.8", + "eth-ape>=0.7.6,<0.8", "ethpm-types", # Use same version as eth-ape ], python_requires=">=3.8,<4", diff --git a/tests/conftest.py b/tests/conftest.py index 95f080d..381d964 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,7 +17,7 @@ def polygon(networks): return networks.polygon -@pytest.fixture +@pytest.fixture(autouse=True) def eth_tester_provider(): if not ape.networks.active_provider or ape.networks.provider.name != "test": with ape.networks.polygon.local.use_provider("test") as provider: diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 0000000..7c4dd08 --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,28 @@ +from ape_ethereum.transactions import TransactionType + +from ape_polygon.ecosystem import PolygonConfig + + +def test_gas_limit(polygon): + assert polygon.config.local.gas_limit == "max" + + +def test_default_transaction_type(polygon): + assert polygon.config.mainnet.default_transaction_type == TransactionType.DYNAMIC + + +def test_mainnet_fork_not_configured(): + obj = PolygonConfig.model_validate({}) + assert obj.mainnet_fork.required_confirmations == 0 + + +def test_mainnet_fork_configured(): + data = {"mainnet_fork": {"required_confirmations": 555}} + obj = PolygonConfig.model_validate(data) + assert obj.mainnet_fork.required_confirmations == 555 + + +def test_custom_network(): + data = {"apenet": {"required_confirmations": 333}} + obj = PolygonConfig.model_validate(data) + assert obj.apenet.required_confirmations == 333 diff --git a/tests/test_ecosystem.py b/tests/test_ecosystem.py index 1500ad0..aa6106a 100644 --- a/tests/test_ecosystem.py +++ b/tests/test_ecosystem.py @@ -3,16 +3,39 @@ from ethpm_types.abi import MethodABI -def test_gas_limit(polygon): - assert polygon.config.local.gas_limit == "max" +@pytest.mark.parametrize( + "tx_kwargs", + [ + {"type": 0}, + {"gas_price": 0}, + {"gasPrice": 0}, + ], +) +def test_create_transaction_type_0(polygon, tx_kwargs): + txn = polygon.create_transaction(**tx_kwargs) + assert txn.type == TransactionType.STATIC.value + +@pytest.mark.parametrize( + "tx_kwargs", + [ + {}, # Default is type 2 in Polygon. + {"type": 2}, + {"max_fee": 0}, + {"max_fee_per_gas": 0}, + {"maxFee": 0}, + {"max_priority_fee_per_gas": 0}, + {"max_priority_fee": 0}, + {"maxPriorityFeePerGas": 0}, + ], +) +def test_create_transaction_type_2(polygon, tx_kwargs): + """ + Show is smart-enough to deduce type 2 transactions. + """ -# NOTE: None because we want to show the default is DYNAMIC -@pytest.mark.parametrize("tx_type", (None, 2, "0x2")) -def test_create_transaction(polygon, tx_type, eth_tester_provider): - tx = polygon.create_transaction(type=tx_type) - assert tx.type == TransactionType.DYNAMIC.value - assert tx.gas_limit == eth_tester_provider.max_gas + txn = polygon.create_transaction(**tx_kwargs) + assert txn.type == TransactionType.DYNAMIC.value @pytest.mark.parametrize(