Skip to content

Commit

Permalink
feat: support polygonzkevm
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Jul 3, 2024
1 parent 986fe61 commit 5b845a8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ repos:
name: black

- repo: https://github.com/pycqa/flake8
rev: 7.0.0
rev: 7.1.0
hooks:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
rev: v1.10.1
hooks:
- id: mypy
additional_dependencies: [types-PyYAML, types-requests, pydantic, types-setuptools]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The `ape-alchemy` plugin supports the following ecosystems:
- Base
- Optimism
- Polygon
- Polygon-ZkEVM

## Dependencies

Expand Down
4 changes: 4 additions & 0 deletions ape_alchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
"mainnet",
"amoy",
],
"polygon-zkevm": [
"mainnet",
"cardona",
],
}


Expand Down
7 changes: 6 additions & 1 deletion ape_alchemy/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
# Alchemy will try to publish private transactions for 25 blocks.
PRIVATE_TX_BLOCK_WAIT = 25

NETWORKS_SUPPORTING_WEBSOCKETS = ("ethereum", "arbitrum", "base", "optimism", "polygon")


class Alchemy(Web3Provider, UpstreamProvider):
"""
Expand All @@ -46,7 +48,9 @@ def uri(self):

key = None

expected_env_var_prefix = f"WEB3_{ecosystem_name.upper()}_{network_name.upper()}_ALCHEMY"
ecosystem_nm_part = ecosystem_name.upper().replace("-", "_")
network_nm_part = network_name.upper().replace("-", "_")
expected_env_var_prefix = f"WEB3_{ecosystem_nm_part}_{network_nm_part}_ALCHEMY"
options = (
*DEFAULT_ENVIRONMENT_VARIABLE_NAMES,
f"{expected_env_var_prefix}_PROJECT_ID",
Expand All @@ -68,6 +72,7 @@ def uri(self):
"base": "https://base-{0}.g.alchemy.com/v2/{1}",
"optimism": "https://opt-{0}.g.alchemy.com/v2/{1}",
"polygon": "https://polygon-{0}.g.alchemy.com/v2/{1}",
"polygon-zkevm": "https://polygonzkevm-{0}.g.alchemy.com/v2/{1}",
}

network_format = network_formats_by_ecosystem[ecosystem_name]
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"ape-base", # Needed for testing Base integration
"ape-optimism", # Needed for testing Optimism integration
"ape-polygon", # Needed for testing Polygon integration
"ape-polygon-zkevm", # Needed for testing Polygon-ZkEVM integration
"pytest>=6.0", # Core testing package
"pytest-xdist", # Multi-process runner
"pytest-cov", # Coverage analyzer plugin
Expand All @@ -17,10 +18,10 @@
],
"lint": [
"black>=24.4.2,<25", # Auto-formatter and linter
"mypy>=1.10.0,<2", # Static type analyzer
"mypy>=1.10.1,<2", # Static type analyzer
"types-setuptools", # Needed for mypy type shed
"types-requests", # Needed for mypy type shed
"flake8>=7.0.0,<8", # Style linter
"flake8>=7.1.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.13.2,<6", # Import sorting linter
Expand Down
6 changes: 5 additions & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ape.utils import ZERO_ADDRESS

from ape_alchemy import NETWORKS
from ape_alchemy.provider import Alchemy
from ape_alchemy.provider import Alchemy, NETWORKS_SUPPORTING_WEBSOCKETS


@pytest.fixture(params=[(name, net) for name, values in NETWORKS.items() for net in values])
Expand All @@ -23,6 +23,10 @@ def test_http(provider):


def test_ws(provider):
if provider.network.ecosystem.name not in NETWORKS_SUPPORTING_WEBSOCKETS:
# Test will fail. Network does not support ws clients.
return

assert provider.ws_uri.startswith("wss")

try:
Expand Down

0 comments on commit 5b845a8

Please sign in to comment.