Skip to content

Commit 1961583

Browse files
ffranrdarioAnongba
authored andcommitted
itest: add AssertSupplyLeafBlockHeaders helper for issuance and burn
Add a new test helper function, AssertSupplyLeafBlockHeaders, which verifies that expected values appear in the unirpc.SupplyLeafBlockHeader message returned from the FetchSupplyLeaves RPC endpoint. Use this helper for issuance and burn events to confirm that block data is available for these new supply leaves. A later commit will extend this check to the supply leaf ignore type.
1 parent fac0840 commit 1961583

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

itest/assertions.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,3 +2882,20 @@ func WaitForSupplyCommit(t *testing.T, ctx context.Context,
28822882

28832883
return fetchResp, supplyCommitOutpoint
28842884
}
2885+
2886+
// AssertSupplyLeafBlockHeaders makes sure that the given block header exists
2887+
// in the map of block headers and that its contents matches the expected
2888+
// values.
2889+
func AssertSupplyLeafBlockHeaders(t *testing.T, expectedBlockHeight uint32,
2890+
expectedTimestamp int64, expectedBlockHash chainhash.Hash,
2891+
actualBlockHeaders map[uint32]*unirpc.SupplyLeafBlockHeader) {
2892+
2893+
actualBlockMeta, ok := actualBlockHeaders[expectedBlockHeight]
2894+
require.True(t, ok, "no block header for height %d",
2895+
expectedBlockHeight)
2896+
2897+
require.EqualValues(
2898+
t, fn.ByteSlice(expectedBlockHash), actualBlockMeta.Hash,
2899+
)
2900+
require.EqualValues(t, expectedTimestamp, actualBlockMeta.Timestamp)
2901+
}

itest/supply_commit_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/lightninglabs/taproot-assets/fn"
1818
"github.com/lightninglabs/taproot-assets/itest/rpcassert"
1919
"github.com/lightninglabs/taproot-assets/mssmt"
20+
"github.com/lightninglabs/taproot-assets/proof"
2021
"github.com/lightninglabs/taproot-assets/tapgarden"
2122
"github.com/lightninglabs/taproot-assets/taprpc"
2223
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
@@ -1105,6 +1106,30 @@ func testFetchSupplyLeaves(t *harnessTest) {
11051106
"issuance leaf amount mismatch",
11061107
)
11071108

1109+
actualMintEvent := new(supplycommit.NewMintEvent)
1110+
err = actualMintEvent.Decode(bytes.NewReader(issuanceLeaf1.RawLeaf))
1111+
require.NoError(t.t, err)
1112+
1113+
// Compare the issuance leaf proof block details with those given in
1114+
// *unirpc.SupplyLeafBlockHeader message field.
1115+
//
1116+
// Decode the block header from the issuance raw proof.
1117+
var actualBlockHeader wire.BlockHeader
1118+
err = proof.SparseDecode(
1119+
bytes.NewReader(actualMintEvent.IssuanceProof.RawProof),
1120+
proof.BlockHeaderRecord(&actualBlockHeader),
1121+
)
1122+
require.NoError(t.t, err)
1123+
1124+
proofBlockHeight := actualMintEvent.BlockHeight()
1125+
proofBlockTimestamp := actualBlockHeader.Timestamp.Unix()
1126+
proofBlockHash := actualBlockHeader.BlockHash()
1127+
1128+
AssertSupplyLeafBlockHeaders(
1129+
t.t, proofBlockHeight, proofBlockTimestamp, proofBlockHash,
1130+
leavesResp1.BlockHeaders,
1131+
)
1132+
11081133
t.Log("Burning portion of the asset")
11091134
const (
11101135
burnAmt = 1500
@@ -1177,6 +1202,24 @@ func testFetchSupplyLeaves(t *harnessTest) {
11771202
require.EqualValues(t.t, burnAmt, burnLeaf.LeafNode.RootSum,
11781203
"burn leaf amount mismatch")
11791204

1205+
// Compare the burn leaf proof block details with those given in
1206+
// *unirpc.SupplyLeafBlockHeader message field.
1207+
//
1208+
// Decode the burn raw proof.
1209+
actualBurnEvent := new(supplycommit.NewBurnEvent)
1210+
err = actualBurnEvent.Decode(bytes.NewReader(burnLeaf.RawLeaf))
1211+
require.NoError(t.t, err)
1212+
1213+
proofBlockHeight = actualBurnEvent.BurnProof.BlockHeight
1214+
proofBlockTimestamp =
1215+
actualBurnEvent.BurnProof.BlockHeader.Timestamp.Unix()
1216+
proofBlockHash = actualBurnEvent.BurnProof.BlockHeader.BlockHash()
1217+
1218+
AssertSupplyLeafBlockHeaders(
1219+
t.t, proofBlockHeight, proofBlockTimestamp, proofBlockHash,
1220+
leavesResp2.BlockHeaders,
1221+
)
1222+
11801223
t.Log("Minting second tranche into the same asset group")
11811224
secondMintReq := &mintrpc.MintAssetRequest{
11821225
Asset: &mintrpc.MintAsset{

0 commit comments

Comments
 (0)