Skip to content

Commit

Permalink
reproduced
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Oct 4, 2024
1 parent 25656a7 commit 514737a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions memiavl/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ var (
ChangeSets []ChangeSet
RefHashes [][]byte
ExpectItems [][]pair

IAVLInitialVersion = 100
RefHashesInitialVersion [][]byte
)

func mockKVPairs(kvPairs ...string) []*KVPair {
Expand Down Expand Up @@ -63,7 +66,23 @@ func init() {
// generate ref hashes with ref impl
d := wrapper.NewDBWrapper(db.NewMemDB())
refTree := iavl.NewMutableTree(d, 0, true, log.NewNopLogger())
refTreeInitialVersion := iavl.NewMutableTree(d, 0, true, log.NewNopLogger(), iavl.InitialVersionOption(uint64(IAVLInitialVersion)))
for _, changes := range ChangeSets {
{
if err := applyChangeSetRef(refTreeInitialVersion, changes); err != nil {
panic(err)
}
workingHash := refTreeInitialVersion.WorkingHash()
refHash, _, err := refTreeInitialVersion.SaveVersion()
if err != nil {
panic(err)
}
if !bytes.Equal(workingHash, refHash) {
panic(fmt.Sprintf("working hash %X != ref hash %X", workingHash, refHash))
}
RefHashesInitialVersion = append(RefHashesInitialVersion, refHash)
}

if err := applyChangeSetRef(refTree, changes); err != nil {
panic(err)
}
Expand Down Expand Up @@ -168,6 +187,20 @@ func TestRootHashes(t *testing.T) {
}
}

func TestRootHashesInitialVersion(t *testing.T) {
tree := NewWithInitialVersion(uint32(IAVLInitialVersion), 0)

for i, changes := range ChangeSets {
tree.ApplyChangeSet(changes)
workingHash := tree.RootHash()
hash, v, err := tree.SaveVersion(true)
require.NoError(t, err)
require.Equal(t, IAVLInitialVersion+i, int(v))
require.Equal(t, RefHashes[i], hash)
require.Equal(t, hash, workingHash)
}
}

func TestNewKey(t *testing.T) {
tree := New(0)

Expand Down

0 comments on commit 514737a

Please sign in to comment.