@@ -473,9 +473,9 @@ func assertPendingChannels(t *testing.T, node *HarnessNode,
473
473
pendingChan .Channel .CustomChannelData , & pendingJSON ,
474
474
)
475
475
require .NoError (t , err )
476
- require .Len (t , pendingJSON .Assets , 1 )
476
+ require .Len (t , pendingJSON .FundingAssets , 1 )
477
477
478
- require .NotZero (t , pendingJSON .Assets [ 0 ]. Capacity )
478
+ require .NotZero (t , pendingJSON .Capacity )
479
479
480
480
// Check the decimal display of the channel funding blob. If no explicit
481
481
// value was set, we assume and expect the value of 0.
@@ -488,7 +488,7 @@ func assertPendingChannels(t *testing.T, node *HarnessNode,
488
488
489
489
require .Equal (
490
490
t , expectedDecimalDisplay ,
491
- pendingJSON .Assets [0 ]. AssetInfo .DecimalDisplay ,
491
+ pendingJSON .FundingAssets [0 ].DecimalDisplay ,
492
492
)
493
493
494
494
// Check the balance of the pending channel.
@@ -501,21 +501,36 @@ func assertPendingChannels(t *testing.T, node *HarnessNode,
501
501
require .EqualValues (t , remoteSum , pendingRemoteBalance )
502
502
}
503
503
504
+ // haveFundingAsset returns true if the given channel has the asset with the
505
+ // given asset ID as a funding asset.
506
+ func haveFundingAsset (assetChannel * rfqmsg.JsonAssetChannel ,
507
+ assetID []byte ) bool {
508
+
509
+ assetIDStr := hex .EncodeToString (assetID )
510
+ for _ , fundingAsset := range assetChannel .FundingAssets {
511
+ if fundingAsset .AssetGenesis .AssetID == assetIDStr {
512
+ return true
513
+ }
514
+ }
515
+
516
+ return false
517
+ }
518
+
504
519
func assertAssetChan (t * testing.T , src , dst * HarnessNode , fundingAmount uint64 ,
505
520
mintedAsset * taprpc.Asset ) {
506
521
507
- assetID := mintedAsset .AssetGenesis .AssetId
508
- assetIDStr := hex .EncodeToString (assetID )
509
522
err := wait .NoError (func () error {
510
523
a , err := getChannelCustomData (src , dst )
511
524
if err != nil {
512
525
return err
513
526
}
514
527
515
- if a .AssetInfo .AssetGenesis .AssetID != assetIDStr {
516
- return fmt .Errorf ("expected asset ID %s, got %s" ,
517
- assetIDStr , a .AssetInfo .AssetGenesis .AssetID )
528
+ assetID := mintedAsset .AssetGenesis .AssetId
529
+ if ! haveFundingAsset (a , assetID ) {
530
+ return fmt .Errorf ("expected asset ID %x, to " +
531
+ "be in channel" , assetID )
518
532
}
533
+
519
534
if a .Capacity != fundingAmount {
520
535
return fmt .Errorf ("expected capacity %d, got %d" ,
521
536
fundingAmount , a .Capacity )
@@ -530,10 +545,10 @@ func assertAssetChan(t *testing.T, src, dst *HarnessNode, fundingAmount uint64,
530
545
)
531
546
}
532
547
533
- if a .AssetInfo .DecimalDisplay != expectedDecimalDisplay {
548
+ if a .FundingAssets [ 0 ] .DecimalDisplay != expectedDecimalDisplay {
534
549
return fmt .Errorf ("expected decimal display %d, got %d" ,
535
550
expectedDecimalDisplay ,
536
- a .AssetInfo .DecimalDisplay )
551
+ a .FundingAssets [ 0 ] .DecimalDisplay )
537
552
}
538
553
539
554
return nil
@@ -580,7 +595,7 @@ func assertChannelKnown(t *testing.T, node *HarnessNode,
580
595
require .NoError (t , err )
581
596
}
582
597
583
- func getChannelCustomData (src , dst * HarnessNode ) (* rfqmsg.JsonAssetChanInfo ,
598
+ func getChannelCustomData (src , dst * HarnessNode ) (* rfqmsg.JsonAssetChannel ,
584
599
error ) {
585
600
586
601
ctxb := context .Background ()
@@ -614,12 +629,12 @@ func getChannelCustomData(src, dst *HarnessNode) (*rfqmsg.JsonAssetChanInfo,
614
629
err )
615
630
}
616
631
617
- if len (assetData .Assets ) != 1 {
632
+ if len (assetData .FundingAssets ) != 1 {
618
633
return nil , fmt .Errorf ("expected 1 asset, got %d" ,
619
- len (assetData .Assets ))
634
+ len (assetData .FundingAssets ))
620
635
}
621
636
622
- return & assetData . Assets [ 0 ] , nil
637
+ return & assetData , nil
623
638
}
624
639
625
640
func getAssetChannelBalance (t * testing.T , node * HarnessNode , assetID []byte ,
@@ -706,10 +721,10 @@ func assertChannelAssetBalance(t *testing.T, node *HarnessNode,
706
721
err := json .Unmarshal (targetChan .CustomChannelData , & assetBalance )
707
722
require .NoError (t , err )
708
723
709
- require .Len (t , assetBalance .Assets , 1 )
724
+ require .Len (t , assetBalance .FundingAssets , 1 )
710
725
711
- require .InDelta (t , local , assetBalance .Assets [ 0 ]. LocalBalance , 1 )
712
- require .InDelta (t , remote , assetBalance .Assets [ 0 ]. RemoteBalance , 1 )
726
+ require .InDelta (t , local , assetBalance .LocalBalance , 1 )
727
+ require .InDelta (t , remote , assetBalance .RemoteBalance , 1 )
713
728
}
714
729
715
730
// addRoutingFee adds the default routing fee (1 part per million fee rate plus
@@ -1385,6 +1400,9 @@ func closeAssetChannelAndAssert(t *harnessTest, net *NetworkHarness,
1385
1400
)
1386
1401
require .NoError (t .t , err )
1387
1402
1403
+ assertWaitingCloseChannelAssetData (t .t , local , chanPoint )
1404
+ assertWaitingCloseChannelAssetData (t .t , remote , chanPoint )
1405
+
1388
1406
mineBlocks (t , net , 1 , 1 )
1389
1407
1390
1408
closeUpdate , err := t .lndHarness .WaitForChannelClose (closeStream )
@@ -1405,6 +1423,9 @@ func closeAssetChannelAndAssert(t *harnessTest, net *NetworkHarness,
1405
1423
t .t , local , remote , closeTx , closeUpdate , assetID , groupKey ,
1406
1424
universeTap ,
1407
1425
)
1426
+
1427
+ assertClosedChannelAssetData (t .t , local , chanPoint )
1428
+ assertClosedChannelAssetData (t .t , remote , chanPoint )
1408
1429
}
1409
1430
1410
1431
// assertDefaultCoOpCloseBalance returns a default implementation of the co-op
@@ -2128,8 +2149,8 @@ func newCloseExpiryInfo(t *testing.T, node *HarnessNode) forceCloseExpiryInfo {
2128
2149
csvDelay : mainChan .CsvDelay ,
2129
2150
currentHeight : nodeInfo .BlockHeight ,
2130
2151
cltvDelays : cltvs ,
2131
- localAssetBalance : assetData .Assets [ 0 ]. LocalBalance ,
2132
- remoteAssetBalance : assetData .Assets [ 0 ]. RemoteBalance ,
2152
+ localAssetBalance : assetData .LocalBalance ,
2153
+ remoteAssetBalance : assetData .RemoteBalance ,
2133
2154
t : t ,
2134
2155
node : node ,
2135
2156
}
@@ -2200,3 +2221,143 @@ func assertInvoiceState(t *testing.T, hn *HarnessNode, payAddr []byte,
2200
2221
}, defaultTimeout )
2201
2222
require .NoError (t , err , "timeout waiting for invoice settled state" )
2202
2223
}
2224
+
2225
+ type pendingChan = lnrpc.PendingChannelsResponse_PendingChannel
2226
+
2227
+ // assertWaitingCloseChannelAssetData asserts that the waiting close channel has
2228
+ // the expected asset data.
2229
+ func assertPendingChannelAssetData (t * testing.T , node * HarnessNode ,
2230
+ chanPoint * lnrpc.ChannelPoint , find func (string ,
2231
+ * lnrpc.PendingChannelsResponse ) (* pendingChan , error )) {
2232
+
2233
+ ctxb := context .Background ()
2234
+
2235
+ err := wait .NoError (func () error {
2236
+ // Make sure we can find the closed channel in the channel
2237
+ // database.
2238
+ pendingChannels , err := node .PendingChannels (
2239
+ ctxb , & lnrpc.PendingChannelsRequest {},
2240
+ )
2241
+ if err != nil {
2242
+ return err
2243
+ }
2244
+
2245
+ targetChanPointStr := fmt .Sprintf ("%v:%v" ,
2246
+ chanPoint .GetFundingTxidStr (),
2247
+ chanPoint .GetOutputIndex ())
2248
+
2249
+ targetChan , err := find (targetChanPointStr , pendingChannels )
2250
+ if err != nil {
2251
+ return err
2252
+ }
2253
+
2254
+ if len (targetChan .CustomChannelData ) == 0 {
2255
+ return fmt .Errorf ("pending channel %s has no " +
2256
+ "custom channel data" , targetChanPointStr )
2257
+ }
2258
+
2259
+ var closeData rfqmsg.JsonAssetChannel
2260
+ err = json .Unmarshal (targetChan .CustomChannelData , & closeData )
2261
+ if err != nil {
2262
+ return fmt .Errorf ("error unmarshalling custom channel " +
2263
+ "data: %v" , err )
2264
+ }
2265
+
2266
+ if len (closeData .FundingAssets ) != 1 {
2267
+ return fmt .Errorf ("expected 1 funding asset, got %d" ,
2268
+ len (closeData .FundingAssets ))
2269
+ }
2270
+
2271
+ return nil
2272
+ }, defaultTimeout )
2273
+ require .NoError (t , err , "timeout waiting for pending channel" )
2274
+ }
2275
+
2276
+ // assertPendingForceCloseChannelAssetData asserts that the pending force close
2277
+ // channel has the expected asset data.
2278
+ func assertPendingForceCloseChannelAssetData (t * testing.T , node * HarnessNode ,
2279
+ chanPoint * lnrpc.ChannelPoint ) {
2280
+
2281
+ assertPendingChannelAssetData (
2282
+ t , node , chanPoint , func (chanPoint string ,
2283
+ resp * lnrpc.PendingChannelsResponse ) (* pendingChan ,
2284
+ error ) {
2285
+
2286
+ if len (resp .PendingForceClosingChannels ) == 0 {
2287
+ return nil , fmt .Errorf ("no pending force close " +
2288
+ "channels found" )
2289
+ }
2290
+
2291
+ for _ , ch := range resp .PendingForceClosingChannels {
2292
+ if ch .Channel .ChannelPoint == chanPoint {
2293
+ return ch .Channel , nil
2294
+ }
2295
+ }
2296
+
2297
+ return nil , fmt .Errorf ("pending channel %s not found" ,
2298
+ chanPoint )
2299
+ },
2300
+ )
2301
+ }
2302
+
2303
+ // assertWaitingCloseChannelAssetData asserts that the waiting close channel has
2304
+ // the expected asset data.
2305
+ func assertWaitingCloseChannelAssetData (t * testing.T , node * HarnessNode ,
2306
+ chanPoint * lnrpc.ChannelPoint ) {
2307
+
2308
+ assertPendingChannelAssetData (
2309
+ t , node , chanPoint , func (chanPoint string ,
2310
+ resp * lnrpc.PendingChannelsResponse ) (* pendingChan ,
2311
+ error ) {
2312
+
2313
+ if len (resp .WaitingCloseChannels ) == 0 {
2314
+ return nil , fmt .Errorf ("no waiting close " +
2315
+ "channels found" )
2316
+ }
2317
+
2318
+ for _ , ch := range resp .WaitingCloseChannels {
2319
+ if ch .Channel .ChannelPoint == chanPoint {
2320
+ return ch .Channel , nil
2321
+ }
2322
+ }
2323
+
2324
+ return nil , fmt .Errorf ("pending channel %s not found" ,
2325
+ chanPoint )
2326
+ },
2327
+ )
2328
+ }
2329
+
2330
+ // assertClosedChannelAssetData asserts that the closed channel has the expected
2331
+ // asset data.
2332
+ func assertClosedChannelAssetData (t * testing.T , node * HarnessNode ,
2333
+ chanPoint * lnrpc.ChannelPoint ) {
2334
+
2335
+ ctxb := context .Background ()
2336
+
2337
+ // Make sure we can find the closed channel in the channel database.
2338
+ closedChannels , err := node .ClosedChannels (
2339
+ ctxb , & lnrpc.ClosedChannelsRequest {},
2340
+ )
2341
+ require .NoError (t , err )
2342
+
2343
+ require .NotEmpty (t , closedChannels .Channels )
2344
+
2345
+ targetChanPointStr := fmt .Sprintf ("%v:%v" ,
2346
+ chanPoint .GetFundingTxidStr (), chanPoint .GetOutputIndex ())
2347
+
2348
+ var closedChan * lnrpc.ChannelCloseSummary
2349
+ for _ , ch := range closedChannels .Channels {
2350
+ if ch .ChannelPoint == targetChanPointStr {
2351
+ closedChan = ch
2352
+ break
2353
+ }
2354
+ }
2355
+ require .NotNil (t , closedChan )
2356
+ require .NotEmpty (t , closedChan .CustomChannelData )
2357
+
2358
+ var closeData rfqmsg.JsonAssetChannel
2359
+ err = json .Unmarshal (closedChan .CustomChannelData , & closeData )
2360
+ require .NoError (t , err )
2361
+
2362
+ require .GreaterOrEqual (t , len (closeData .FundingAssets ), 1 )
2363
+ }
0 commit comments