@@ -3,14 +3,18 @@ package itest
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "testing"
6
7
7
8
"github.com/btcsuite/btcd/chaincfg/chainhash"
8
9
"github.com/btcsuite/btcd/wire"
10
+ "github.com/lightninglabs/taproot-assets/taprpc"
9
11
"github.com/lightningnetwork/lnd/channeldb"
10
12
"github.com/lightningnetwork/lnd/lnrpc"
13
+ "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
11
14
"github.com/lightningnetwork/lnd/lntest"
12
15
"github.com/lightningnetwork/lnd/lntest/wait"
13
16
"github.com/stretchr/testify/require"
17
+ "google.golang.org/protobuf/proto"
14
18
)
15
19
16
20
// shutdownAndAssert shuts down the given node and asserts that no errors
@@ -172,24 +176,25 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
172
176
// block.
173
177
block := mineBlocks (t , net , 1 , 1 )[0 ]
174
178
175
- closingTxid , err := net .WaitForChannelClose (closeUpdates )
179
+ closingUpdate , err := net .WaitForChannelClose (closeUpdates )
176
180
require .NoError (t .t , err , "error while waiting for channel close" )
177
181
182
+ closingTxid , err := chainhash .NewHash (closingUpdate .ClosingTxid )
183
+ require .NoError (t .t , err )
178
184
assertTxInBlock (t , block , closingTxid )
179
185
180
186
// Finally, the transaction should no longer be in the waiting close
181
187
// state as we've just mined a block that should include the closing
182
188
// transaction.
183
189
err = wait .Predicate (func () bool {
184
- pendingChansRequest := & lnrpc.PendingChannelsRequest {}
185
- pendingChanResp , err := node .PendingChannels (
186
- ctx , pendingChansRequest ,
190
+ resp , err := node .PendingChannels (
191
+ ctx , & lnrpc.PendingChannelsRequest {},
187
192
)
188
193
if err != nil {
189
194
return false
190
195
}
191
196
192
- for _ , pendingClose := range pendingChanResp .WaitingCloseChannels {
197
+ for _ , pendingClose := range resp .WaitingCloseChannels {
193
198
if pendingClose .Channel .ChannelPoint == chanPointStr {
194
199
return false
195
200
}
@@ -203,3 +208,34 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
203
208
204
209
return closingTxid
205
210
}
211
+
212
+ func assertSweepExists (t * testing.T , node * HarnessNode ,
213
+ witnessType walletrpc.WitnessType ) {
214
+
215
+ ctxb := context .Background ()
216
+ err := wait .NoError (func () error {
217
+ pendingSweeps , err := node .WalletKitClient .PendingSweeps (
218
+ ctxb , & walletrpc.PendingSweepsRequest {},
219
+ )
220
+ if err != nil {
221
+ return err
222
+ }
223
+
224
+ for _ , sweep := range pendingSweeps .PendingSweeps {
225
+ if sweep .WitnessType == witnessType {
226
+ return nil
227
+ }
228
+ }
229
+
230
+ return fmt .Errorf ("failed to find second level sweep: %v" ,
231
+ toProtoJSON (t , pendingSweeps ))
232
+ }, defaultTimeout )
233
+ require .NoError (t , err )
234
+ }
235
+
236
+ func toProtoJSON (t * testing.T , resp proto.Message ) string {
237
+ jsonBytes , err := taprpc .ProtoJSONMarshalOpts .Marshal (resp )
238
+ require .NoError (t , err )
239
+
240
+ return string (jsonBytes )
241
+ }
0 commit comments