Skip to content

Commit 69a2cb0

Browse files
committed
remove obsolete test script and add comprehensive validation tests for bootstrap addresses
1 parent ec20ca8 commit 69a2cb0

File tree

3 files changed

+35
-96
lines changed

3 files changed

+35
-96
lines changed

tests/discovery/bootstrap/test_bootstrap_script.py

Lines changed: 0 additions & 70 deletions
This file was deleted.

tests/discovery/bootstrap/test_integration.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,18 @@
33
Test the full bootstrap discovery integration
44
"""
55

6-
import logging
76
import secrets
87

98
import pytest
109

1110
from libp2p import new_host
12-
from libp2p.abc import PeerInfo
1311
from libp2p.crypto.secp256k1 import create_new_key_pair
14-
from libp2p.discovery.events.peerDiscovery import peerDiscovery
1512
from libp2p.host.basic_host import BasicHost
1613

17-
# Configure logging
18-
logging.basicConfig(level=logging.INFO)
19-
logger = logging.getLogger("bootstrap_test")
20-
21-
22-
def on_peer_discovery(peer_info: PeerInfo) -> None:
23-
"""Handler for peer discovery events."""
24-
logger.info(f"🔍 Discovered peer: {peer_info.peer_id}")
25-
logger.info(f" Addresses: {[str(addr) for addr in peer_info.addrs]}")
26-
2714

2815
@pytest.mark.trio
2916
async def test_bootstrap_integration():
3017
"""Test bootstrap integration with new_host"""
31-
print("🧪 Testing Bootstrap Integration")
32-
3318
# Test bootstrap addresses
3419
bootstrap_addrs = [
3520
"/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SznbYGzPwp8qDrq",
@@ -40,18 +25,9 @@ async def test_bootstrap_integration():
4025
secret = secrets.token_bytes(32)
4126
key_pair = create_new_key_pair(secret)
4227

43-
# Register peer discovery handler
44-
peerDiscovery.register_peer_discovered_handler(on_peer_discovery)
45-
46-
print(f"🌐 Testing with {len(bootstrap_addrs)} bootstrap peers")
47-
4828
# Create host with bootstrap
4929
host = new_host(key_pair=key_pair, bootstrap=bootstrap_addrs)
5030

51-
print("✅ Successfully created host with bootstrap")
52-
print(f"📍 Host peer ID: {host.get_id()}")
53-
print("🔗 Bootstrap discovery should process peers when host starts")
54-
5531
# Verify bootstrap discovery is set up (cast to BasicHost for type checking)
5632
assert isinstance(host, BasicHost), "Host should be a BasicHost instance"
5733
assert hasattr(host, "bootstrap"), "Host should have bootstrap attribute"
@@ -60,8 +36,6 @@ async def test_bootstrap_integration():
6036
"Bootstrap addresses should match"
6137
)
6238

63-
print("🎉 Bootstrap integration test completed successfully!")
64-
6539

6640
def test_bootstrap_no_addresses():
6741
"""Test that bootstrap is not initialized when no addresses provided"""
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Test bootstrap address validation
4+
"""
5+
6+
import pytest
7+
from libp2p.discovery.bootstrap.utils import (
8+
parse_bootstrap_peer_info,
9+
validate_bootstrap_addresses,
10+
)
11+
12+
def test_validate_addresses():
13+
"""Test validation with a mix of valid and invalid addresses in one list."""
14+
addresses = [
15+
# Valid
16+
"/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SznbYGzPwp8qDrq",
17+
"/ip4/104.236.179.241/tcp/4001/p2p/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
18+
# Invalid
19+
"invalid-address",
20+
"/ip4/192.168.1.1/tcp/4001", # Missing p2p part
21+
"", # Empty
22+
"/ip4/127.0.0.1/tcp/4001/p2p/InvalidPeerID", # Bad peer ID
23+
]
24+
valid_expected = [
25+
"/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SznbYGzPwp8qDrq",
26+
"/ip4/104.236.179.241/tcp/4001/p2p/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
27+
]
28+
validated = validate_bootstrap_addresses(addresses)
29+
assert validated == valid_expected, f"Expected only valid addresses, got: {validated}"
30+
for addr in addresses:
31+
peer_info = parse_bootstrap_peer_info(addr)
32+
if addr in valid_expected:
33+
assert peer_info is not None and peer_info.peer_id is not None, f"Should parse valid address: {addr}"
34+
else:
35+
assert peer_info is None, f"Should not parse invalid address: {addr}"

0 commit comments

Comments
 (0)