lntest: add method AssertTxnsNotInMempool

So we only need to do one `GetRawMempool` lookup when checking the
exclusion of multiple txns.
This commit is contained in:
yyforyongyu 2024-10-17 07:34:40 +08:00 committed by Oliver Gugger
parent 56e05a3e1e
commit f09b638343
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
2 changed files with 29 additions and 3 deletions

View File

@ -112,9 +112,7 @@ func (h *HarnessTest) MineBlocksAndAssertNumTxes(num uint32,
}
// Make sure the mempool has been updated.
for _, txid := range txids {
h.miner.AssertTxNotInMempool(txid)
}
h.miner.AssertTxnsNotInMempool(txids)
// Finally, make sure all the active nodes are synced.
bestBlock := blocks[len(blocks)-1]

View File

@ -314,6 +314,34 @@ func (h *HarnessMiner) AssertTxInMempool(txid chainhash.Hash) *wire.MsgTx {
return msgTx
}
// AssertTxnsNotInMempool asserts the given txns are not found in the mempool.
// It assumes the mempool is not empty.
func (h *HarnessMiner) AssertTxnsNotInMempool(txids []chainhash.Hash) {
err := wait.NoError(func() error {
// We require the RPC call to be succeeded and won't wait for
// it as it's an unexpected behavior.
mempool := h.GetRawMempool()
// Turn the mempool into a txn set for faster lookups.
mempoolTxns := fn.NewSet(mempool...)
// Check if any of the txids are in the mempool.
for _, txid := range txids {
// Skip if the tx is not in the mempool.
if !mempoolTxns.Contains(txid) {
continue
}
return fmt.Errorf("expect txid %v to be NOT found in "+
"mempool", txid)
}
return nil
}, wait.MinerMempoolTimeout)
require.NoError(h, err, "timeout checking txns not in mempool")
}
// AssertTxNotInMempool asserts a given transaction cannot be found in the
// mempool. It assumes the mempool is not empty.
//