mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
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:
parent
56e05a3e1e
commit
f09b638343
@ -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]
|
||||
|
@ -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.
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user