refactor: test: Static assert_highbandwidth_states
What changed, and why it matters
This commit is a minor code cleanup in Bitcoin Core's test suite. It moves a small helper function from inside one test method to the class level so other tests can reuse it. There is no change to the actual Bitcoin network code, no change to how nodes communicate, and no security issue.
No action required. This is a benign test-only refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors assert_highbandwidth_states from a nested function inside test_highbandwidth_mode_states_via_getpeerinfo to a static method on the CompactBlocksTest class. All existing call sites are updated from assert_highbandwidth_states(...) to self.assert_highbandwidth_states(...). The function body is unchanged. This is a move-only refactor in functional test code.
Changed components
test/functional/p2p_compactblocks.pyInspect captured patch +12 / −11
diff --git a/test/functional/p2p_compactblocks.py b/test/functional/p2p_compactblocks.py
index bf305cbd..52bbb294 100755
--- a/test/functional/p2p_compactblocks.py
+++ b/test/functional/p2p_compactblocks.py
@@ -852,33 +852,34 @@ class CompactBlocksTest(BitcoinTestFramework):
stalling_peer.send_and_ping(msg)
assert_equal(node.getbestblockhash(), block.hash_hex)
+ # assert the RPC getpeerinfo boolean fields `bip152_hb_{to, from}`
+ # match the given parameters for the last peer of a given node
+ @staticmethod
+ def assert_highbandwidth_states(node, hb_to, hb_from):
+ peerinfo = node.getpeerinfo()[-1]
+ assert_equal(peerinfo['bip152_hb_to'], hb_to)
+ assert_equal(peerinfo['bip152_hb_from'], hb_from)
+
def test_highbandwidth_mode_states_via_getpeerinfo(self):
# create new p2p connection for a fresh state w/o any prior sendcmpct messages sent
hb_test_node = self.nodes[0].add_p2p_connection(TestP2PConn())
- # assert the RPC getpeerinfo boolean fields `bip152_hb_{to, from}`
- # match the given parameters for the last peer of a given node
- def assert_highbandwidth_states(node, hb_to, hb_from):
- peerinfo = node.getpeerinfo()[-1]
- assert_equal(peerinfo['bip152_hb_to'], hb_to)
- assert_equal(peerinfo['bip152_hb_from'], hb_from)
-
# initially, neither node has selected the other peer as high-bandwidth yet
- assert_highbandwidth_states(self.nodes[0], hb_to=False, hb_from=False)
+ self.assert_highbandwidth_states(self.nodes[0], hb_to=False, hb_from=False)
# peer requests high-bandwidth mode by sending sendcmpct(1)
hb_test_node.send_and_ping(msg_sendcmpct(announce=True, version=2))
- assert_highbandwidth_states(self.nodes[0], hb_to=False, hb_from=True)
+ self.assert_highbandwidth_states(self.nodes[0], hb_to=False, hb_from=True)
# peer generates a block and sends it to node, which should
# select the peer as high-bandwidth (up to 3 peers according to BIP 152)
block = self.build_block_on_tip(self.nodes[0])
hb_test_node.send_and_ping(msg_block(block))
- assert_highbandwidth_states(self.nodes[0], hb_to=True, hb_from=True)
+ self.assert_highbandwidth_states(self.nodes[0], hb_to=True, hb_from=True)
# peer requests low-bandwidth mode by sending sendcmpct(0)
hb_test_node.send_and_ping(msg_sendcmpct(announce=False, version=2))
- assert_highbandwidth_states(self.nodes[0], hb_to=True, hb_from=False)
+ self.assert_highbandwidth_states(self.nodes[0], hb_to=True, hb_from=False)
def test_compactblock_reconstruction_parallel_reconstruction(self, stalling_peer, delivery_peer, inbound_peer, outbound_peer):
""" All p2p connections are inbound except outbound_peer. We test that ultimate parallel slot
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.