@@ -7,15 +7,20 @@ import (
7
7
"github.com/btcsuite/btcd/btcutil"
8
8
"github.com/lightningnetwork/lnd/lnrpc"
9
9
"github.com/lightningnetwork/lnd/lntest"
10
+ "github.com/lightningnetwork/lnd/lntest/node"
10
11
"github.com/lightningnetwork/lnd/lntest/wait"
11
12
"github.com/stretchr/testify/require"
12
13
)
13
14
14
15
func testCoopCloseWithExternalDelivery (ht * lntest.HarnessTest ) {
16
+ alice := ht .NewNodeWithCoins ("Alice" , nil )
17
+ bob := ht .NewNodeWithCoins ("bob" , nil )
18
+ ht .ConnectNodes (alice , bob )
19
+
15
20
ok := ht .Run ("set P2WPKH delivery address at open" , func (t * testing.T ) {
16
- tt := ht .Subtest (t )
17
21
testCoopCloseWithExternalDeliveryImpl (
18
- tt , true , lnrpc .AddressType_UNUSED_WITNESS_PUBKEY_HASH ,
22
+ ht , alice , bob , true ,
23
+ lnrpc .AddressType_UNUSED_WITNESS_PUBKEY_HASH ,
19
24
)
20
25
})
21
26
// Abort the test if failed.
@@ -24,9 +29,9 @@ func testCoopCloseWithExternalDelivery(ht *lntest.HarnessTest) {
24
29
}
25
30
26
31
ok = ht .Run ("set P2WPKH delivery address at close" , func (t * testing.T ) {
27
- tt := ht .Subtest (t )
28
32
testCoopCloseWithExternalDeliveryImpl (
29
- tt , false , lnrpc .AddressType_UNUSED_WITNESS_PUBKEY_HASH ,
33
+ ht , alice , bob , false ,
34
+ lnrpc .AddressType_UNUSED_WITNESS_PUBKEY_HASH ,
30
35
)
31
36
})
32
37
// Abort the test if failed.
@@ -35,9 +40,9 @@ func testCoopCloseWithExternalDelivery(ht *lntest.HarnessTest) {
35
40
}
36
41
37
42
ok = ht .Run ("set P2TR delivery address at open" , func (t * testing.T ) {
38
- tt := ht .Subtest (t )
39
43
testCoopCloseWithExternalDeliveryImpl (
40
- tt , true , lnrpc .AddressType_UNUSED_TAPROOT_PUBKEY ,
44
+ ht , alice , bob , true ,
45
+ lnrpc .AddressType_UNUSED_TAPROOT_PUBKEY ,
41
46
)
42
47
})
43
48
// Abort the test if failed.
@@ -46,9 +51,9 @@ func testCoopCloseWithExternalDelivery(ht *lntest.HarnessTest) {
46
51
}
47
52
48
53
ht .Run ("set P2TR delivery address at close" , func (t * testing.T ) {
49
- tt := ht .Subtest (t )
50
54
testCoopCloseWithExternalDeliveryImpl (
51
- tt , false , lnrpc .AddressType_UNUSED_TAPROOT_PUBKEY ,
55
+ ht , alice , bob , false ,
56
+ lnrpc .AddressType_UNUSED_TAPROOT_PUBKEY ,
52
57
)
53
58
})
54
59
}
@@ -58,11 +63,8 @@ func testCoopCloseWithExternalDelivery(ht *lntest.HarnessTest) {
58
63
// not. Some users set this value to be an address in a different wallet and
59
64
// this should not affect our ability to accurately report the settled balance.
60
65
func testCoopCloseWithExternalDeliveryImpl (ht * lntest.HarnessTest ,
61
- upfrontShutdown bool , deliveryAddressType lnrpc.AddressType ) {
62
-
63
- alice := ht .NewNodeWithCoins ("Alice" , nil )
64
- bob := ht .NewNodeWithCoins ("bob" , nil )
65
- ht .ConnectNodes (alice , bob )
66
+ alice , bob * node.HarnessNode , upfrontShutdown bool ,
67
+ deliveryAddressType lnrpc.AddressType ) {
66
68
67
69
// Here we generate a final delivery address in bob's wallet but set by
68
70
// alice. We do this to ensure that the address is not in alice's LND
@@ -121,11 +123,22 @@ func testCoopCloseWithExternalDeliveryImpl(ht *lntest.HarnessTest,
121
123
Cooperative : true ,
122
124
})
123
125
124
- if len (closed .Channels ) == 0 {
126
+ // Find our channel. We do not recreate alice and bob between
127
+ // testCoopCloseWithExternalDeliveryImpl calls.
128
+ var closedChannel * lnrpc.ChannelCloseSummary
129
+ chanPointStr := ht .OutPointFromChannelPoint (chanPoint ).String ()
130
+ for _ , summary := range closed .Channels {
131
+ if summary .ChannelPoint == chanPointStr {
132
+ closedChannel = summary
133
+ break
134
+ }
135
+ }
136
+
137
+ if closedChannel == nil {
125
138
return fmt .Errorf ("expected closed channel not found" )
126
139
}
127
140
128
- if closed . Channels [ 0 ] .SettledBalance == 0 {
141
+ if closedChannel .SettledBalance == 0 {
129
142
return fmt .Errorf ("expected settled balance to be zero" )
130
143
}
131
144
0 commit comments