Skip to content

Commit 9321086

Browse files
committed
test: add assert_getpeerinfo method and coverage in p2p_addrfetch.py
1 parent 5e21382 commit 9321086

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

test/functional/p2p_addrfetch.py

Lines changed: 12 additions & 6 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,7 +51,7 @@ 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

0 commit comments

Comments
 (0)