@@ -1042,18 +1042,21 @@ func testSupplyCommitMintBurn(t *harnessTest) {
10421042// 5. Ignores the asset outpoint sent to the secondary node.
10431043// 6. Publishes the second supply commitment and mines it.
10441044// 7. Verifies the secondary node can fetch the updated supply commitment.
1045+ // 8. Primary node mints another asset into the group and publishes the
1046+ // third supply commitment.
1047+ // 9. Verifies the secondary node can fetch the third supply commitment.
10451048func testSupplyVerifyPeerNode (t * harnessTest ) {
10461049 ctxb := context .Background ()
10471050
10481051 t .Log ("Minting initial asset group with universe/supply " +
10491052 "commitments enabled" )
10501053
10511054 // Create a mint request for a grouped asset with supply commitments.
1052- mintReq := CopyRequest (issuableAssets [0 ])
1053- mintReq .Asset .Amount = 5000
1055+ firstMintReq := CopyRequest (issuableAssets [0 ])
1056+ firstMintReq .Asset .Amount = 5000
10541057
10551058 rpcFirstAsset , _ := MintAssetWithSupplyCommit (
1056- t , mintReq , fn .None [btcec.PublicKey ](),
1059+ t , firstMintReq , fn .None [btcec.PublicKey ](),
10571060 )
10581061
10591062 // Parse out the group key from the minted asset.
@@ -1077,7 +1080,7 @@ func testSupplyVerifyPeerNode(t *harnessTest) {
10771080 // Verify the issuance subtree root exists and has the correct amount.
10781081 require .NotNil (t .t , fetchResp .IssuanceSubtreeRoot )
10791082 require .Equal (
1080- t .t , int64 (mintReq .Asset .Amount ),
1083+ t .t , int64 (firstMintReq .Asset .Amount ),
10811084 fetchResp .IssuanceSubtreeRoot .RootNode .RootSum ,
10821085 )
10831086
@@ -1125,7 +1128,7 @@ func testSupplyVerifyPeerNode(t *harnessTest) {
11251128 )
11261129
11271130 require .Equal (
1128- t .t , int64 (mintReq .Asset .Amount ),
1131+ t .t , int64 (firstMintReq .Asset .Amount ),
11291132 peerFetchResp .IssuanceSubtreeRoot .RootNode .RootSum ,
11301133 )
11311134
@@ -1160,7 +1163,7 @@ func testSupplyVerifyPeerNode(t *harnessTest) {
11601163
11611164 t .Log ("Verifying retrieval of second supply commitment from primary " +
11621165 "node" )
1163- fetchResp , _ = WaitForSupplyCommit (
1166+ fetchResp , supplyOutpoint = WaitForSupplyCommit (
11641167 t .t , ctxb , t .tapd , groupKeyBytes , fn .Some (supplyOutpoint ),
11651168 func (resp * unirpc.FetchSupplyCommitResponse ) bool {
11661169 ignoreRoot := resp .IgnoreSubtreeRoot
@@ -1265,4 +1268,92 @@ func testSupplyVerifyPeerNode(t *harnessTest) {
12651268 // Verify that the secondary node's supply commitment matches the
12661269 // primary's.
12671270 assertFetchCommitResponse (t , fetchResp , peerFetchResp2 )
1271+
1272+ // Step 8: Primary node mints another asset into the group and publishes
1273+ // the third supply commitment.
1274+ t .Log ("Minting second asset into the same asset group" )
1275+
1276+ secondMintReq := & mintrpc.MintAssetRequest {
1277+ Asset : & mintrpc.MintAsset {
1278+ AssetType : taprpc .AssetType_NORMAL ,
1279+ Name : "itestbuxx-supply-commit-tranche-2" ,
1280+ AssetMeta : & taprpc.AssetMeta {
1281+ Data : []byte ("second tranche metadata" ),
1282+ },
1283+ Amount : 2000 ,
1284+ AssetVersion : taprpc .AssetVersion_ASSET_VERSION_V1 ,
1285+ NewGroupedAsset : false ,
1286+ GroupedAsset : true ,
1287+ GroupKey : groupKeyBytes ,
1288+
1289+ EnableSupplyCommitments : true ,
1290+ },
1291+ }
1292+
1293+ MintAssetWithSupplyCommit (
1294+ t , secondMintReq , fn .None [btcec.PublicKey ](),
1295+ )
1296+
1297+ t .Log ("Updating supply commitment after second mint (creating third " +
1298+ "supply commitment)" )
1299+ UpdateAndMineSupplyCommit (
1300+ t .t , ctxb , t .tapd , t .lndHarness .Miner ().Client ,
1301+ groupKeyBytes , 1 ,
1302+ )
1303+
1304+ // Wait for the third supply commitment to be available.
1305+ expectedTotalAfterSecondMint := int64 (
1306+ firstMintReq .Asset .Amount + secondMintReq .Asset .Amount ,
1307+ )
1308+ var thirdSupplyCommitResp * unirpc.FetchSupplyCommitResponse
1309+ thirdSupplyCommitResp , _ = WaitForSupplyCommit (
1310+ t .t , ctxb , t .tapd , groupKeyBytes , fn .Some (supplyOutpoint ),
1311+ func (resp * unirpc.FetchSupplyCommitResponse ) bool {
1312+ actualRootSum :=
1313+ resp .IssuanceSubtreeRoot .RootNode .RootSum
1314+
1315+ return resp .IssuanceSubtreeRoot != nil &&
1316+ actualRootSum == expectedTotalAfterSecondMint
1317+ },
1318+ )
1319+
1320+ // Step 9: Verify the secondary node can fetch the third supply
1321+ // commitment.
1322+ t .Log ("Verifying secondary node can fetch third supply commitment" )
1323+
1324+ // Verify the secondary node can fetch the third supply commitment.
1325+ peerFetchPred3 := func (resp * unirpc.FetchSupplyCommitResponse ) error {
1326+ if resp .IssuanceSubtreeRoot == nil {
1327+ return fmt .Errorf ("expected issuance subtree root" )
1328+ }
1329+
1330+ // Check if the supply commitment includes the second mint.
1331+ if resp .IssuanceSubtreeRoot .RootNode .RootSum !=
1332+ expectedTotalAfterSecondMint {
1333+
1334+ return fmt .Errorf ("expected RootSum %d, got %d" ,
1335+ expectedTotalAfterSecondMint ,
1336+ resp .IssuanceSubtreeRoot .RootNode .RootSum )
1337+ }
1338+
1339+ return nil
1340+ }
1341+
1342+ // nolint: lll
1343+ req = unirpc.FetchSupplyCommitRequest {
1344+ GroupKey : & unirpc.FetchSupplyCommitRequest_GroupKeyBytes {
1345+ GroupKeyBytes : groupKeyBytes ,
1346+ },
1347+ Locator : & unirpc.FetchSupplyCommitRequest_SpentCommitOutpoint {
1348+ SpentCommitOutpoint : thirdSupplyCommitResp .SpentCommitmentOutpoint ,
1349+ },
1350+ }
1351+
1352+ peerFetchResp3 := rpcassert .FetchSupplyCommitRPC (
1353+ t .t , ctxb , secondTapd , peerFetchPred3 , & req ,
1354+ )
1355+
1356+ // Verify that the secondary node's third supply commitment matches the
1357+ // primary's.
1358+ assertFetchCommitResponse (t , thirdSupplyCommitResp , peerFetchResp3 )
12681359}
0 commit comments