remove obsolete test script and add comprehensive validation tests for bootstrap addresses

This commit is contained in:
sumanjeet0012@gmail.com
2025-06-30 23:12:48 +05:30
parent ec20ca81dd
commit 69a2cb00ba
3 changed files with 35 additions and 96 deletions

View File

@ -0,0 +1,35 @@
#!/usr/bin/env python3
"""
Test bootstrap address validation
"""
import pytest
from libp2p.discovery.bootstrap.utils import (
parse_bootstrap_peer_info,
validate_bootstrap_addresses,
)
def test_validate_addresses():
"""Test validation with a mix of valid and invalid addresses in one list."""
addresses = [
# Valid
"/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SznbYGzPwp8qDrq",
"/ip4/104.236.179.241/tcp/4001/p2p/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
# Invalid
"invalid-address",
"/ip4/192.168.1.1/tcp/4001", # Missing p2p part
"", # Empty
"/ip4/127.0.0.1/tcp/4001/p2p/InvalidPeerID", # Bad peer ID
]
valid_expected = [
"/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SznbYGzPwp8qDrq",
"/ip4/104.236.179.241/tcp/4001/p2p/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
]
validated = validate_bootstrap_addresses(addresses)
assert validated == valid_expected, f"Expected only valid addresses, got: {validated}"
for addr in addresses:
peer_info = parse_bootstrap_peer_info(addr)
if addr in valid_expected:
assert peer_info is not None and peer_info.peer_id is not None, f"Should parse valid address: {addr}"
else:
assert peer_info is None, f"Should not parse invalid address: {addr}"