Skip to content

Commit 999f8b2

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#22568: test: add addr-fetch peer connection state and timeout coverage
f8d8eb5 test: add addr-fetch timeout connection coverage in p2p_addrfetch.py (Jon Atack) 9321086 test: add assert_getpeerinfo method and coverage in p2p_addrfetch.py (Jon Atack) Pull request description: This patch adds additional addr-fetch peer connection state and timeout coverage as a follow-up to #22096. ACKs for top commit: Saviour1001: Tested ACK <code>[f8d8eb5](https://github.com/bitcoin/bitcoin/pull/22568/commits/f8d8eb5fdaa93b6e5b77fd901b94927dc3a0473e)</code> mzumsande: Code review ACK f8d8eb5 Tree-SHA512: 9a13a705d1da6b308d6dcbc6930575205e2e88bfe9f2e7cb4e0c4c40d26538430e6b02c6c772d0cee64e534777348291469a139f99afbf9d4f93f31b9e7b0818
2 parents 92f3a4b + f8d8eb5 commit 999f8b2

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

test/functional/p2p_addrfetch.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,24 @@
2121

2222

2323
class P2PAddrFetch(BitcoinTestFramework):
24-
2524
def set_test_params(self):
2625
self.setup_clean_chain = True
2726
self.num_nodes = 1
2827

28+
def assert_getpeerinfo(self, *, peer_ids):
29+
num_peers = len(peer_ids)
30+
info = self.nodes[0].getpeerinfo()
31+
assert_equal(len(info), num_peers)
32+
for n in range(0, num_peers):
33+
assert_equal(info[n]['id'], peer_ids[n])
34+
assert_equal(info[n]['connection_type'], 'addr-fetch')
35+
2936
def run_test(self):
3037
node = self.nodes[0]
3138
self.log.info("Connect to an addr-fetch peer")
32-
peer = node.add_outbound_p2p_connection(P2PInterface(), p2p_idx=0, connection_type="addr-fetch")
33-
info = node.getpeerinfo()
34-
assert_equal(len(info), 1)
35-
assert_equal(info[0]['connection_type'], 'addr-fetch')
39+
peer_id = 0
40+
peer = node.add_outbound_p2p_connection(P2PInterface(), p2p_idx=peer_id, connection_type="addr-fetch")
41+
self.assert_getpeerinfo(peer_ids=[peer_id])
3642

3743
self.log.info("Check that we send getaddr but don't try to sync headers with the addr-fetch peer")
3844
peer.sync_send_with_ping()
@@ -45,17 +51,28 @@ def run_test(self):
4551
msg = msg_addr()
4652
msg.addrs = [ADDR]
4753
peer.send_and_ping(msg)
48-
assert_equal(len(node.getpeerinfo()), 1)
54+
self.assert_getpeerinfo(peer_ids=[peer_id])
4955

5056
self.log.info("Check that answering with larger addr messages leads to disconnect")
5157
msg.addrs = [ADDR] * 2
5258
peer.send_message(msg)
5359
peer.wait_for_disconnect(timeout=5)
5460

5561
self.log.info("Check timeout for addr-fetch peer that does not send addrs")
56-
peer = node.add_outbound_p2p_connection(P2PInterface(), p2p_idx=1, connection_type="addr-fetch")
57-
node.setmocktime(int(time.time()) + 301) # Timeout: 5 minutes
62+
peer_id = 1
63+
peer = node.add_outbound_p2p_connection(P2PInterface(), p2p_idx=peer_id, connection_type="addr-fetch")
64+
65+
time_now = int(time.time())
66+
self.assert_getpeerinfo(peer_ids=[peer_id])
67+
68+
# Expect addr-fetch peer connection to be maintained up to 5 minutes.
69+
node.setmocktime(time_now + 295)
70+
self.assert_getpeerinfo(peer_ids=[peer_id])
71+
72+
# Expect addr-fetch peer connection to be disconnected after 5 minutes.
73+
node.setmocktime(time_now + 301)
5874
peer.wait_for_disconnect(timeout=5)
75+
self.assert_getpeerinfo(peer_ids=[])
5976

6077

6178
if __name__ == '__main__':

0 commit comments

Comments
 (0)