Skip to content

Commit

Permalink
tapdb: add unit test for asset group version 1
Browse files Browse the repository at this point in the history
Add TestAssetGroupV1 to verify the ability to store and load an
asset group of version 1.
  • Loading branch information
ffranr committed Jan 15, 2025
1 parent 3ff703b commit c4a9222
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tapdb/assets_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,59 @@ func TestAssetGroupComplexWitness(t *testing.T) {
require.True(t, groupKey.IsEqual(storedGroup.GroupKey))
}

// TestAssetGroupV1 tests that we can store and load an asset group version 1.
func TestAssetGroupV1(t *testing.T) {
t.Parallel()

mintingStore, assetStore, db := newAssetStore(t)
ctx := context.Background()

internalKey := test.RandPubKey(t)
groupAnchorGen := asset.RandGenesis(t, asset.RandAssetType(t))
groupAnchorGen.MetaHash = [32]byte{}
tapscriptRoot := test.RandBytes(32)
customTapscriptRoot := test.RandHash()
groupSig := test.RandBytes(64)

// First, we'll insert all the required rows we need to satisfy the
// foreign key constraints needed to insert a new genesis witness.
genesisPointID, err := upsertGenesisPoint(
ctx, db, groupAnchorGen.FirstPrevOut,
)
require.NoError(t, err)

genAssetID, err := upsertGenesis(
ctx, db, genesisPointID, groupAnchorGen,
)
require.NoError(t, err)

groupKey := asset.GroupKey{
Version: asset.GroupKeyV1,
RawKey: keychain.KeyDescriptor{
PubKey: internalKey,
},
GroupPubKey: *internalKey,
TapscriptRoot: tapscriptRoot,
CustomTapscriptRoot: fn.Some[chainhash.Hash](
customTapscriptRoot,
),
Witness: fn.MakeSlice(tapscriptRoot, groupSig),
}

_, err = upsertGroupKey(
ctx, &groupKey, assetStore.db, genesisPointID, genAssetID,
)
require.NoError(t, err)

// If we fetch the group, it should have all the fields correctly
// populated.
storedGroup, err := mintingStore.FetchGroupByGroupKey(ctx, internalKey)
require.NoError(t, err)

require.Equal(t, groupAnchorGen, *storedGroup.Genesis)
require.True(t, groupKey.IsEqual(storedGroup.GroupKey))
}

// TestAssetGroupKeyUpsert tests that if you try to insert another asset group
// key with the same tweaked_group_key, then only one is actually created.
func TestAssetGroupKeyUpsert(t *testing.T) {
Expand Down

0 comments on commit c4a9222

Please sign in to comment.