@@ -21,6 +21,7 @@ import (
21
21
"github.com/lightninglabs/taproot-assets/tapdb/sqlc"
22
22
"github.com/lightninglabs/taproot-assets/tapgarden"
23
23
"github.com/lightninglabs/taproot-assets/tapscript"
24
+ "github.com/lightninglabs/taproot-assets/vm"
24
25
"github.com/lightningnetwork/lnd/build"
25
26
"github.com/lightningnetwork/lnd/clock"
26
27
"github.com/lightningnetwork/lnd/keychain"
@@ -332,7 +333,7 @@ func seedlingsToAssetRoot(t *testing.T, genesisPoint wire.OutPoint,
332
333
groupKeys map [string ]* btcec.PrivateKey ) * commitment.TapCommitment {
333
334
334
335
orderedSeedlings := tapgarden .SortSeedlings (maps .Values (seedlings ))
335
- assetRoots := make ([]* commitment. AssetCommitment , 0 , len (seedlings ))
336
+ newAssets := make ([]* asset. Asset , 0 , len (seedlings ))
336
337
newGroupPrivs := make (map [string ]* btcec.PrivateKey )
337
338
newGroupInfo := make (map [string ]* asset.AssetGroup )
338
339
@@ -421,17 +422,18 @@ func seedlingsToAssetRoot(t *testing.T, genesisPoint wire.OutPoint,
421
422
)
422
423
require .NoError (t , err )
423
424
424
- // Finally make a new asset commitment (the inner SMT tree) for
425
- // this newly created asset.
426
- assetRoot , err := commitment .NewAssetCommitment (
427
- newAsset ,
428
- )
429
- require .NoError (t , err )
425
+ if groupKey != nil {
426
+ engine , err := vm .New (newAsset , nil , nil )
427
+ require .NoError (t , err )
428
+
429
+ err = engine .Execute ()
430
+ require .NoError (t , err )
431
+ }
430
432
431
- assetRoots = append (assetRoots , assetRoot )
433
+ newAssets = append (newAssets , newAsset )
432
434
}
433
435
434
- tapCommitment , err := commitment .NewTapCommitment ( assetRoots ... )
436
+ tapCommitment , err := commitment .FromAssets ( newAssets ... )
435
437
require .NoError (t , err )
436
438
437
439
return tapCommitment
@@ -1059,6 +1061,9 @@ func TestGroupAnchors(t *testing.T) {
1059
1061
ctx := context .Background ()
1060
1062
const numSeedlings = 10
1061
1063
assetStore , _ , _ := newAssetStore (t )
1064
+ groupVerifier := tapgarden .GenGroupVerifier (ctx , assetStore )
1065
+ groupAnchorVerifier := tapgarden .GenGroupAnchorVerifier (ctx , assetStore )
1066
+ rawGroupAnchorVerifier := tapgarden .GenRawGroupAnchorVerifier (ctx )
1062
1067
1063
1068
// First, we'll write a new minting batch to disk, including an
1064
1069
// internal key and a set of seedlings. One random seedling will
@@ -1113,6 +1118,19 @@ func TestGroupAnchors(t *testing.T) {
1113
1118
)
1114
1119
seedlings [secondGrouped ].GroupAnchor = & secondAnchor
1115
1120
1121
+ // Record the number of seedlings set as group anchors and members.
1122
+ // These counts should not change after sprouting.
1123
+ batchSeedlings := maps .Values (mintingBatch .Seedlings )
1124
+ isGroupAnchor := func (s * tapgarden.Seedling ) bool {
1125
+ return s .EnableEmission == true
1126
+ }
1127
+ isGroupMember := func (s * tapgarden.Seedling ) bool {
1128
+ return s .GroupAnchor != nil || s .GroupInfo != nil
1129
+ }
1130
+
1131
+ anchorCount := fn .Count (batchSeedlings , isGroupAnchor )
1132
+ memberCount := fn .Count (batchSeedlings , isGroupMember )
1133
+
1116
1134
// Now we'll map these seedlings to an asset commitment and insert them
1117
1135
// into the DB as sprouts.
1118
1136
genesisPacket := randGenesisPacket (t )
@@ -1135,6 +1153,30 @@ func TestGroupAnchors(t *testing.T) {
1135
1153
assertBatchState (t , mintingBatches [0 ], tapgarden .BatchStateCommitted )
1136
1154
assertPsbtEqual (t , genesisPacket , mintingBatches [0 ].GenesisPacket )
1137
1155
assertAssetsEqual (t , assetRoot , mintingBatches [0 ].RootAssetCommitment )
1156
+
1157
+ // Check that the number of group anchors and members matches the batch
1158
+ // state when frozen.
1159
+ storedAssets := mintingBatches [0 ].RootAssetCommitment .CommittedAssets ()
1160
+ groupedAssets := fn .Filter (storedAssets , func (a * asset.Asset ) bool {
1161
+ return a .GroupKey != nil
1162
+ })
1163
+ require .Equal (t , anchorCount + memberCount , len (groupedAssets ))
1164
+ require .True (t , fn .All (groupedAssets , func (a * asset.Asset ) bool {
1165
+ return groupVerifier (& a .GroupKey .GroupPubKey ) == nil
1166
+ }))
1167
+
1168
+ // Both group anchor verifiers must return the same result.
1169
+ groupAnchors := fn .Filter (groupedAssets , func (a * asset.Asset ) bool {
1170
+ return groupAnchorVerifier (& a .Genesis , a .GroupKey ) == nil
1171
+ })
1172
+ require .Equal (t , anchorCount , len (groupAnchors ))
1173
+
1174
+ rawGroupAnchors := fn .Filter (groupAnchors , func (a * asset.Asset ) bool {
1175
+ return rawGroupAnchorVerifier (& a .Genesis , a .GroupKey ) == nil
1176
+ })
1177
+ require .Equal (t , anchorCount , len (rawGroupAnchors ))
1178
+ require .Equal (t , groupAnchors , rawGroupAnchors )
1179
+
1138
1180
}
1139
1181
1140
1182
func init () {
0 commit comments