From c4a922292e64c181906fbf9b834afa74da11c751 Mon Sep 17 00:00:00 2001 From: ffranr Date: Wed, 15 Jan 2025 10:47:12 +0000 Subject: [PATCH] tapdb: add unit test for asset group version 1 Add TestAssetGroupV1 to verify the ability to store and load an asset group of version 1. --- tapdb/assets_store_test.go | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tapdb/assets_store_test.go b/tapdb/assets_store_test.go index b83d14411..847a107c1 100644 --- a/tapdb/assets_store_test.go +++ b/tapdb/assets_store_test.go @@ -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) {