mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-25 16:23:49 +02:00
lntest/itest: add mempool tx utility functions
This commit is contained in:
parent
b3afa0c9ed
commit
0e8eb40625
@ -6850,6 +6850,27 @@ func waitForNTxsInMempool(miner *rpcclient.Client, n int,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getNTxsFromMempool polls until finding the desired number of transactions in
|
||||||
|
// the provided miner's mempool and returns the full transactions to the caller.
|
||||||
|
func getNTxsFromMempool(miner *rpcclient.Client, n int,
|
||||||
|
timeout time.Duration) ([]*wire.MsgTx, error) {
|
||||||
|
|
||||||
|
txids, err := waitForNTxsInMempool(miner, n, timeout)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var txes []*wire.MsgTx
|
||||||
|
for _, txid := range txids {
|
||||||
|
tx, err := miner.GetRawTransaction(txid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
txes = append(txes, tx.MsgTx())
|
||||||
|
}
|
||||||
|
return txes, nil
|
||||||
|
}
|
||||||
|
|
||||||
// testFailingChannel tests that we will fail the channel by force closing ii
|
// testFailingChannel tests that we will fail the channel by force closing ii
|
||||||
// in the case where a counterparty tries to settle an HTLC with the wrong
|
// in the case where a counterparty tries to settle an HTLC with the wrong
|
||||||
// preimage.
|
// preimage.
|
||||||
@ -10568,7 +10589,16 @@ func assertNumActiveHtlcs(nodes []*lntest.HarnessNode, numHtlcs int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func assertSpendingTxInMempool(t *harnessTest, miner *rpcclient.Client,
|
func assertSpendingTxInMempool(t *harnessTest, miner *rpcclient.Client,
|
||||||
timeout time.Duration, chanPoint wire.OutPoint) {
|
timeout time.Duration, chanPoint wire.OutPoint) chainhash.Hash {
|
||||||
|
|
||||||
|
tx := getSpendingTxInMempool(t, miner, timeout, chanPoint)
|
||||||
|
return tx.TxHash()
|
||||||
|
}
|
||||||
|
|
||||||
|
// getSpendingTxInMempool waits for a transaction spending the given outpoint to
|
||||||
|
// appear in the mempool and returns that tx in full.
|
||||||
|
func getSpendingTxInMempool(t *harnessTest, miner *rpcclient.Client,
|
||||||
|
timeout time.Duration, chanPoint wire.OutPoint) *wire.MsgTx {
|
||||||
|
|
||||||
breakTimeout := time.After(timeout)
|
breakTimeout := time.After(timeout)
|
||||||
ticker := time.NewTicker(50 * time.Millisecond)
|
ticker := time.NewTicker(50 * time.Millisecond)
|
||||||
@ -10594,9 +10624,10 @@ func assertSpendingTxInMempool(t *harnessTest, miner *rpcclient.Client,
|
|||||||
t.Fatalf("unable to fetch tx: %v", err)
|
t.Fatalf("unable to fetch tx: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, txIn := range tx.MsgTx().TxIn {
|
msgTx := tx.MsgTx()
|
||||||
|
for _, txIn := range msgTx.TxIn {
|
||||||
if txIn.PreviousOutPoint == chanPoint {
|
if txIn.PreviousOutPoint == chanPoint {
|
||||||
return
|
return msgTx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user