From 9988fe00a9648bb90ffd9a48224229bc950c666e Mon Sep 17 00:00:00 2001 From: abrahamojes Date: Sat, 17 Jan 2026 19:22:51 +0100 Subject: [PATCH] feat: Add Polygon Amoy network support - Add polygon-amoy to SupportedNetworks literal - Add polygon-amoy chain ID (80002) to network mappings - Add USDC token configuration for Polygon Amoy - Add comprehensive tests for Polygon Amoy support Fixes #670 --- python/x402/src/x402/chains.py | 10 ++++++ python/x402/src/x402/networks.py | 3 +- python/x402/tests/test_polygon_amoy.py | 48 ++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 python/x402/tests/test_polygon_amoy.py diff --git a/python/x402/src/x402/chains.py b/python/x402/src/x402/chains.py index 5b82439fc..b1ce904cd 100644 --- a/python/x402/src/x402/chains.py +++ b/python/x402/src/x402/chains.py @@ -3,6 +3,7 @@ "base": "8453", "avalanche-fuji": "43113", "avalanche": "43114", + "polygon-amoy": "80002", } @@ -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", + } + ], } diff --git a/python/x402/src/x402/networks.py b/python/x402/src/x402/networks.py index d4ed5d52a..75e0824f7 100644 --- a/python/x402/src/x402/networks.py +++ b/python/x402/src/x402/networks.py @@ -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, } diff --git a/python/x402/tests/test_polygon_amoy.py b/python/x402/tests/test_polygon_amoy.py new file mode 100644 index 000000000..7419b5f58 --- /dev/null +++ b/python/x402/tests/test_polygon_amoy.py @@ -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"