Skip to content

Commit 6a438e6

Browse files
committed
tapdb: use group verifiers in tests
1 parent 9e000d3 commit 6a438e6

File tree

1 file changed

+51
-9
lines changed

1 file changed

+51
-9
lines changed

tapdb/asset_minting_test.go

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/lightninglabs/taproot-assets/tapdb/sqlc"
2222
"github.com/lightninglabs/taproot-assets/tapgarden"
2323
"github.com/lightninglabs/taproot-assets/tapscript"
24+
"github.com/lightninglabs/taproot-assets/vm"
2425
"github.com/lightningnetwork/lnd/build"
2526
"github.com/lightningnetwork/lnd/clock"
2627
"github.com/lightningnetwork/lnd/keychain"
@@ -332,7 +333,7 @@ func seedlingsToAssetRoot(t *testing.T, genesisPoint wire.OutPoint,
332333
groupKeys map[string]*btcec.PrivateKey) *commitment.TapCommitment {
333334

334335
orderedSeedlings := tapgarden.SortSeedlings(maps.Values(seedlings))
335-
assetRoots := make([]*commitment.AssetCommitment, 0, len(seedlings))
336+
newAssets := make([]*asset.Asset, 0, len(seedlings))
336337
newGroupPrivs := make(map[string]*btcec.PrivateKey)
337338
newGroupInfo := make(map[string]*asset.AssetGroup)
338339

@@ -421,17 +422,18 @@ func seedlingsToAssetRoot(t *testing.T, genesisPoint wire.OutPoint,
421422
)
422423
require.NoError(t, err)
423424

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+
}
430432

431-
assetRoots = append(assetRoots, assetRoot)
433+
newAssets = append(newAssets, newAsset)
432434
}
433435

434-
tapCommitment, err := commitment.NewTapCommitment(assetRoots...)
436+
tapCommitment, err := commitment.FromAssets(newAssets...)
435437
require.NoError(t, err)
436438

437439
return tapCommitment
@@ -1059,6 +1061,9 @@ func TestGroupAnchors(t *testing.T) {
10591061
ctx := context.Background()
10601062
const numSeedlings = 10
10611063
assetStore, _, _ := newAssetStore(t)
1064+
groupVerifier := tapgarden.GenGroupVerifier(ctx, assetStore)
1065+
groupAnchorVerifier := tapgarden.GenGroupAnchorVerifier(ctx, assetStore)
1066+
rawGroupAnchorVerifier := tapgarden.GenRawGroupAnchorVerifier(ctx)
10621067

10631068
// First, we'll write a new minting batch to disk, including an
10641069
// internal key and a set of seedlings. One random seedling will
@@ -1113,6 +1118,19 @@ func TestGroupAnchors(t *testing.T) {
11131118
)
11141119
seedlings[secondGrouped].GroupAnchor = &secondAnchor
11151120

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+
11161134
// Now we'll map these seedlings to an asset commitment and insert them
11171135
// into the DB as sprouts.
11181136
genesisPacket := randGenesisPacket(t)
@@ -1135,6 +1153,30 @@ func TestGroupAnchors(t *testing.T) {
11351153
assertBatchState(t, mintingBatches[0], tapgarden.BatchStateCommitted)
11361154
assertPsbtEqual(t, genesisPacket, mintingBatches[0].GenesisPacket)
11371155
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+
11381180
}
11391181

11401182
func init() {

0 commit comments

Comments
 (0)