lntest+itest: extend CloseChannelAssertPending

In this commit, we extend `CloseChannelAssertPending` with new args that
returns the raw close status update (as we have more things we'd like to
assert), and also allows us to pass in a custom fee rate.
This commit is contained in:
Olaoluwa Osuntokun committed 2025-03-18 11:44:21 -05:00
1 parent 2899a757c4
commit fbc67f7610
4 files changed
+60 -21

No files matched your search

+18 -8
View File
@@ -109,7 +109,11 @@ func breachRetributionTestCase(ht *lntest.HarnessTest,
// broadcasting his current channel state. This is actually the
// commitment transaction of a prior *revoked* state, so he'll soon
// feel the wrath of Carol's retribution.
_, breachTXID := ht.CloseChannelAssertPending(bob, chanPoint, true)
_, breachCloseUpd := ht.CloseChannelAssertPending(bob, chanPoint, true)
closeUpd := breachCloseUpd.GetClosePending()
require.NotNil(ht, closeUpd)
breachTXID, err := chainhash.NewHash(closeUpd.Txid)
require.NoError(ht, err)
// Here, Carol sees Bob's breach transaction in the mempool, but is
// waiting for it to confirm before continuing her retribution. We
@@ -122,13 +126,13 @@ func breachRetributionTestCase(ht *lntest.HarnessTest,
// update, then ensure that the closing transaction was included in the
// block.
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.AssertTxInBlock(block, breachTXID)
ht.AssertTxInBlock(block, *breachTXID)
// Construct to_remote output which pays to Bob. Based on the output
// ordering, the first output in this breach tx is the to_remote
// output.
toRemoteOp := wire.OutPoint{
Hash: breachTXID,
Hash: *breachTXID,
Index: 0,
}
@@ -151,7 +155,7 @@ func breachRetributionTestCase(ht *lntest.HarnessTest,
// Assert that all the inputs of this transaction are spending outputs
// generated by Bob's breach transaction above.
for _, txIn := range justiceTx.TxIn {
require.Equal(ht, breachTXID, txIn.PreviousOutPoint.Hash,
require.Equal(ht, *breachTXID, txIn.PreviousOutPoint.Hash,
"justice tx not spending commitment utxo")
}
@@ -296,7 +300,7 @@ func revokedCloseRetributionZeroValueRemoteOutputCase(ht *lntest.HarnessTest,
// broadcasting her current channel state. This is actually the
// commitment transaction of a prior *revoked* state, so she'll soon
// feel the wrath of Dave's retribution.
stream, closeTxID := ht.CloseChannelAssertPending(
stream, closeUpdate := ht.CloseChannelAssertPending(
carol, chanPoint, true,
)
@@ -310,9 +314,11 @@ func revokedCloseRetributionZeroValueRemoteOutputCase(ht *lntest.HarnessTest,
// state and continues exacting justice after his node restarts.
ht.RestartNode(dave)
closeTxID := closeUpdate.GetClosePending().Txid
// The breachTXID should match the above closeTxID.
breachTXID := ht.WaitForChannelCloseEvent(stream)
require.EqualValues(ht, breachTXID, closeTxID)
require.EqualValues(ht, breachTXID[:], closeTxID)
// Construct to_local output which pays to Dave. Based on the output
// ordering, the first output in this breach tx is the to_local
@@ -543,9 +549,13 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest,
// broadcasting her current channel state. This is actually the
// commitment transaction of a prior *revoked* state, so she'll soon
// feel the wrath of Dave's retribution.
closeUpdates, closeTxID := ht.CloseChannelAssertPending(
closeUpdates, closeUpd := ht.CloseChannelAssertPending(
carol, chanPoint, true,
)
pendingCloseUpd := closeUpd.GetClosePending()
require.NotNil(ht, pendingCloseUpd)
closeTxID, err := chainhash.NewHash(pendingCloseUpd.Txid)
require.NoError(ht, err)
// Generate a single block to mine the breach transaction.
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
@@ -593,7 +603,7 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest,
return nil, errNotFound
}
err := wait.NoError(func() error {
err = wait.NoError(func() error {
txid, err := findJusticeTx()
if err != nil {
return err
+7 -4
View File
@@ -5,6 +5,7 @@ import (
"time"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/contractcourt"
"github.com/lightningnetwork/lnd/fn/v2"
@@ -1963,8 +1964,8 @@ func testBumpForceCloseFee(ht *lntest.HarnessTest) {
ht.FundCoinsP2TR(btcutil.SatoshiPerBitcoin, alice)
// Alice force closes the channel which has no HTLCs at stake.
_, closingTxID := ht.CloseChannelAssertPending(alice, chanPoint, true)
require.NotNil(ht, closingTxID)
_, closeUpdates := ht.CloseChannelAssertPending(alice, chanPoint, true)
require.NotNil(ht, closeUpdates)
// Alice should see one waiting close channel.
ht.AssertNumWaitingClose(alice, 1)
@@ -1974,8 +1975,10 @@ func testBumpForceCloseFee(ht *lntest.HarnessTest) {
ht.AssertNumPendingSweeps(alice, 2)
// Calculate the commitment tx fee rate.
closingTx := ht.AssertTxInMempool(closingTxID)
require.NotNil(ht, closingTx)
pendingClose := closeUpdates.GetClosePending()
closeTxid, err := chainhash.NewHash(pendingClose.Txid)
require.NoError(ht, err)
closingTx := ht.AssertTxInMempool(*closeTxid)
// The default commitment fee for anchor channels is capped at 2500
// sat/kw but there might be some inaccuracies because of the witness
+3 -2
View File
@@ -491,7 +491,7 @@ func testRevokedCloseRetributionAltruistWatchtowerCase(ht *lntest.HarnessTest,
// broadcasting his current channel state. This is actually the
// commitment transaction of a prior *revoked* state, so he'll soon
// feel the wrath of Dave's retribution.
closeUpdates, closeTxID := ht.CloseChannelAssertPending(
closeUpdates, pendingClose := ht.CloseChannelAssertPending(
carol, chanPoint, true,
)
@@ -504,7 +504,8 @@ func testRevokedCloseRetributionAltruistWatchtowerCase(ht *lntest.HarnessTest,
ht.AssertTxInBlock(block, breachTXID)
// The breachTXID should match the above closeTxID.
require.EqualValues(ht, breachTXID, closeTxID)
closeTxID := pendingClose.GetClosePending().Txid
require.EqualValues(ht, breachTXID[:], closeTxID)
// Query the mempool for Dave's justice transaction, this should be
// broadcast as Carol's contract breaching transaction gets confirmed