Skip to content

Commit dde1006

Browse files
jharveybRoasbeef
authored andcommitted
tapdb: populate proof type when fetching uni roots
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.
1 parent 02ea446 commit dde1006

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

tapdb/multiverse.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ func (b *MultiverseStore) RootNodes(
152152
groupedAssets map[asset.ID]uint64
153153
)
154154

155+
// Parse universe proof type and populate the universe
156+
// ID.
157+
id.ProofType, err = universe.ParseStrProofType(
158+
dbRoot.ProofType,
159+
)
160+
if err != nil {
161+
return err
162+
}
163+
155164
if dbRoot.AssetID != nil {
156165
copy(id.AssetID[:], dbRoot.AssetID)
157166
}
@@ -189,15 +198,6 @@ func (b *MultiverseStore) RootNodes(
189198
}
190199
}
191200

192-
// Parse universe proof type and populate the universe
193-
// ID.
194-
id.ProofType, err = universe.ParseStrProofType(
195-
dbRoot.ProofType,
196-
)
197-
if err != nil {
198-
return err
199-
}
200-
201201
var nodeHash mssmt.NodeHash
202202
copy(nodeHash[:], dbRoot.RootHash)
203203
uniRoot := universe.BaseRoot{

tapdb/universe_test.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,16 @@ func TestUniverseTreeIsolation(t *testing.T) {
422422

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

428-
idNormal := randUniverseID(t, false)
432+
idNormal := randUniverseID(
433+
t, false, withProofType(universe.ProofTypeTransfer),
434+
)
429435
normalUniverse, _ := newTestUniverseWithDb(db.BaseDB, idNormal)
430436

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

482+
// Similarly, each of the roots should have the proper proof type set.
483+
require.True(t, fn.All(rootNodes, func(root universe.BaseRoot) bool {
484+
switch root.ID.ProofType {
485+
case universe.ProofTypeIssuance:
486+
return mssmt.IsEqualNode(root.Node, groupRoot)
487+
case universe.ProofTypeTransfer:
488+
return mssmt.IsEqualNode(root.Node, normalRoot)
489+
default:
490+
return false
491+
}
492+
}))
493+
494+
// Finally, the grouped root should have the GroupedAssets field
495+
// properly set.
496+
for _, root := range rootNodes {
497+
if mssmt.IsEqualNode(root.Node, groupRoot) {
498+
require.True(t, len(root.GroupedAssets) != 0)
499+
500+
groupAmt, ok := root.GroupedAssets[groupLeaf.Leaf.ID()]
501+
require.True(t, ok)
502+
require.Equal(t, groupLeaf.Leaf.Amt, groupAmt)
503+
}
504+
}
505+
476506
// We should be able to delete one Universe with no effect on the other.
477507
normalNamespace, err := normalUniverse.DeleteUniverse(ctx)
478508
require.NoError(t, err)

0 commit comments

Comments
 (0)