@@ -18,60 +18,110 @@ import (
1818 "github.com/stretchr/testify/require"
1919)
2020
21+ type flagCombo struct {
22+ isRbf bool
23+ isTaproot bool
24+ testName string
25+ flags []string
26+ commitType lnrpc.CommitmentType
27+ private bool
28+ }
29+
30+ // createFlagCombos generates a slice of flagCombo structs representing
31+ // different test configurations for RBF and Taproot channels.
32+ func createFlagCombos () []flagCombo {
33+ var testCases []flagCombo
34+ for _ , isRbf := range []bool {true , false } {
35+ for _ , isTaproot := range []bool {true , false } {
36+ flagCombo := flagCombo {
37+ isRbf : isRbf ,
38+ isTaproot : isTaproot ,
39+ }
40+
41+ var flags []string
42+
43+ if isRbf {
44+ flags = append (flags , node .CfgRbfClose ... )
45+ }
46+
47+ if isTaproot {
48+ flags = append (flags , node .CfgSimpleTaproot ... )
49+ flagCombo .commitType = lnrpc .CommitmentType_SIMPLE_TAPROOT //nolint:ll
50+ flagCombo .private = true
51+ }
52+
53+ flagCombo .flags = flags
54+ flagCombo .testName = fmt .Sprintf (
55+ "is_rbf=%v is_taproot=%v" , isRbf , isTaproot ,
56+ )
57+
58+ testCases = append (testCases , flagCombo )
59+ }
60+ }
61+
62+ return testCases
63+ }
64+
2165// testCoopCloseWithHtlcs tests whether we can successfully issue a coop close
22- // request while there are still active htlcs on the link. In all the tests , we
66+ // request while there are still active htlcs on the link. In this test , we
2367// will set up an HODL invoice to suspend settlement. Then we will attempt to
2468// close the channel which should appear as a noop for the time being. Then we
2569// will have the receiver settle the invoice and observe that the channel gets
26- // torn down after settlement.
70+ // torn down after settlement. This test covers scenarios without node restarts.
2771func testCoopCloseWithHtlcs (ht * lntest.HarnessTest ) {
28- rbfCoopFlags := [] string { "--protocol.rbf-coop-close" }
72+ testCases := createFlagCombos ()
2973
30- for _ , isRbf := range [] bool { true , false } {
31- testName := fmt . Sprintf ( "no restart is_rbf=%v" , isRbf )
32- ht .Run (testName , func (t * testing.T ) {
74+ for _ , testCase := range testCases {
75+ testCase := testCase // Capture range variable.
76+ ht .Run (testCase . testName , func (t * testing.T ) {
3377 tt := ht .Subtest (t )
3478
35- var flags []string
36- if isRbf {
37- flags = rbfCoopFlags
38- }
39-
40- alice := ht .NewNodeWithCoins ("Alice" , flags )
41- bob := ht .NewNodeWithCoins ("bob" , flags )
79+ alice := ht .NewNodeWithCoins ("Alice" , testCase .flags )
80+ bob := ht .NewNodeWithCoins ("bob" , testCase .flags )
4281
43- coopCloseWithHTLCs (tt , alice , bob )
82+ runCoopCloseWithHTLCsScenario (tt , alice , bob , testCase )
4483 })
4584 }
85+ }
4686
47- for _ , isRbf := range []bool {true , false } {
48- testName := fmt .Sprintf ("with restart is_rbf=%v" , isRbf )
49- ht .Run (testName , func (t * testing.T ) {
87+ // testCoopCloseWithHtlcsWithRestart tests whether we can successfully issue a
88+ // coop close request while there are still active htlcs on the link, even
89+ // after a node restart. In this test, we will set up an HODL invoice to
90+ // suspend settlement. Then we will attempt to close the channel, restart the
91+ // nodes, and then have the receiver settle the invoice, observing that the
92+ // channel gets torn down after settlement and restart.
93+ func testCoopCloseWithHtlcsWithRestart (ht * lntest.HarnessTest ) {
94+ testCases := createFlagCombos ()
95+
96+ for _ , testCase := range testCases {
97+ testCase := testCase // Capture range variable.
98+ ht .Run (testCase .testName , func (t * testing.T ) {
5099 tt := ht .Subtest (t )
51100
52- var flags []string
53- if isRbf {
54- flags = rbfCoopFlags
55- }
56-
57- alice := ht .NewNodeWithCoins ("Alice" , flags )
58- bob := ht .NewNodeWithCoins ("bob" , flags )
101+ alice := ht .NewNodeWithCoins ("Alice" , testCase .flags )
102+ bob := ht .NewNodeWithCoins ("bob" , testCase .flags )
59103
60- coopCloseWithHTLCsWithRestart (tt , alice , bob )
104+ runCoopCloseWithHTLCsWithRestartScenario (
105+ tt , alice , bob , testCase ,
106+ )
61107 })
62108 }
63109}
64110
65- // coopCloseWithHTLCs tests the basic coop close scenario which occurs when one
66- // channel party initiates a channel shutdown while an HTLC is still pending on
67- // the channel.
68- func coopCloseWithHTLCs (ht * lntest.HarnessTest , alice , bob * node.HarnessNode ) {
111+ // runCoopCloseWithHTLCsScenario tests the basic coop close scenario which
112+ // occurs when one channel party initiates a channel shutdown while an HTLC is
113+ // still pending on the channel.
114+ func runCoopCloseWithHTLCsScenario (ht * lntest.HarnessTest , alice ,
115+ bob * node.HarnessNode , testCase flagCombo ) {
116+
69117 ht .ConnectNodes (alice , bob )
70118
71119 // Here we set up a channel between Alice and Bob, beginning with a
72120 // balance on Bob's side.
73121 chanPoint := ht .OpenChannel (bob , alice , lntest.OpenChannelParams {
74- Amt : btcutil .Amount (1000000 ),
122+ Amt : btcutil .Amount (1000000 ),
123+ CommitmentType : testCase .commitType ,
124+ Private : testCase .private ,
75125 })
76126
77127 // Wait for Bob to understand that the channel is ready to use.
@@ -153,12 +203,12 @@ func coopCloseWithHTLCs(ht *lntest.HarnessTest, alice, bob *node.HarnessNode) {
153203 ht .AssertStreamChannelCoopClosed (alice , chanPoint , false , closeClient )
154204}
155205
156- // coopCloseWithHTLCsWithRestart also tests the coop close flow when an HTLC
157- // is still pending on the channel but this time it ensures that the shutdown
158- // process continues as expected even if a channel re-establish happens after
159- // one party has already initiated the shutdown.
160- func coopCloseWithHTLCsWithRestart (ht * lntest.HarnessTest , alice ,
161- bob * node.HarnessNode ) {
206+ // runCoopCloseWithHTLCsWithRestartScenario also tests the coop close flow when
207+ // an HTLC is still pending on the channel but this time it ensures that the
208+ // shutdown process continues as expected even if a channel re-establish
209+ // happens after one party has already initiated the shutdown.
210+ func runCoopCloseWithHTLCsWithRestartScenario (ht * lntest.HarnessTest , alice ,
211+ bob * node.HarnessNode , testCase flagCombo ) {
162212
163213 ht .ConnectNodes (alice , bob )
164214
@@ -167,8 +217,10 @@ func coopCloseWithHTLCsWithRestart(ht *lntest.HarnessTest, alice,
167217 // so that we can assert that the correct delivery address gets used by
168218 // the channel close initiator.
169219 chanPoint := ht .OpenChannel (bob , alice , lntest.OpenChannelParams {
170- Amt : btcutil .Amount (1000000 ),
171- PushAmt : btcutil .Amount (1000000 / 2 ),
220+ Amt : btcutil .Amount (1000000 ),
221+ PushAmt : btcutil .Amount (1000000 / 2 ),
222+ CommitmentType : testCase .commitType ,
223+ Private : testCase .private ,
172224 })
173225
174226 // Wait for Bob to understand that the channel is ready to use.
0 commit comments