@@ -121,6 +121,37 @@ func (h *HarnessTest) MineBlocksAndAssertNumTxes(num uint32,
121121 return blocks
122122}
123123
124+ // MineBlocksAndAssertNumTxesWithSweep is like MineBlocksAndAssertNumTxes but
125+ // handles async confirmation notification races by triggering sweeps if needed.
126+ // Use this for tests that expect sweep transactions after force closes or other
127+ // events where confirmation notifications may arrive asynchronously.
128+ func (h * HarnessTest ) MineBlocksAndAssertNumTxesWithSweep (num uint32 ,
129+ numTxs int , hn * node.HarnessNode ) []* wire.MsgBlock {
130+
131+ // Update the harness's current height.
132+ defer h .updateCurrentHeight ()
133+
134+ // Wait for transactions with sweep triggering support.
135+ txids := h .AssertNumTxsInMempoolWithSweepTrigger (numTxs , hn )
136+
137+ // Mine blocks.
138+ blocks := h .miner .MineBlocks (num )
139+
140+ // Assert that all the transactions were included in the first block.
141+ for _ , txid := range txids {
142+ h .miner .AssertTxInBlock (blocks [0 ], txid )
143+ }
144+
145+ // Make sure the mempool has been updated.
146+ h .miner .AssertTxnsNotInMempool (txids )
147+
148+ // Finally, make sure all the active nodes are synced.
149+ bestBlock := blocks [len (blocks )- 1 ]
150+ h .AssertActiveNodesSyncedTo (bestBlock .BlockHash ())
151+
152+ return blocks
153+ }
154+
124155// ConnectMiner connects the miner with the chain backend in the network.
125156func (h * HarnessTest ) ConnectMiner () {
126157 err := h .manager .chainBackend .ConnectMiner ()
@@ -222,6 +253,16 @@ func (h *HarnessTest) AssertNumTxsInMempool(n int) []chainhash.Hash {
222253 return h .miner .AssertNumTxsInMempool (n )
223254}
224255
256+ // AssertNumTxsInMempoolWithSweepTrigger waits for N transactions with sweep
257+ // triggering support to handle async confirmation notification races. If
258+ // transactions don't appear within a short timeout, it triggers a manual sweep
259+ // via the provided node's RPC and waits again.
260+ func (h * HarnessTest ) AssertNumTxsInMempoolWithSweepTrigger (n int ,
261+ hn * node.HarnessNode ) []chainhash.Hash {
262+
263+ return h .miner .AssertNumTxsInMempoolWithSweepTrigger (n , hn .RPC )
264+ }
265+
225266// AssertOutpointInMempool asserts a given outpoint can be found in the mempool.
226267func (h * HarnessTest ) AssertOutpointInMempool (op wire.OutPoint ) * wire.MsgTx {
227268 return h .miner .AssertOutpointInMempool (op )
@@ -240,6 +281,23 @@ func (h *HarnessTest) GetNumTxsFromMempool(n int) []*wire.MsgTx {
240281 return h .miner .GetNumTxsFromMempool (n )
241282}
242283
284+ // GetNumTxsFromMempoolWithSweep gets N transactions from mempool with sweep
285+ // triggering support to handle async confirmation notification races. Use this
286+ // for tests that expect sweep transactions after force closes.
287+ func (h * HarnessTest ) GetNumTxsFromMempoolWithSweep (n int ,
288+ hn * node.HarnessNode ) []* wire.MsgTx {
289+
290+ txids := h .AssertNumTxsInMempoolWithSweepTrigger (n , hn )
291+
292+ var txes []* wire.MsgTx
293+ for _ , txid := range txids {
294+ tx := h .miner .GetRawTransaction (txid )
295+ txes = append (txes , tx .MsgTx ())
296+ }
297+
298+ return txes
299+ }
300+
243301// GetBestBlock makes a RPC request to miner and asserts.
244302func (h * HarnessTest ) GetBestBlock () (* chainhash.Hash , int32 ) {
245303 return h .miner .GetBestBlock ()
0 commit comments