@@ -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"
@@ -1044,7 +1045,9 @@ func testSupplyCommitMintBurn(t *harnessTest) {
10441045// 4. Calling FetchSupplyLeaves to verify burn leaves are included.
10451046// 5. Minting another tranche into the same group.
10461047// 6. Calling FetchSupplyLeaves to verify all leaves are present.
1047- // 7. Testing inclusion proof generation for various leaf types.
1048+ // 7. Ignoring an asset outpoint from the second mint.
1049+ // 8. Calling FetchSupplyLeaves to verify ignore leaves are included.
1050+ // 9. Testing inclusion proof generation for various leaf types.
10481051func testFetchSupplyLeaves (t * harnessTest ) {
10491052 ctxb := context .Background ()
10501053
@@ -1105,6 +1108,30 @@ func testFetchSupplyLeaves(t *harnessTest) {
11051108 "issuance leaf amount mismatch" ,
11061109 )
11071110
1111+ actualMintEvent := new (supplycommit.NewMintEvent )
1112+ err = actualMintEvent .Decode (bytes .NewReader (issuanceLeaf1 .RawLeaf ))
1113+ require .NoError (t .t , err )
1114+
1115+ // Compare the issuance leaf proof block details with those given in
1116+ // *unirpc.SupplyLeafBlockHeader message field.
1117+ //
1118+ // Decode the block header from the issuance raw proof.
1119+ var actualBlockHeader wire.BlockHeader
1120+ err = proof .SparseDecode (
1121+ bytes .NewReader (actualMintEvent .IssuanceProof .RawProof ),
1122+ proof .BlockHeaderRecord (& actualBlockHeader ),
1123+ )
1124+ require .NoError (t .t , err )
1125+
1126+ proofBlockHeight := actualMintEvent .BlockHeight ()
1127+ proofBlockTimestamp := actualBlockHeader .Timestamp .Unix ()
1128+ proofBlockHash := actualBlockHeader .BlockHash ()
1129+
1130+ AssertSupplyLeafBlockHeaders (
1131+ t .t , proofBlockHeight , proofBlockTimestamp , proofBlockHash ,
1132+ leavesResp1 .BlockHeaders ,
1133+ )
1134+
11081135 t .Log ("Burning portion of the asset" )
11091136 const (
11101137 burnAmt = 1500
@@ -1177,6 +1204,24 @@ func testFetchSupplyLeaves(t *harnessTest) {
11771204 require .EqualValues (t .t , burnAmt , burnLeaf .LeafNode .RootSum ,
11781205 "burn leaf amount mismatch" )
11791206
1207+ // Compare the burn leaf proof block details with those given in
1208+ // *unirpc.SupplyLeafBlockHeader message field.
1209+ //
1210+ // Decode the burn raw proof.
1211+ actualBurnEvent := new (supplycommit.NewBurnEvent )
1212+ err = actualBurnEvent .Decode (bytes .NewReader (burnLeaf .RawLeaf ))
1213+ require .NoError (t .t , err )
1214+
1215+ proofBlockHeight = actualBurnEvent .BurnProof .BlockHeight
1216+ proofBlockTimestamp =
1217+ actualBurnEvent .BurnProof .BlockHeader .Timestamp .Unix ()
1218+ proofBlockHash = actualBurnEvent .BurnProof .BlockHeader .BlockHash ()
1219+
1220+ AssertSupplyLeafBlockHeaders (
1221+ t .t , proofBlockHeight , proofBlockTimestamp , proofBlockHash ,
1222+ leavesResp2 .BlockHeaders ,
1223+ )
1224+
11801225 t .Log ("Minting second tranche into the same asset group" )
11811226 secondMintReq := & mintrpc.MintAssetRequest {
11821227 Asset : & mintrpc.MintAsset {
@@ -1216,7 +1261,7 @@ func testFetchSupplyLeaves(t *harnessTest) {
12161261 expectedIssuanceTotal := int64 (
12171262 mintReq .Asset .Amount + secondMintReq .Asset .Amount ,
12181263 )
1219- _ , _ = WaitForSupplyCommit (
1264+ _ , supplyOutpoint = WaitForSupplyCommit (
12201265 t .t , ctxb , t .tapd , groupKeyBytes , fn .Some (supplyOutpoint ),
12211266 func (resp * unirpc.FetchSupplyCommitResponse ) bool {
12221267 return resp .IssuanceSubtreeRoot != nil &&
@@ -1259,6 +1304,103 @@ func testFetchSupplyLeaves(t *harnessTest) {
12591304 "total issuance amount mismatch" ,
12601305 )
12611306
1307+ t .Log ("Ignoring an asset outpoint from the second mint" )
1308+
1309+ // Get the outpoint from the second minted asset to ignore it.
1310+ // We must ignore the entire asset at the outpoint, not just a portion.
1311+ ignoreAmount := rpcSecondAsset [0 ].Amount
1312+ ignoreAssetOutpoint := taprpc.AssetOutPoint {
1313+ AnchorOutPoint : rpcSecondAsset [0 ].ChainAnchor .AnchorOutpoint ,
1314+ AssetId : rpcSecondAsset [0 ].AssetGenesis .AssetId ,
1315+ ScriptKey : rpcSecondAsset [0 ].ScriptKey ,
1316+ }
1317+ ignoreReq := & unirpc.IgnoreAssetOutPointRequest {
1318+ AssetOutPoint : & ignoreAssetOutpoint ,
1319+ Amount : ignoreAmount ,
1320+ }
1321+
1322+ respIgnore , err := t .tapd .IgnoreAssetOutPoint (ctxb , ignoreReq )
1323+ require .NoError (t .t , err )
1324+ require .NotNil (t .t , respIgnore )
1325+ require .EqualValues (t .t , ignoreAmount , respIgnore .Leaf .RootSum )
1326+
1327+ t .Log ("Updating supply commitment after ignoring asset outpoint" )
1328+ UpdateAndMineSupplyCommit (
1329+ t .t , ctxb , t .tapd , t .lndHarness .Miner ().Client ,
1330+ groupKeyBytes , 1 ,
1331+ )
1332+
1333+ t .Log ("Wait for the supply commitment to include the ignored outpoint." )
1334+ _ , _ = WaitForSupplyCommit (
1335+ t .t , ctxb , t .tapd , groupKeyBytes , fn .Some (supplyOutpoint ),
1336+ func (resp * unirpc.FetchSupplyCommitResponse ) bool {
1337+ if resp .IgnoreSubtreeRoot == nil {
1338+ return false
1339+ }
1340+
1341+ return resp .IgnoreSubtreeRoot .RootNode .RootSum ==
1342+ int64 (ignoreAmount )
1343+ },
1344+ )
1345+
1346+ t .Log ("Fetching supply leaves after ignoring asset outpoint" )
1347+ req = unirpc.FetchSupplyLeavesRequest {
1348+ GroupKey : & unirpc.FetchSupplyLeavesRequest_GroupKeyBytes {
1349+ GroupKeyBytes : groupKeyBytes ,
1350+ },
1351+ }
1352+ leavesResp4 , err := t .tapd .FetchSupplyLeaves (ctxb , & req )
1353+ require .NoError (t .t , err )
1354+ require .NotNil (t .t , leavesResp4 )
1355+
1356+ // Verify we have two issuance leaves, one burn leaf, and one ignore
1357+ // leaf.
1358+ require .Len (
1359+ t .t , leavesResp4 .IssuanceLeaves , 2 ,
1360+ "expected 2 issuance leaves after ignore" ,
1361+ )
1362+ require .Len (
1363+ t .t , leavesResp4 .BurnLeaves , 1 ,
1364+ "expected 1 burn leaf after ignore" ,
1365+ )
1366+ require .Len (
1367+ t .t , leavesResp4 .IgnoreLeaves , 1 ,
1368+ "expected 1 ignore leaf after ignore" ,
1369+ )
1370+
1371+ // Verify the ignore leaf amount.
1372+ ignoreLeaf := leavesResp4 .IgnoreLeaves [0 ]
1373+ require .EqualValues (
1374+ t .t , ignoreAmount , ignoreLeaf .LeafNode .RootSum ,
1375+ "ignore leaf amount mismatch" ,
1376+ )
1377+
1378+ // Compare the ignore leaf block data with that given in
1379+ // *unirpc.SupplyLeafBlockHeader message field.
1380+ //
1381+ // TODO(ffranr): Extend t.lndHarness.Miner() with
1382+ // GetBlockHeaderByHeight and use here.
1383+ //
1384+ // We can't retrieve the block header from the miner based on block
1385+ // height, so we fetch it given the block hash in the field we are
1386+ // testing. This is not ideal, but it covers timestamp and height
1387+ // verification.
1388+ expectedBlockHeight := ignoreLeaf .BlockHeight
1389+ ignoreLeafBlockHeader :=
1390+ leavesResp4 .BlockHeaders [expectedBlockHeight ]
1391+
1392+ ignoreBlockHash , err := chainhash .NewHash (ignoreLeafBlockHeader .Hash )
1393+ require .NoError (t .t , err )
1394+
1395+ ignoreLeafBlock := t .lndHarness .Miner ().GetBlock (ignoreBlockHash )
1396+ require .NotNil (t .t , ignoreLeafBlock )
1397+ expectedBlockTimestamp := ignoreLeafBlock .Header .Timestamp .Unix ()
1398+
1399+ AssertSupplyLeafBlockHeaders (
1400+ t .t , expectedBlockHeight , expectedBlockTimestamp ,
1401+ * ignoreBlockHash , leavesResp4 .BlockHeaders ,
1402+ )
1403+
12621404 t .Log ("Testing inclusion proof generation for supply leaves" )
12631405
12641406 // Collect leaf keys for inclusion proof request.
0 commit comments