Skip to content

Commit a21e4eb

Browse files
committed
itest: use ListBurns in burn test
1 parent 47e7875 commit a21e4eb

File tree

1 file changed

+90
-1
lines changed

1 file changed

+90
-1
lines changed

itest/burn_test.go

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package itest
22

33
import (
4+
"bytes"
45
"context"
56
"encoding/hex"
67

@@ -129,12 +130,17 @@ func testBurnAssets(t *harnessTest) {
129130
// Test case 2: We'll now try to burn a small amount of assets, which
130131
// should select the largest output, which is located alone in an anchor
131132
// output.
132-
const burnAmt = 100
133+
const (
134+
burnAmt = 100
135+
burnNote = "blazeit"
136+
)
137+
133138
burnResp, err := t.tapd.BurnAsset(ctxt, &taprpc.BurnAssetRequest{
134139
Asset: &taprpc.BurnAssetRequest_AssetId{
135140
AssetId: simpleAssetID[:],
136141
},
137142
AmountToBurn: burnAmt,
143+
Note: burnNote,
138144
ConfirmationText: taprootassets.AssetBurnConfirmationText,
139145
})
140146
require.NoError(t.t, err)
@@ -169,6 +175,16 @@ func testBurnAssets(t *harnessTest) {
169175
t.t, t.tapd, simpleAssetGen.AssetId, simpleAsset.Amount-burnAmt,
170176
)
171177

178+
burns, err := t.tapd.ListBurns(ctxt, &taprpc.ListBurnsRequest{})
179+
require.NoError(t.t, err)
180+
181+
require.Len(t.t, burns.Burns, 1)
182+
burn := burns.Burns[0]
183+
require.Equal(t.t, uint64(burnAmt), burn.Amount)
184+
require.Equal(t.t, burnResp.BurnTransfer.AnchorTxHash, burn.AnchorTxid)
185+
require.Equal(t.t, burn.AssetId, simpleAssetID[:])
186+
require.Equal(t.t, burn.Note, burnNote)
187+
172188
// The burned asset should be pruned from the tree when we next spend
173189
// the anchor output it was in (together with the change). So let's test
174190
// that we can successfully spend the change output.
@@ -280,6 +296,35 @@ func testBurnAssets(t *harnessTest) {
280296
t.t, t.tapd, simpleGroupGen.AssetId, simpleGroup.Amount-burnAmt,
281297
)
282298

299+
burns, err = t.tapd.ListBurns(ctxt, &taprpc.ListBurnsRequest{})
300+
require.NoError(t.t, err)
301+
302+
require.Len(t.t, burns.Burns, 4)
303+
var groupBurn *taprpc.AssetBurn
304+
for _, b := range burns.Burns {
305+
if bytes.Equal(b.AssetId, simpleGroupGen.AssetId) {
306+
groupBurn = b
307+
}
308+
}
309+
310+
// Keep track of the txhash of the anchor transaction that completed
311+
// this transfer. This will be used later to query burns with a txhash
312+
// filter.
313+
groupBurnTxHash := burnResp.BurnTransfer.AnchorTxHash
314+
315+
require.Equal(t.t, uint64(burnAmt), groupBurn.Amount)
316+
require.Equal(
317+
t.t, burnResp.BurnTransfer.AnchorTxHash, groupBurn.AnchorTxid,
318+
)
319+
320+
require.Equal(t.t, groupBurn.AssetId, simpleGroupGen.AssetId[:])
321+
require.Equal(
322+
t.t, groupBurn.TweakedGroupKey,
323+
simpleGroup.AssetGroup.TweakedGroupKey,
324+
)
325+
326+
require.Equal(t.t, groupBurn.Note, "")
327+
283328
// Test case 6: Burn the single unit of a grouped collectible. We start
284329
// by making sure we still have the full balance before burning.
285330
AssertBalanceByID(
@@ -305,6 +350,36 @@ func testBurnAssets(t *harnessTest) {
305350
simpleGroupCollectGen.AssetId, []uint64{1}, 6, 7, 1, true,
306351
)
307352
AssertBalanceByID(t.t, t.tapd, simpleGroupCollectGen.AssetId, 0)
353+
354+
// We now perform some queries to test the filters of the ListBurns
355+
// call.
356+
357+
// Fetch the burns related to the simple asset id, which should have a
358+
// total of 2 burns (tc1 & tc4).
359+
burns, err = t.tapd.ListBurns(ctxt, &taprpc.ListBurnsRequest{
360+
AssetId: simpleAssetGen.AssetId,
361+
})
362+
require.NoError(t.t, err)
363+
364+
require.Len(t.t, burns.Burns, 2)
365+
366+
// Fetch the burns related to the group key of the grouped asset in tc5.
367+
// There should be 1 burn.
368+
burns, err = t.tapd.ListBurns(ctxt, &taprpc.ListBurnsRequest{
369+
TweakedGroupKey: simpleGroup.AssetGroup.TweakedGroupKey,
370+
})
371+
require.NoError(t.t, err)
372+
373+
require.Len(t.t, burns.Burns, 1)
374+
375+
// Fetch the burns associated with the txhash of the burn in tc5. There
376+
// should be 1 burn returned.
377+
burns, err = t.tapd.ListBurns(ctxt, &taprpc.ListBurnsRequest{
378+
AnchorTxid: groupBurnTxHash,
379+
})
380+
require.NoError(t.t, err)
381+
382+
require.Len(t.t, burns.Burns, 1)
308383
}
309384

310385
// testBurnGroupedAssets tests that some amount of an asset from an asset group
@@ -315,6 +390,7 @@ func testBurnGroupedAssets(t *harnessTest) {
315390
miner = t.lndHarness.Miner().Client
316391

317392
firstMintReq = issuableAssets[0]
393+
burnNote = "blazeit"
318394
)
319395

320396
// We start off without any asset groups.
@@ -376,6 +452,7 @@ func testBurnGroupedAssets(t *harnessTest) {
376452
AssetId: burnAssetID,
377453
},
378454
AmountToBurn: burnAmt,
455+
Note: burnNote,
379456
ConfirmationText: taprootassets.AssetBurnConfirmationText,
380457
})
381458
require.NoError(t.t, err)
@@ -414,4 +491,16 @@ func testBurnGroupedAssets(t *harnessTest) {
414491
encodedGroupKey = hex.EncodeToString(assetGroupKey)
415492
assetGroup = assetGroups.Groups[encodedGroupKey]
416493
require.Len(t.t, assetGroup.Assets, 2)
494+
495+
burns, err := t.tapd.ListBurns(ctxb, &taprpc.ListBurnsRequest{
496+
TweakedGroupKey: assetGroupKey,
497+
})
498+
require.NoError(t.t, err)
499+
require.Len(t.t, burns.Burns, 1)
500+
501+
burn := burns.Burns[0]
502+
503+
require.Equal(t.t, burnAmt, burn.Amount)
504+
require.Equal(t.t, burnNote, burn.Note)
505+
require.Equal(t.t, assetGroupKey, burn.TweakedGroupKey)
417506
}

0 commit comments

Comments
 (0)