@@ -3,14 +3,18 @@ package itest
33import (
44 "context"
55 "fmt"
6+ "testing"
67
78 "github.com/btcsuite/btcd/chaincfg/chainhash"
89 "github.com/btcsuite/btcd/wire"
10+ "github.com/lightninglabs/taproot-assets/taprpc"
911 "github.com/lightningnetwork/lnd/channeldb"
1012 "github.com/lightningnetwork/lnd/lnrpc"
13+ "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
1114 "github.com/lightningnetwork/lnd/lntest"
1215 "github.com/lightningnetwork/lnd/lntest/wait"
1316 "github.com/stretchr/testify/require"
17+ "google.golang.org/protobuf/proto"
1418)
1519
1620// shutdownAndAssert shuts down the given node and asserts that no errors
@@ -172,24 +176,25 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
172176 // block.
173177 block := mineBlocks (t , net , 1 , 1 )[0 ]
174178
175- closingTxid , err := net .WaitForChannelClose (closeUpdates )
179+ closingUpdate , err := net .WaitForChannelClose (closeUpdates )
176180 require .NoError (t .t , err , "error while waiting for channel close" )
177181
182+ closingTxid , err := chainhash .NewHash (closingUpdate .ClosingTxid )
183+ require .NoError (t .t , err )
178184 assertTxInBlock (t , block , closingTxid )
179185
180186 // Finally, the transaction should no longer be in the waiting close
181187 // state as we've just mined a block that should include the closing
182188 // transaction.
183189 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 {},
187192 )
188193 if err != nil {
189194 return false
190195 }
191196
192- for _ , pendingClose := range pendingChanResp .WaitingCloseChannels {
197+ for _ , pendingClose := range resp .WaitingCloseChannels {
193198 if pendingClose .Channel .ChannelPoint == chanPointStr {
194199 return false
195200 }
@@ -203,3 +208,34 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
203208
204209 return closingTxid
205210}
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