Skip to content

Commit

Permalink
itest: use ListBurns in burn test
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeTsagk committed Nov 13, 2024
1 parent 7e8716a commit b9c8ce7
Showing 1 changed file with 76 additions and 1 deletion.
77 changes: 76 additions & 1 deletion itest/burn_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package itest

import (
"bytes"
"context"
"encoding/hex"

Expand Down Expand Up @@ -129,16 +130,31 @@ func testBurnAssets(t *harnessTest) {
// Test case 2: We'll now try to burn a small amount of assets, which
// should select the largest output, which is located alone in an anchor
// output.
const burnAmt = 100
const (
burnAmt = 100
burnNote = "blazeit"
)

burnResp, err := t.tapd.BurnAsset(ctxt, &taprpc.BurnAssetRequest{
Asset: &taprpc.BurnAssetRequest_AssetId{
AssetId: simpleAssetID[:],
},
AmountToBurn: burnAmt,
Note: burnNote,
ConfirmationText: taprootassets.AssetBurnConfirmationText,
})
require.NoError(t.t, err)

burns, err := t.tapd.ListBurns(ctxt, &taprpc.ListBurnsRequest{})
require.NoError(t.t, err)

require.Len(t.t, burns.Burns, 1)
burn := burns.Burns[0]
require.Equal(t.t, uint64(burnAmt), burn.Amount)
require.Equal(t.t, burnResp.BurnTransfer.AnchorTxHash, burn.AnchorTxid)
require.Equal(t.t, burn.AssetId, simpleAssetID[:])
require.Equal(t.t, burn.Note, burnNote)

burnRespJSON, err := formatProtoJSON(burnResp)
require.NoError(t.t, err)
t.Logf("Got response from burning %d units: %v", burnAmt, burnRespJSON)
Expand Down Expand Up @@ -266,6 +282,35 @@ func testBurnAssets(t *harnessTest) {
})
require.NoError(t.t, err)

burns, err = t.tapd.ListBurns(ctxt, &taprpc.ListBurnsRequest{})
require.NoError(t.t, err)

require.Len(t.t, burns.Burns, 4)
var groupBurn *taprpc.AssetBurn
for _, b := range burns.Burns {
if bytes.Equal(b.AssetId, simpleGroupGen.AssetId) {
groupBurn = b
}
}

// Keep track of the txhash of the anchor transaction that completed
// this transfer. This will be used later to query burns with a txhash
// filter.
groupBurnTxHash := burnResp.BurnTransfer.AnchorTxHash

require.Equal(t.t, uint64(burnAmt), groupBurn.Amount)
require.Equal(
t.t, burnResp.BurnTransfer.AnchorTxHash, groupBurn.AnchorTxid,
)

require.Equal(t.t, groupBurn.AssetId, simpleGroupGen.AssetId[:])
require.Equal(
t.t, groupBurn.TweakedGroupKey,
simpleGroup.AssetGroup.TweakedGroupKey,
)

require.Equal(t.t, groupBurn.Note, "")

burnRespJSON, err = formatProtoJSON(burnResp)
require.NoError(t.t, err)
t.Logf("Got response from burning units from grouped asset: %v",
Expand Down Expand Up @@ -305,6 +350,36 @@ func testBurnAssets(t *harnessTest) {
simpleGroupCollectGen.AssetId, []uint64{1}, 6, 7, 1, true,
)
AssertBalanceByID(t.t, t.tapd, simpleGroupCollectGen.AssetId, 0)

// We now perform some queries to test the filters of the ListBurns
// call.

// Fetch the burns related to the simple asset id, which should have a
// total of 2 burns (tc1 & tc4).
burns, err = t.tapd.ListBurns(ctxt, &taprpc.ListBurnsRequest{
AssetId: simpleAssetGen.AssetId,
})
require.NoError(t.t, err)

require.Len(t.t, burns.Burns, 2)

// Fetch the burns related to the group key of the grouped asset in tc5.
// There should be 1 burn.
burns, err = t.tapd.ListBurns(ctxt, &taprpc.ListBurnsRequest{
TweakedGroupKey: simpleGroup.AssetGroup.TweakedGroupKey,
})
require.NoError(t.t, err)

require.Len(t.t, burns.Burns, 1)

// Fetch the burns associated with the txhash of the burn in tc5. There
// should be 1 burn returned.
burns, err = t.tapd.ListBurns(ctxt, &taprpc.ListBurnsRequest{
AnchorTxid: groupBurnTxHash,
})
require.NoError(t.t, err)

require.Len(t.t, burns.Burns, 1)
}

// testBurnGroupedAssets tests that some amount of an asset from an asset group
Expand Down

0 comments on commit b9c8ce7

Please sign in to comment.