Skip to content

Commit

Permalink
test: Ensure apphash stays the same for different InitialVersions
Browse files Browse the repository at this point in the history
  • Loading branch information
drklee3 committed Aug 16, 2024
1 parent 5237676 commit c1d6db0
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion mutable_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,8 @@ func TestMutableTree_InitialVersion_Prune(t *testing.T) {
func TestMutableTree_InitialVersion_NodeDB_Version(t *testing.T) {
testInitialVersions := []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

var expTreeHash []byte

for _, initialVersion := range testInitialVersions {
t.Run(fmt.Sprintf("InitialVersion(%d)", initialVersion), func(t *testing.T) {
db := dbm.NewMemDB()
Expand All @@ -1696,10 +1698,19 @@ func TestMutableTree_InitialVersion_NodeDB_Version(t *testing.T) {
_, err := tree.Set([]byte("hello"), []byte("world"))
require.NoError(t, err)

_, version, err := tree.SaveVersion()
treeHash, version, err := tree.SaveVersion()
require.NoError(t, err)
require.Equal(t, initialVersion, version)

if expTreeHash == nil {
expTreeHash = treeHash
} else {
require.NotEmpty(t, expTreeHash, "expected tree hash should not be empty")
require.Equal(t, expTreeHash, treeHash, "tree hash should be the same")
}

t.Logf("treeHash: %X", treeHash)

// ------------------------------
// Verify

Expand Down Expand Up @@ -1732,4 +1743,22 @@ func TestMutableTree_InitialVersion_NodeDB_Version(t *testing.T) {
require.ErrorIs(t, err, ErrVersionDoesNotExist)
})
}

t.Run("No InitialVersion", func(t *testing.T) {
// Starts at 1, same as InitialVersion(1)
// This goes through the non-patched path

db := dbm.NewMemDB()
tree := NewMutableTree(db, 0, false, log.NewNopLogger())

_, err := tree.Set([]byte("hello"), []byte("world"))
require.NoError(t, err)

treeHash, version, err := tree.SaveVersion()
require.NoError(t, err)
require.Equal(t, int64(1), version)

require.NotEmpty(t, expTreeHash, "expected tree hash should not be empty, should have been set in previous test")
require.Equal(t, expTreeHash, treeHash, "tree hash should be the same")
})
}

0 comments on commit c1d6db0

Please sign in to comment.