MCPcopy Create free account
hub / github.com/ElementsProject/elements / run_test

Method run_test

test/functional/p2p_addrfetch.py:43–82  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

41 assert_equal(info[n]['connection_type'], 'addr-fetch')
42
43 def run_test(self):
44 node = self.nodes[0]
45 self.log.info("Connect to an addr-fetch peer")
46 peer_id = 0
47 peer = node.add_outbound_p2p_connection(P2PInterface(), p2p_idx=peer_id, connection_type="addr-fetch")
48 self.assert_getpeerinfo(peer_ids=[peer_id])
49
50 self.log.info("Check that we send getaddr but don't try to sync headers with the addr-fetch peer")
51 peer.sync_send_with_ping()
52 with p2p_lock:
53 assert peer.message_count['getaddr'] == 1
54 assert peer.message_count['getheaders'] == 0
55
56 self.log.info("Check that answering the getaddr with a single address does not lead to disconnect")
57 # This prevents disconnecting on self-announcements
58 msg = msg_addr()
59 msg.addrs = [ADDR]
60 peer.send_and_ping(msg)
61 self.assert_getpeerinfo(peer_ids=[peer_id])
62
63 self.log.info("Check that answering with larger addr messages leads to disconnect")
64 msg.addrs = [ADDR] * 2
65 peer.send_message(msg)
66 peer.wait_for_disconnect(timeout=5)
67
68 self.log.info("Check timeout for addr-fetch peer that does not send addrs")
69 peer_id = 1
70 peer = node.add_outbound_p2p_connection(P2PInterface(), p2p_idx=peer_id, connection_type="addr-fetch")
71
72 time_now = int(time.time())
73 self.assert_getpeerinfo(peer_ids=[peer_id])
74
75 # Expect addr-fetch peer connection to be maintained up to 5 minutes.
76 node.setmocktime(time_now + 295)
77 self.assert_getpeerinfo(peer_ids=[peer_id])
78
79 # Expect addr-fetch peer connection to be disconnected after 5 minutes.
80 node.setmocktime(time_now + 301)
81 peer.wait_for_disconnect(timeout=5)
82 self.assert_getpeerinfo(peer_ids=[])
83
84
85if __name__ == '__main__':

Callers

nothing calls this directly

Calls 10

assert_getpeerinfoMethod · 0.95
P2PInterfaceClass · 0.90
msg_addrClass · 0.90
infoMethod · 0.80
sync_send_with_pingMethod · 0.80
setmocktimeMethod · 0.80
send_and_pingMethod · 0.45
send_messageMethod · 0.45
wait_for_disconnectMethod · 0.45

Tested by

no test coverage detected