itest: update async coop close itests to also use new rbf flow

This commit is contained in:
Olaoluwa Osuntokun
2024-03-05 00:20:33 -06:00
parent 429bbf33ef
commit 413cc3da35

View File

@ -1,6 +1,7 @@
package itest package itest
import ( import (
"fmt"
"testing" "testing"
"github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/btcutil"
@ -10,6 +11,7 @@ import (
"github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc" "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lntest" "github.com/lightningnetwork/lnd/lntest"
"github.com/lightningnetwork/lnd/lntest/node"
"github.com/lightningnetwork/lnd/lntest/wait" "github.com/lightningnetwork/lnd/lntest/wait"
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/lightningnetwork/lnd/lnwallet/chainfee"
@ -23,23 +25,48 @@ import (
// will have the receiver settle the invoice and observe that the channel gets // will have the receiver settle the invoice and observe that the channel gets
// torn down after settlement. // torn down after settlement.
func testCoopCloseWithHtlcs(ht *lntest.HarnessTest) { func testCoopCloseWithHtlcs(ht *lntest.HarnessTest) {
ht.Run("no restart", func(t *testing.T) { rbfCoopFlags := []string{"--protocol.rbf-coop-close"}
tt := ht.Subtest(t)
coopCloseWithHTLCs(tt)
})
ht.Run("with restart", func(t *testing.T) { for _, isRbf := range []bool{true, false} {
tt := ht.Subtest(t) testName := fmt.Sprintf("no restart is_rbf=%v", isRbf)
coopCloseWithHTLCsWithRestart(tt) ht.Run(testName, func(t *testing.T) {
}) tt := ht.Subtest(t)
var flags []string
if isRbf {
flags = rbfCoopFlags
}
alice := ht.NewNodeWithCoins("Alice", flags)
bob := ht.NewNodeWithCoins("bob", flags)
coopCloseWithHTLCs(tt, alice, bob)
})
}
for _, isRbf := range []bool{true, false} {
testName := fmt.Sprintf("with restart is_rbf=%v", isRbf)
ht.Run(testName, func(t *testing.T) {
tt := ht.Subtest(t)
var flags []string
if isRbf {
flags = rbfCoopFlags
}
alice := ht.NewNodeWithCoins("Alice", flags)
bob := ht.NewNodeWithCoins("bob", flags)
coopCloseWithHTLCsWithRestart(tt, alice, bob)
})
}
} }
// coopCloseWithHTLCs tests the basic coop close scenario which occurs when one // coopCloseWithHTLCs tests the basic coop close scenario which occurs when one
// channel party initiates a channel shutdown while an HTLC is still pending on // channel party initiates a channel shutdown while an HTLC is still pending on
// the channel. // the channel.
func coopCloseWithHTLCs(ht *lntest.HarnessTest) { func coopCloseWithHTLCs(ht *lntest.HarnessTest, alice, bob *node.HarnessNode) {
alice := ht.NewNodeWithCoins("Alice", nil)
bob := ht.NewNodeWithCoins("bob", nil)
ht.ConnectNodes(alice, bob) ht.ConnectNodes(alice, bob)
// Here we set up a channel between Alice and Bob, beginning with a // Here we set up a channel between Alice and Bob, beginning with a
@ -131,9 +158,9 @@ func coopCloseWithHTLCs(ht *lntest.HarnessTest) {
// is still pending on the channel but this time it ensures that the shutdown // is still pending on the channel but this time it ensures that the shutdown
// process continues as expected even if a channel re-establish happens after // process continues as expected even if a channel re-establish happens after
// one party has already initiated the shutdown. // one party has already initiated the shutdown.
func coopCloseWithHTLCsWithRestart(ht *lntest.HarnessTest) { func coopCloseWithHTLCsWithRestart(ht *lntest.HarnessTest, alice,
alice := ht.NewNodeWithCoins("Alice", nil) bob *node.HarnessNode) {
bob := ht.NewNodeWithCoins("bob", nil)
ht.ConnectNodes(alice, bob) ht.ConnectNodes(alice, bob)
// Open a channel between Alice and Bob with the balance split equally. // Open a channel between Alice and Bob with the balance split equally.
@ -219,8 +246,8 @@ func coopCloseWithHTLCsWithRestart(ht *lntest.HarnessTest) {
}, defaultTimeout) }, defaultTimeout)
require.NoError(ht, err) require.NoError(ht, err)
// Wait for the close tx to be in the Mempool and then mine 6 blocks // Wait for the close tx to be in the Mempool and then mine 6 blocks to
// to confirm the close. // confirm the close.
closingTx := ht.AssertClosingTxInMempool( closingTx := ht.AssertClosingTxInMempool(
chanPoint, lnrpc.CommitmentType_LEGACY, chanPoint, lnrpc.CommitmentType_LEGACY,
) )