Skip to content

Commit 497c897

Browse files
committed
itest: add coop close assertion for grouped channels
Makes sure we properly assert the final closing balances of coop closed grouped asset channels.
1 parent 71d9650 commit 497c897

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

itest/assets_test.go

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,10 @@ func defaultCoOpCloseBalanceCheck(t *testing.T, local, remote *HarnessNode,
18261826
assetIDs [][]byte, groupKey []byte, universeTap *tapClient,
18271827
remoteBtcBalance, remoteAssetBalance bool) {
18281828

1829+
ctxb := context.Background()
1830+
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
1831+
defer cancel()
1832+
18291833
// With the channel closed, we'll now assert that the co-op close
18301834
// transaction was inserted into the local universe.
18311835
//
@@ -1923,10 +1927,37 @@ func defaultCoOpCloseBalanceCheck(t *testing.T, local, remote *HarnessNode,
19231927
closeTx.TxOut[localAssetIndex].PkScript,
19241928
)
19251929

1930+
// Because we don't exactly know what asset IDs made it into the close
1931+
// transaction, we need to fetch the closed channel to find that out.
1932+
closedChans, err := local.ClosedChannels(
1933+
ctxt, &lnrpc.ClosedChannelsRequest{
1934+
Cooperative: true,
1935+
},
1936+
)
1937+
require.NoError(t, err)
1938+
require.GreaterOrEqual(t, len(closedChans.Channels), 1)
1939+
1940+
var closedJsonChannel *rfqmsg.JsonAssetChannel
1941+
for _, closedChan := range closedChans.Channels {
1942+
if closedChan.ClosingTxHash == closeTx.TxHash().String() {
1943+
closedJsonChannel = &rfqmsg.JsonAssetChannel{}
1944+
err = json.Unmarshal(
1945+
closedChan.CustomChannelData, closedJsonChannel,
1946+
)
1947+
require.NoError(t, err)
1948+
1949+
t.Logf("Closed channel: %v",
1950+
spew.Sdump(closedJsonChannel))
1951+
1952+
break
1953+
}
1954+
}
1955+
require.NotNil(t, closedJsonChannel)
1956+
19261957
// We now verify the arrival of the local balance asset proof at the
19271958
// universe server.
19281959
var localAssetCloseOut rfqmsg.JsonCloseOutput
1929-
err := json.Unmarshal(
1960+
err = json.Unmarshal(
19301961
localCloseOut.CustomChannelData, &localAssetCloseOut,
19311962
)
19321963
require.NoError(t, err)
@@ -1938,6 +1969,22 @@ func defaultCoOpCloseBalanceCheck(t *testing.T, local, remote *HarnessNode,
19381969

19391970
require.Contains(t, assetIDStrings, assetIDStr)
19401971

1972+
// We only check for a proof if an asset of that asset ID was
1973+
// actually in the close output, which might not always be the
1974+
// case in grouped asset channels.
1975+
localAssetIDs := fn.NewSet[string](fn.Map(
1976+
func(t rfqmsg.JsonAssetTranche) string {
1977+
return t.AssetID
1978+
},
1979+
closedJsonChannel.LocalAssets,
1980+
)...)
1981+
if !localAssetIDs.Contains(assetIDStr) {
1982+
continue
1983+
}
1984+
1985+
t.Logf("Is script key %s (asset ID %s) in list of asset IDs "+
1986+
"(%v)?", scriptKeyStr, assetIDStr, localAssetIDs)
1987+
19411988
assetID, err := hex.DecodeString(assetIDStr)
19421989
require.NoError(t, err)
19431990

@@ -1977,6 +2024,19 @@ func defaultCoOpCloseBalanceCheck(t *testing.T, local, remote *HarnessNode,
19772024

19782025
require.Contains(t, assetIDStrings, assetIDStr)
19792026

2027+
// We only check for a proof if an asset of that asset ID was
2028+
// actually in the close output, which might not always be the
2029+
// case in grouped asset channels.
2030+
remoteAssetIDs := fn.NewSet[string](fn.Map(
2031+
func(t rfqmsg.JsonAssetTranche) string {
2032+
return t.AssetID
2033+
},
2034+
closedJsonChannel.RemoteAssets,
2035+
)...)
2036+
if !remoteAssetIDs.Contains(assetIDStr) {
2037+
continue
2038+
}
2039+
19802040
assetID, err := hex.DecodeString(assetIDStr)
19812041
require.NoError(t, err)
19822042

itest/litd_custom_channels_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,10 +1308,7 @@ func testCustomChannelsGroupTranchesForceClose(ctx context.Context,
13081308
closeAssetChannelAndAssert(
13091309
t, net, charlie, dave, chanPointCD,
13101310
[][]byte{assetID1, assetID2}, groupKey, universeTap,
1311-
// TODO(guggero): replace this with
1312-
// assertDefaultCoOpCloseBalance(true, true) once we have the
1313-
// ability to check the custom data in the closed channel list.
1314-
noOpCoOpCloseBalanceCheck,
1311+
assertDefaultCoOpCloseBalance(true, true),
13151312
)
13161313

13171314
assertSpendableBalance(

0 commit comments

Comments
 (0)