Skip to content

Commit 70f3b47

Browse files
vvillait88claude
andcommitted
feat: add is_agentscore_test_address + AGENTSCORE_TEST_ADDRESSES
Python parity with the test-mode helper currently shipping in @agent-score/pay and @agent-score/mcp. Recognizes the seven reserved AgentScore EVM test fixtures (0x0000…0001 through 0x0000…0007) so dev/test interactions can be labeled distinctly without burning real KYC credits. Lives in agentscore.test_mode and is re-exported from the package root. 6 new tests, coverage holds at 97.35%. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 51617ae commit 70f3b47

3 files changed

Lines changed: 76 additions & 0 deletions

File tree

agentscore/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from agentscore.client import AgentScore
44
from agentscore.errors import AgentScoreError
5+
from agentscore.test_mode import AGENTSCORE_TEST_ADDRESSES, is_agentscore_test_address
56
from agentscore.types import (
67
AccountVerification,
78
AgentMemoryHint,
@@ -35,6 +36,7 @@
3536
__version__ = _pkg_version("agentscore-py")
3637

3738
__all__ = [
39+
"AGENTSCORE_TEST_ADDRESSES",
3840
"AccountVerification",
3941
"AgentMemoryHint",
4042
"AgentMemoryIdentityPaths",
@@ -65,5 +67,6 @@
6567
"WalletAuthRequiresSigningBody",
6668
"WalletSignerMismatchBody",
6769
"__version__",
70+
"is_agentscore_test_address",
6871
"verify_webhook_signature",
6972
]

agentscore/test_mode.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""Recognizers for AgentScore reserved test addresses.
2+
3+
AgentScore's ``/v1/assess`` endpoint recognizes seven EVM addresses
4+
(``0x0000…0001`` through ``0x0000…0007``) as test fixtures with deterministic
5+
policy outcomes — KYC verified, sanctions clear, age gates passing — so dev/test
6+
interactions don't burn real KYC credits and produce predictable results.
7+
8+
Use this in test suites and dev/staging tooling to label test-mode interactions
9+
distinctly from production traffic.
10+
"""
11+
12+
from __future__ import annotations
13+
14+
_TEST_ADDRESSES: frozenset[str] = frozenset(
15+
{
16+
"0x0000000000000000000000000000000000000001",
17+
"0x0000000000000000000000000000000000000002",
18+
"0x0000000000000000000000000000000000000003",
19+
"0x0000000000000000000000000000000000000004",
20+
"0x0000000000000000000000000000000000000005",
21+
"0x0000000000000000000000000000000000000006",
22+
"0x0000000000000000000000000000000000000007",
23+
},
24+
)
25+
26+
AGENTSCORE_TEST_ADDRESSES: tuple[str, ...] = tuple(sorted(_TEST_ADDRESSES))
27+
"""The full list of reserved test addresses, exposed for documentation, completion,
28+
and downstream test fixtures."""
29+
30+
31+
def is_agentscore_test_address(address: str | None) -> bool:
32+
"""Recognize one of the seven reserved AgentScore EVM test fixtures.
33+
34+
Lowercases for comparison so accidentally mixed-case input still matches.
35+
"""
36+
if not address:
37+
return False
38+
return address.lower() in _TEST_ADDRESSES
39+
40+
41+
__all__ = ["AGENTSCORE_TEST_ADDRESSES", "is_agentscore_test_address"]

tests/test_test_mode.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""Tests for is_agentscore_test_address + AGENTSCORE_TEST_ADDRESSES."""
2+
3+
from agentscore import AGENTSCORE_TEST_ADDRESSES, is_agentscore_test_address
4+
5+
6+
def test_returns_true_for_each_of_seven_reserved_addresses():
7+
for i in range(1, 8):
8+
addr = "0x" + "0" * 39 + str(i)
9+
assert is_agentscore_test_address(addr) is True
10+
11+
12+
def test_matches_case_insensitively():
13+
assert is_agentscore_test_address("0x0000000000000000000000000000000000000001".upper()) is True
14+
15+
16+
def test_returns_false_for_addresses_outside_reserved_range():
17+
assert is_agentscore_test_address("0x0000000000000000000000000000000000000008") is False
18+
assert is_agentscore_test_address("0xabcabcabcabcabcabcabcabcabcabcabcabcabca") is False
19+
20+
21+
def test_returns_false_for_none_and_empty():
22+
assert is_agentscore_test_address(None) is False
23+
assert is_agentscore_test_address("") is False
24+
25+
26+
def test_exports_exactly_seven_addresses():
27+
assert len(AGENTSCORE_TEST_ADDRESSES) == 7
28+
29+
30+
def test_every_exported_address_passes_recognizer():
31+
for addr in AGENTSCORE_TEST_ADDRESSES:
32+
assert is_agentscore_test_address(addr) is True

0 commit comments

Comments
 (0)