Skip to content

Commit 2a30f86

Browse files
committed
tapdb: use group verifiers in tests
1 parent 2efdfb9 commit 2a30f86

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

tapdb/asset_minting_test.go

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,9 @@ func seedlingsToAssetRoot(t *testing.T, genesisPoint wire.OutPoint,
421421
)
422422
require.NoError(t, err)
423423

424-
// Finally make a new asset commitment (the inner SMT tree) for
424+
// Finally, make a new asset commitment (the inner SMT tree) for
425425
// this newly created asset.
426-
assetRoot, err := commitment.NewAssetCommitment(
427-
newAsset,
428-
)
426+
assetRoot, err := commitment.NewAssetCommitment(newAsset)
429427
require.NoError(t, err)
430428

431429
assetRoots = append(assetRoots, assetRoot)
@@ -1059,6 +1057,9 @@ func TestGroupAnchors(t *testing.T) {
10591057
ctx := context.Background()
10601058
const numSeedlings = 10
10611059
assetStore, _, _ := newAssetStore(t)
1060+
groupVerifier := tapgarden.GenGroupVerifier(ctx, assetStore)
1061+
groupAnchorVerifier := tapgarden.GenGroupAnchorVerifier(ctx, assetStore)
1062+
rawGroupAnchorVerifier := tapgarden.GenRawGroupAnchorVerifier(ctx)
10621063

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

1117+
// Record the number of seedlings set as group anchors and members.
1118+
// These counts should not change after sprouting.
1119+
batchSeedlings := maps.Values(mintingBatch.Seedlings)
1120+
isGroupAnchor := func(s *tapgarden.Seedling) bool {
1121+
return s.EnableEmission == true
1122+
}
1123+
isGroupMember := func(s *tapgarden.Seedling) bool {
1124+
return s.GroupAnchor != nil || s.GroupInfo != nil
1125+
}
1126+
1127+
anchorCount := fn.Count(batchSeedlings, isGroupAnchor)
1128+
memberCount := fn.Count(batchSeedlings, isGroupMember)
1129+
11161130
// Now we'll map these seedlings to an asset commitment and insert them
11171131
// into the DB as sprouts.
11181132
genesisPacket := randGenesisPacket(t)
@@ -1135,6 +1149,29 @@ func TestGroupAnchors(t *testing.T) {
11351149
assertBatchState(t, mintingBatches[0], tapgarden.BatchStateCommitted)
11361150
assertPsbtEqual(t, genesisPacket, mintingBatches[0].GenesisPacket)
11371151
assertAssetsEqual(t, assetRoot, mintingBatches[0].RootAssetCommitment)
1152+
1153+
// Check that the number of group anchors and members matches the batch
1154+
// state when frozen.
1155+
storedAssets := mintingBatches[0].RootAssetCommitment.CommittedAssets()
1156+
groupedAssets := fn.Filter(storedAssets, func(a *asset.Asset) bool {
1157+
return a.GroupKey != nil
1158+
})
1159+
require.Equal(t, anchorCount+memberCount, len(groupedAssets))
1160+
require.True(t, fn.All(groupedAssets, func(a *asset.Asset) bool {
1161+
return groupVerifier(&a.GroupKey.GroupPubKey) == nil
1162+
}))
1163+
1164+
// Both group anchor verifiers must return the same result.
1165+
groupAnchors := fn.Filter(groupedAssets, func(a *asset.Asset) bool {
1166+
return groupAnchorVerifier(&a.Genesis, a.GroupKey) == nil
1167+
})
1168+
require.Equal(t, anchorCount, len(groupAnchors))
1169+
1170+
rawGroupAnchors := fn.Filter(groupAnchors, func(a *asset.Asset) bool {
1171+
return rawGroupAnchorVerifier(&a.Genesis, a.GroupKey) == nil
1172+
})
1173+
require.Equal(t, anchorCount, len(rawGroupAnchors))
1174+
require.Equal(t, groupAnchors, rawGroupAnchors)
11381175
}
11391176

11401177
func init() {

0 commit comments

Comments
 (0)