Fix incorrect initial CurrentIdx in kvdb

This commit is contained in:
Eduard S
2021-01-28 11:43:33 +01:00
parent f3678e8cb8
commit d7c56afa5c
5 changed files with 91 additions and 5 deletions

View File

@@ -341,6 +341,11 @@ func (s *StateDB) MTGetRoot() *big.Int {
return s.MT.Root().BigInt()
}
// Close the StateDB
func (s *StateDB) Close() {
s.db.Close()
}
// LocalStateDB represents the local StateDB which allows to make copies from
// the synchronizer StateDB, and is used by the tx-selector and the
// batch-builder. LocalStateDB is an in-memory storage.

View File

@@ -532,3 +532,38 @@ func TestDeleteOldCheckpoints(t *testing.T) {
assert.LessOrEqual(t, len(checkpoints), keep)
}
}
func TestCurrentIdx(t *testing.T) {
dir, err := ioutil.TempDir("", "tmpdb")
require.NoError(t, err)
defer require.NoError(t, os.RemoveAll(dir))
keep := 16
sdb, err := NewStateDB(dir, keep, TypeSynchronizer, 32)
require.NoError(t, err)
idx := sdb.CurrentIdx()
assert.Equal(t, common.Idx(255), idx)
sdb.Close()
sdb, err = NewStateDB(dir, keep, TypeSynchronizer, 32)
require.NoError(t, err)
idx = sdb.CurrentIdx()
assert.Equal(t, common.Idx(255), idx)
err = sdb.MakeCheckpoint()
require.NoError(t, err)
idx = sdb.CurrentIdx()
assert.Equal(t, common.Idx(255), idx)
sdb.Close()
sdb, err = NewStateDB(dir, keep, TypeSynchronizer, 32)
require.NoError(t, err)
idx = sdb.CurrentIdx()
assert.Equal(t, common.Idx(255), idx)
}