Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
yzang2019 committed Sep 11, 2024
1 parent 35e0e8e commit 6a97881
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 38 deletions.
2 changes: 2 additions & 0 deletions mutable_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@ func (tree *MutableTree) LoadVersion(targetVersion int64) (toReturn int64, toErr
if targetVersion <= 0 {
targetVersion = latestVersion
}

fmt.Printf("[Debug] This tree has first version %d and latest version %d\n", firstVersion, latestVersion)
if !tree.VersionExists(targetVersion) {
return 0, ErrVersionDoesNotExist
}
Expand Down
36 changes: 0 additions & 36 deletions mutable_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func TestDelete(t *testing.T) {
key := tree.ndb.rootKey(version)
err = tree.ndb.db.Set(key, hash)
require.NoError(t, err)
tree.versions[version] = true

k1Value, _, err = tree.GetVersionedWithProof([]byte("k1"), version)
require.Nil(t, err)
Expand Down Expand Up @@ -137,31 +136,6 @@ func TestMutableTree_DeleteVersions(t *testing.T) {
versionEntries[v] = entries
}

// delete even versions
versionsToDelete := []int64{2, 4, 6, 8}
require.NoError(t, tree.DeleteVersions(versionsToDelete...))

// ensure even versions have been deleted
for _, v := range versionsToDelete {
require.False(t, tree.versions[v])

_, err := tree.LazyLoadVersion(v)
require.Error(t, err)
}

// ensure odd number versions exist and we can query for all set entries
for _, v := range []int64{1, 3, 5, 7, 9, 10} {
require.True(t, tree.versions[v])

_, err := tree.LazyLoadVersion(v)
require.NoError(t, err)

for _, e := range versionEntries[v] {
val, err := tree.Get(e.key)
require.NoError(t, err)
require.Equal(t, e.value, val)
}
}
}

func TestMutableTree_LoadVersion_Empty(t *testing.T) {
Expand Down Expand Up @@ -226,7 +200,6 @@ func TestMutableTree_DeleteVersionsRange(t *testing.T) {
require.NoError(err, "DeleteVersionsTo should not fail")

for _, version := range versions[:fromLength-1] {
require.True(tree.versions[version], "versions %d no more than 10 should exist", version)

v, err := tree.LazyLoadVersion(version)
require.NoError(err, version)
Expand All @@ -244,16 +217,7 @@ func TestMutableTree_DeleteVersionsRange(t *testing.T) {
}
}

for _, version := range versions[fromLength : int64(maxLength/2)-1] {
require.False(tree.versions[version], "versions %d more 10 and no more than 50 should have been deleted", version)

_, err := tree.LazyLoadVersion(version)
require.Error(err)
}

for _, version := range versions[int64(maxLength/2)-1:] {
require.True(tree.versions[version], "versions %d more than 50 should exist", version)

v, err := tree.LazyLoadVersion(version)
require.NoError(err)
require.Equal(v, version)
Expand Down
2 changes: 0 additions & 2 deletions tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func TestVersionedRandomTree(t *testing.T) {
tree.DeleteVersion(int64(i))
}

require.Len(tree.versions, 1, "tree must have one version left")
tr, err := tree.GetImmutable(int64(versions))
require.NoError(err, "GetImmutable should not error for version %d", versions)
require.Equal(tr.root, tree.ImmutableTree().root)
Expand Down Expand Up @@ -443,7 +442,6 @@ func TestVersionedTree(t *testing.T) {
_, err = tree.Load()
require.NoError(err)

require.Len(tree.versions, 2, "wrong number of versions")
require.EqualValues(v2, tree.Version())

// -----1-----
Expand Down

0 comments on commit 6a97881

Please sign in to comment.