From c462e54f9df431434e6480d8293060645468d3ab Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Sat, 21 Feb 2026 17:13:11 +0100 Subject: [PATCH] test: don't always assert NUM_PRIVATE_BROADCAST_PER_TX broadcasts In `p2p_private_broadcast.py` in the function `check_broadcasts()` we should assert that the broadcast was done to `broadcasts_to_expect` peers, not to `NUM_PRIVATE_BROADCAST_PER_TX`. This is because in the "Basic" test we check the first broadcast manually because it is done to `nodes[1]` and then check the other two by `check_broadcasts(..., NUM_PRIVATE_BROADCAST_PER_TX - 1, ...)`. The first broadcast might not have fully concluded by the time we call `check_broadcasts()` to check the remaining 2. Demanding always `NUM_PRIVATE_BROADCAST_PER_TX` can lead to: ``` Traceback (most recent call last): File "/home/vd/gh/bitcoin/bitcoin/test/functional/test_framework/test_framework.py", line 142, in main self.run_test() ~~~~~~~~~~~~~^^ File "/tmp/build/clang22/test/functional/p2p_private_broadcast.py", line 347, in run_test self.check_broadcasts("Basic", txs[0], NUM_PRIVATE_BROADCAST_PER_TX - 1, NUM_INITIAL_CONNECTIONS + 1) ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/build/clang22/test/functional/p2p_private_broadcast.py", line 313, in check_broadcasts assert_greater_than_or_equal(sum(1 for p in peers if "received" in p), NUM_PRIVATE_BROADCAST_PER_TX) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/vd/gh/bitcoin/bitcoin/test/functional/test_framework/util.py", line 94, in assert_greater_than_or_equal raise AssertionError("%s < %s" % (str(thing1), str(thing2))) AssertionError: 2 < 3 ``` --- test/functional/p2p_private_broadcast.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/p2p_private_broadcast.py b/test/functional/p2p_private_broadcast.py index 9a1a7991edf..b81b5aa483d 100755 --- a/test/functional/p2p_private_broadcast.py +++ b/test/functional/p2p_private_broadcast.py @@ -310,7 +310,7 @@ class P2PPrivateBroadcast(BitcoinTestFramework): peers = pending[0]["peers"] assert len(peers) >= NUM_PRIVATE_BROADCAST_PER_TX assert all("address" in p and "sent" in p for p in peers) - assert_greater_than_or_equal(sum(1 for p in peers if "received" in p), NUM_PRIVATE_BROADCAST_PER_TX) + assert_greater_than_or_equal(sum(1 for p in peers if "received" in p), broadcasts_to_expect) def run_test(self): tx_originator = self.nodes[0]