test: Cover abortprivatebroadcast in p2p_private_broadcast
What changed, and why it matters
This commit only adds new test code to Bitcoin Core. It does not change any production wallet, networking, or consensus code. The test verifies that a new RPC command, abortprivatebroadcast, correctly removes a transaction from the private-broadcast queue and returns an error for a non-existent transaction. There is no security-relevant change to end-user behavior.
No action required; this is a routine test-coverage addition.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff extends test/functional/p2p_private_broadcast.py with two functional test cases for the abortprivatebroadcast RPC: (1) successful removal of a pending private-broadcast transaction, checking the returned txid/wtxid/hex fields and that the transaction no longer appears in getprivatebroadcastinfo; (2) an RPC error (-5, ‘Transaction not in private broadcast queue’) when called with a non-existent txid. No production code is modified.
Changed components
test/functional/p2p_private_broadcast.pyInspect captured patch +19 / −0
diff --git a/test/functional/p2p_private_broadcast.py b/test/functional/p2p_private_broadcast.py
index 97c90bf4..f43863ee 100755
--- a/test/functional/p2p_private_broadcast.py
+++ b/test/functional/p2p_private_broadcast.py
@@ -382,6 +382,25 @@ class P2PPrivateBroadcast(BitcoinTestFramework):
pending = [t for t in pbinfo["transactions"] if t["txid"] == txs[0]["txid"] and t["wtxid"] == txs[0]["wtxid"]]
assert_equal(len(pending), 0)
+ self.log.info("Checking abortprivatebroadcast removes a pending private-broadcast transaction")
+ tx_abort = wallet.create_self_transfer()
+ tx_originator.sendrawtransaction(hexstring=tx_abort["hex"], maxfeerate=0.1)
+ assert any(t["wtxid"] == tx_abort["wtxid"] for t in tx_originator.getprivatebroadcastinfo()["transactions"])
+ abort_res = tx_originator.abortprivatebroadcast(tx_abort["txid"])
+ assert_equal(len(abort_res["removed_transactions"]), 1)
+ assert_equal(abort_res["removed_transactions"][0]["txid"], tx_abort["txid"])
+ assert_equal(abort_res["removed_transactions"][0]["wtxid"], tx_abort["wtxid"])
+ assert_equal(abort_res["removed_transactions"][0]["hex"].lower(), tx_abort["hex"].lower())
+ assert all(t["wtxid"] != tx_abort["wtxid"] for t in tx_originator.getprivatebroadcastinfo()["transactions"])
+
+ self.log.info("Checking abortprivatebroadcast fails for non-existent transaction")
+ assert_raises_rpc_error(
+ -5,
+ "Transaction not in private broadcast queue",
+ tx_originator.abortprivatebroadcast,
+ "0" * 64,
+ )
+
self.log.info("Sending a transaction that is already in the mempool")
skip_destinations = len(self.destinations)
tx_originator.sendrawtransaction(hexstring=txs[0]["hex"], maxfeerate=0)
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.