Skip to content

Commit

Permalink
tapdb: populate proof type when fetching uni roots
Browse files Browse the repository at this point in the history
In this commit, we fix an issue that prevented the display of asset IDs
for asset group members. The unpopulated proof type field led the
following query for universe leaves to fail.
  • Loading branch information
jharveyb authored and Roasbeef committed Oct 14, 2023
1 parent 02ea446 commit dde1006
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
18 changes: 9 additions & 9 deletions tapdb/multiverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ func (b *MultiverseStore) RootNodes(
groupedAssets map[asset.ID]uint64
)

// Parse universe proof type and populate the universe
// ID.
id.ProofType, err = universe.ParseStrProofType(
dbRoot.ProofType,
)
if err != nil {
return err
}

if dbRoot.AssetID != nil {
copy(id.AssetID[:], dbRoot.AssetID)
}
Expand Down Expand Up @@ -189,15 +198,6 @@ func (b *MultiverseStore) RootNodes(
}
}

// Parse universe proof type and populate the universe
// ID.
id.ProofType, err = universe.ParseStrProofType(
dbRoot.ProofType,
)
if err != nil {
return err
}

var nodeHash mssmt.NodeHash
copy(nodeHash[:], dbRoot.RootHash)
uniRoot := universe.BaseRoot{
Expand Down
34 changes: 32 additions & 2 deletions tapdb/universe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,16 @@ func TestUniverseTreeIsolation(t *testing.T) {

// For this test, we'll create two different Universes: one based on a
// group key, and the other with a plain asset ID.
idGroup := randUniverseID(t, true)
//
// One will be an issuance tree, while the other a transfer tree.
idGroup := randUniverseID(
t, true, withProofType(universe.ProofTypeIssuance),
)
groupUniverse, _ := newTestUniverseWithDb(db.BaseDB, idGroup)

idNormal := randUniverseID(t, false)
idNormal := randUniverseID(
t, false, withProofType(universe.ProofTypeTransfer),
)
normalUniverse, _ := newTestUniverseWithDb(db.BaseDB, idNormal)

// For each of the Universes, we'll now insert a random leaf that
Expand Down Expand Up @@ -473,6 +479,30 @@ func TestUniverseTreeIsolation(t *testing.T) {
return false
}))

// Similarly, each of the roots should have the proper proof type set.
require.True(t, fn.All(rootNodes, func(root universe.BaseRoot) bool {
switch root.ID.ProofType {
case universe.ProofTypeIssuance:
return mssmt.IsEqualNode(root.Node, groupRoot)
case universe.ProofTypeTransfer:
return mssmt.IsEqualNode(root.Node, normalRoot)
default:
return false
}
}))

// Finally, the grouped root should have the GroupedAssets field
// properly set.
for _, root := range rootNodes {
if mssmt.IsEqualNode(root.Node, groupRoot) {
require.True(t, len(root.GroupedAssets) != 0)

groupAmt, ok := root.GroupedAssets[groupLeaf.Leaf.ID()]
require.True(t, ok)
require.Equal(t, groupLeaf.Leaf.Amt, groupAmt)
}
}

// We should be able to delete one Universe with no effect on the other.
normalNamespace, err := normalUniverse.DeleteUniverse(ctx)
require.NoError(t, err)
Expand Down

0 comments on commit dde1006

Please sign in to comment.