3
3
Test the full bootstrap discovery integration
4
4
"""
5
5
6
- import logging
7
6
import secrets
8
7
9
8
import pytest
10
9
11
10
from libp2p import new_host
12
- from libp2p .abc import PeerInfo
13
11
from libp2p .crypto .secp256k1 import create_new_key_pair
14
- from libp2p .discovery .events .peerDiscovery import peerDiscovery
15
12
from libp2p .host .basic_host import BasicHost
16
13
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
-
27
14
28
15
@pytest .mark .trio
29
16
async def test_bootstrap_integration ():
30
17
"""Test bootstrap integration with new_host"""
31
- print ("🧪 Testing Bootstrap Integration" )
32
-
33
18
# Test bootstrap addresses
34
19
bootstrap_addrs = [
35
20
"/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SznbYGzPwp8qDrq" ,
@@ -40,18 +25,9 @@ async def test_bootstrap_integration():
40
25
secret = secrets .token_bytes (32 )
41
26
key_pair = create_new_key_pair (secret )
42
27
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
-
48
28
# Create host with bootstrap
49
29
host = new_host (key_pair = key_pair , bootstrap = bootstrap_addrs )
50
30
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
-
55
31
# Verify bootstrap discovery is set up (cast to BasicHost for type checking)
56
32
assert isinstance (host , BasicHost ), "Host should be a BasicHost instance"
57
33
assert hasattr (host , "bootstrap" ), "Host should have bootstrap attribute"
@@ -60,8 +36,6 @@ async def test_bootstrap_integration():
60
36
"Bootstrap addresses should match"
61
37
)
62
38
63
- print ("🎉 Bootstrap integration test completed successfully!" )
64
-
65
39
66
40
def test_bootstrap_no_addresses ():
67
41
"""Test that bootstrap is not initialized when no addresses provided"""
0 commit comments