@@ -473,9 +473,9 @@ func assertPendingChannels(t *testing.T, node *HarnessNode,
473473 pendingChan .Channel .CustomChannelData , & pendingJSON ,
474474 )
475475 require .NoError (t , err )
476- require .Len (t , pendingJSON .Assets , 1 )
476+ require .Len (t , pendingJSON .FundingAssets , 1 )
477477
478- require .NotZero (t , pendingJSON .Assets [ 0 ]. Capacity )
478+ require .NotZero (t , pendingJSON .Capacity )
479479
480480 // Check the decimal display of the channel funding blob. If no explicit
481481 // value was set, we assume and expect the value of 0.
@@ -488,7 +488,7 @@ func assertPendingChannels(t *testing.T, node *HarnessNode,
488488
489489 require .Equal (
490490 t , expectedDecimalDisplay ,
491- pendingJSON .Assets [0 ]. AssetInfo .DecimalDisplay ,
491+ pendingJSON .FundingAssets [0 ].DecimalDisplay ,
492492 )
493493
494494 // Check the balance of the pending channel.
@@ -501,21 +501,36 @@ func assertPendingChannels(t *testing.T, node *HarnessNode,
501501 require .EqualValues (t , remoteSum , pendingRemoteBalance )
502502}
503503
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+
504519func assertAssetChan (t * testing.T , src , dst * HarnessNode , fundingAmount uint64 ,
505520 mintedAsset * taprpc.Asset ) {
506521
507- assetID := mintedAsset .AssetGenesis .AssetId
508- assetIDStr := hex .EncodeToString (assetID )
509522 err := wait .NoError (func () error {
510523 a , err := getChannelCustomData (src , dst )
511524 if err != nil {
512525 return err
513526 }
514527
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 )
518532 }
533+
519534 if a .Capacity != fundingAmount {
520535 return fmt .Errorf ("expected capacity %d, got %d" ,
521536 fundingAmount , a .Capacity )
@@ -530,10 +545,10 @@ func assertAssetChan(t *testing.T, src, dst *HarnessNode, fundingAmount uint64,
530545 )
531546 }
532547
533- if a .AssetInfo .DecimalDisplay != expectedDecimalDisplay {
548+ if a .FundingAssets [ 0 ] .DecimalDisplay != expectedDecimalDisplay {
534549 return fmt .Errorf ("expected decimal display %d, got %d" ,
535550 expectedDecimalDisplay ,
536- a .AssetInfo .DecimalDisplay )
551+ a .FundingAssets [ 0 ] .DecimalDisplay )
537552 }
538553
539554 return nil
@@ -580,7 +595,7 @@ func assertChannelKnown(t *testing.T, node *HarnessNode,
580595 require .NoError (t , err )
581596}
582597
583- func getChannelCustomData (src , dst * HarnessNode ) (* rfqmsg.JsonAssetChanInfo ,
598+ func getChannelCustomData (src , dst * HarnessNode ) (* rfqmsg.JsonAssetChannel ,
584599 error ) {
585600
586601 ctxb := context .Background ()
@@ -614,12 +629,12 @@ func getChannelCustomData(src, dst *HarnessNode) (*rfqmsg.JsonAssetChanInfo,
614629 err )
615630 }
616631
617- if len (assetData .Assets ) != 1 {
632+ if len (assetData .FundingAssets ) != 1 {
618633 return nil , fmt .Errorf ("expected 1 asset, got %d" ,
619- len (assetData .Assets ))
634+ len (assetData .FundingAssets ))
620635 }
621636
622- return & assetData . Assets [ 0 ] , nil
637+ return & assetData , nil
623638}
624639
625640func getAssetChannelBalance (t * testing.T , node * HarnessNode , assetID []byte ,
@@ -706,10 +721,10 @@ func assertChannelAssetBalance(t *testing.T, node *HarnessNode,
706721 err := json .Unmarshal (targetChan .CustomChannelData , & assetBalance )
707722 require .NoError (t , err )
708723
709- require .Len (t , assetBalance .Assets , 1 )
724+ require .Len (t , assetBalance .FundingAssets , 1 )
710725
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 )
713728}
714729
715730// addRoutingFee adds the default routing fee (1 part per million fee rate plus
@@ -1385,6 +1400,9 @@ func closeAssetChannelAndAssert(t *harnessTest, net *NetworkHarness,
13851400 )
13861401 require .NoError (t .t , err )
13871402
1403+ assertWaitingCloseChannelAssetData (t .t , local , chanPoint )
1404+ assertWaitingCloseChannelAssetData (t .t , remote , chanPoint )
1405+
13881406 mineBlocks (t , net , 1 , 1 )
13891407
13901408 closeUpdate , err := t .lndHarness .WaitForChannelClose (closeStream )
@@ -1405,6 +1423,9 @@ func closeAssetChannelAndAssert(t *harnessTest, net *NetworkHarness,
14051423 t .t , local , remote , closeTx , closeUpdate , assetID , groupKey ,
14061424 universeTap ,
14071425 )
1426+
1427+ assertClosedChannelAssetData (t .t , local , chanPoint )
1428+ assertClosedChannelAssetData (t .t , remote , chanPoint )
14081429}
14091430
14101431// assertDefaultCoOpCloseBalance returns a default implementation of the co-op
@@ -2128,8 +2149,8 @@ func newCloseExpiryInfo(t *testing.T, node *HarnessNode) forceCloseExpiryInfo {
21282149 csvDelay : mainChan .CsvDelay ,
21292150 currentHeight : nodeInfo .BlockHeight ,
21302151 cltvDelays : cltvs ,
2131- localAssetBalance : assetData .Assets [ 0 ]. LocalBalance ,
2132- remoteAssetBalance : assetData .Assets [ 0 ]. RemoteBalance ,
2152+ localAssetBalance : assetData .LocalBalance ,
2153+ remoteAssetBalance : assetData .RemoteBalance ,
21332154 t : t ,
21342155 node : node ,
21352156 }
@@ -2200,3 +2221,143 @@ func assertInvoiceState(t *testing.T, hn *HarnessNode, payAddr []byte,
22002221 }, defaultTimeout )
22012222 require .NoError (t , err , "timeout waiting for invoice settled state" )
22022223}
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