Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions python/x402/src/x402/chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"base": "8453",
"avalanche-fuji": "43113",
"avalanche": "43114",
"polygon-amoy": "80002",
}


Expand Down Expand Up @@ -57,6 +58,15 @@ def get_chain_id(network: str) -> str:
"version": "2",
}
],
"80002": [
{
"human_name": "usdc",
"address": "0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582",
"name": "USDC",
"decimals": 6,
"version": "2",
}
],
}


Expand Down
3 changes: 2 additions & 1 deletion python/x402/src/x402/networks.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import Literal


SupportedNetworks = Literal["base", "base-sepolia", "avalanche-fuji", "avalanche"]
SupportedNetworks = Literal["base", "base-sepolia", "avalanche-fuji", "avalanche", "polygon-amoy"]

EVM_NETWORK_TO_CHAIN_ID = {
"base-sepolia": 84532,
"base": 8453,
"avalanche-fuji": 43113,
"avalanche": 43114,
"polygon-amoy": 80002,
}
48 changes: 48 additions & 0 deletions python/x402/tests/test_polygon_amoy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Test Polygon Amoy network support"""

import pytest
from x402.networks import SupportedNetworks, EVM_NETWORK_TO_CHAIN_ID
from x402.chains import NETWORK_TO_ID, KNOWN_TOKENS, get_chain_id, get_default_token_address


def test_polygon_amoy_supported_network():
"""Test that polygon-amoy is in SupportedNetworks"""
assert "polygon-amoy" in SupportedNetworks.__args__


def test_polygon_amoy_chain_id_mapping():
"""Test that polygon-amoy maps to correct chain ID"""
assert EVM_NETWORK_TO_CHAIN_ID["polygon-amoy"] == 80002
assert NETWORK_TO_ID["polygon-amoy"] == "80002"


def test_polygon_amoy_known_tokens():
"""Test that USDC token is configured for Polygon Amoy"""
assert "80002" in KNOWN_TOKENS
usdc_tokens = KNOWN_TOKENS["80002"]
assert len(usdc_tokens) == 1

usdc_token = usdc_tokens[0]
assert usdc_token["human_name"] == "usdc"
assert usdc_token["address"] == "0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582"
assert usdc_token["name"] == "USDC"
assert usdc_token["decimals"] == 6
assert usdc_token["version"] == "2"


def test_get_chain_id_polygon_amoy():
"""Test get_chain_id function works with polygon-amoy"""
chain_id = get_chain_id("polygon-amoy")
assert chain_id == "80002"


def test_get_default_token_address_polygon_amoy():
"""Test get_default_token_address works for Polygon Amoy"""
usdc_address = get_default_token_address("80002", "usdc")
assert usdc_address == "0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582"


def test_get_chain_id_direct_chain_id():
"""Test that direct chain ID still works"""
chain_id = get_chain_id("80002")
assert chain_id == "80002"