@@ -67,11 +67,18 @@ func assertBatchState(t *testing.T, batch *tapgarden.MintingBatch,
6767 require .Equal (t , state , batch .State ())
6868}
6969
70+ func assertBatchSibling (t * testing.T , batch * tapgarden.MintingBatch ,
71+ sibling chainhash.Hash ) {
72+
73+ require .Equal (t , sibling [:], batch .TapSibling ())
74+ }
75+
7076func assertBatchEqual (t * testing.T , a , b * tapgarden.MintingBatch ) {
7177 t .Helper ()
7278
7379 require .Equal (t , a .CreationTime .Unix (), b .CreationTime .Unix ())
7480 require .Equal (t , a .State (), b .State ())
81+ require .Equal (t , a .TapSibling (), b .TapSibling ())
7582 require .Equal (t , a .BatchKey , b .BatchKey )
7683 require .Equal (t , a .Seedlings , b .Seedlings )
7784 require .Equal (t , a .GenesisPacket , b .GenesisPacket )
@@ -329,6 +336,22 @@ func addRandGroupToBatch(t *testing.T, store *AssetMintingStore,
329336 return genesisAmt , seedlingGroups , group
330337}
331338
339+ // addRandSiblingToBatch generates a random hash and adds it to the given batch.
340+ func addRandSiblingToBatch (t * testing.T , batch * tapgarden.MintingBatch ) (
341+ commitment.TapscriptPreimage , chainhash.Hash ) {
342+
343+ tapSiblingSingleLeaf := test .RandTapLeaf (nil )
344+ siblingPreimage , err := commitment .NewPreimageFromLeaf (
345+ tapSiblingSingleLeaf ,
346+ )
347+ require .NoError (t , err )
348+ tapSibling , err := siblingPreimage .TapHash ()
349+ require .NoError (t , err )
350+ batch .UpdateTapSibling (tapSibling )
351+
352+ return * siblingPreimage , * tapSibling
353+ }
354+
332355// addMultiAssetGroupToBatch selects a random seedling pair, where neither
333356// seedling is being issued into an existing group, and creates a multi-asset
334357// group. Specifically, one seedling will have emission enabled, and the other
@@ -384,6 +407,7 @@ func TestCommitMintingBatchSeedlings(t *testing.T) {
384407 // be a reissuance into a specific group.
385408 mintingBatch := tapgarden .RandSeedlingMintingBatch (t , numSeedlings )
386409 addRandGroupToBatch (t , assetStore , ctx , mintingBatch .Seedlings )
410+ _ , randSiblingHash := addRandSiblingToBatch (t , mintingBatch )
387411 err := assetStore .CommitMintingBatch (ctx , mintingBatch )
388412 require .NoError (t , err )
389413
@@ -394,6 +418,7 @@ func TestCommitMintingBatchSeedlings(t *testing.T) {
394418 mintingBatches := noError1 (t , assetStore .FetchNonFinalBatches , ctx )
395419 assertSeedlingBatchLen (t , mintingBatches , 1 , numSeedlings )
396420 assertBatchEqual (t , mintingBatch , mintingBatches [0 ])
421+ assertBatchSibling (t , mintingBatch , randSiblingHash )
397422
398423 mintingBatchKeyed , err := assetStore .FetchMintingBatch (ctx , batchKey )
399424 require .NoError (t , err )
@@ -740,13 +765,16 @@ func TestAddSproutsToBatch(t *testing.T) {
740765}
741766
742767type randAssetCtx struct {
743- batchKey * btcec.PublicKey
744- groupKey * btcec.PublicKey
745- groupGenAmt uint64
746- genesisPkt * tapgarden.FundedPsbt
747- scriptRoot []byte
748- assetRoot * commitment.TapCommitment
749- mintingBatch * tapgarden.MintingBatch
768+ batchKey * btcec.PublicKey
769+ groupKey * btcec.PublicKey
770+ groupGenAmt uint64
771+ genesisPkt * tapgarden.FundedPsbt
772+ assetRoot * commitment.TapCommitment
773+ merkleRoot []byte
774+ scriptRoot []byte
775+ tapSiblingBytes []byte
776+ tapSiblingHash chainhash.Hash
777+ mintingBatch * tapgarden.MintingBatch
750778}
751779
752780func addRandAssets (t * testing.T , ctx context.Context ,
@@ -756,6 +784,7 @@ func addRandAssets(t *testing.T, ctx context.Context,
756784 genAmt , seedlingGroups , group := addRandGroupToBatch (
757785 t , assetStore , ctx , mintingBatch .Seedlings ,
758786 )
787+ randSibling , randSiblingHash := addRandSiblingToBatch (t , mintingBatch )
759788 batchKey := mintingBatch .BatchKey .PubKey
760789 require .NoError (t , assetStore .CommitMintingBatch (ctx , mintingBatch ))
761790
@@ -769,16 +798,24 @@ func addRandAssets(t *testing.T, ctx context.Context,
769798 ctx , batchKey , genesisPacket , assetRoot ,
770799 ))
771800
801+ merkleRoot := assetRoot .TapscriptRoot (& randSiblingHash )
772802 scriptRoot := assetRoot .TapscriptRoot (nil )
803+ siblingBytes , _ , err := commitment .MaybeEncodeTapscriptPreimage (
804+ & randSibling ,
805+ )
806+ require .NoError (t , err )
773807
774808 return randAssetCtx {
775- batchKey : batchKey ,
776- groupKey : & group .GroupKey .GroupPubKey ,
777- groupGenAmt : genAmt ,
778- genesisPkt : genesisPacket ,
779- scriptRoot : scriptRoot [:],
780- assetRoot : assetRoot ,
781- mintingBatch : mintingBatch ,
809+ batchKey : batchKey ,
810+ groupKey : & group .GroupKey .GroupPubKey ,
811+ groupGenAmt : genAmt ,
812+ genesisPkt : genesisPacket ,
813+ assetRoot : assetRoot ,
814+ merkleRoot : merkleRoot [:],
815+ scriptRoot : scriptRoot [:],
816+ tapSiblingBytes : siblingBytes ,
817+ tapSiblingHash : randSiblingHash ,
818+ mintingBatch : mintingBatch ,
782819 }
783820}
784821
@@ -812,7 +849,8 @@ func TestCommitBatchChainActions(t *testing.T) {
812849 // alongside any managed UTXOs.
813850 require .NoError (t , assetStore .CommitSignedGenesisTx (
814851 ctx , randAssetCtx .batchKey , randAssetCtx .genesisPkt , 2 ,
815- randAssetCtx .scriptRoot ,
852+ randAssetCtx .merkleRoot , randAssetCtx .scriptRoot ,
853+ randAssetCtx .tapSiblingBytes ,
816854 ))
817855
818856 // The batch updated above should be found, with the batch state
@@ -825,6 +863,7 @@ func TestCommitBatchChainActions(t *testing.T) {
825863 assertPsbtEqual (
826864 t , randAssetCtx .genesisPkt , mintingBatches [0 ].GenesisPacket ,
827865 )
866+ assertBatchSibling (t , mintingBatches [0 ], randAssetCtx .tapSiblingHash )
828867
829868 var rawTxBytes bytes.Buffer
830869 rawGenTx , err := psbt .Extract (randAssetCtx .genesisPkt .Pkt )
@@ -849,7 +888,11 @@ func TestCommitBatchChainActions(t *testing.T) {
849888 TxnID : sqlInt64 (dbGenTx .TxnID ),
850889 })
851890 require .NoError (t , err )
852- require .Equal (t , randAssetCtx .scriptRoot , managedUTXO .MerkleRoot )
891+ require .Equal (t , randAssetCtx .merkleRoot , managedUTXO .MerkleRoot )
892+ require .Equal (t , randAssetCtx .scriptRoot , managedUTXO .TaprootAssetRoot )
893+ require .Equal (
894+ t , randAssetCtx .tapSiblingBytes , managedUTXO .TapscriptSibling ,
895+ )
853896
854897 // Next, we'll confirm that all the assets inserted previously now are
855898 // able to be queried according to the anchor UTXO primary key.
0 commit comments