* mainly sdk.int to cosmossdk.io/math * staking keys * fumpt * var-naming linter errors and a fumpt * Update CHANGELOG.md * Update .golangci.yml * Update CHANGELOG.md * Update test_helpers.go * Update test_helpers.go * fumpt and lint * this lints the db module, and makes it easier to use. It adds breaking name changes * DBConnection -> Connection * previous commit contained a merge error * Update test_helpers.go * Update test_helpers.go * db renamings * merge master * changelog * DBWriter -> Writer * consistent multistore reciever * standard recievers for multistore v2alpha1 * general cleanup of linting issues * more linter fixes * remove prealloc linter * nolint the secp256k1 import * nolint the secp256k1 package * completenolint resulting in a diff that has only nolints
78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
//go:build rocksdb_build
|
|
|
|
package rocksdb
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/cosmos/cosmos-sdk/db"
|
|
"github.com/cosmos/cosmos-sdk/db/dbtest"
|
|
)
|
|
|
|
func load(t *testing.T, dir string) db.Connection {
|
|
d, err := NewDB(dir)
|
|
require.NoError(t, err)
|
|
return d
|
|
}
|
|
|
|
func TestGetSetHasDelete(t *testing.T) {
|
|
dbtest.DoTestGetSetHasDelete(t, load)
|
|
}
|
|
|
|
func TestIterators(t *testing.T) {
|
|
dbtest.DoTestIterators(t, load)
|
|
}
|
|
|
|
func TestTransactions(t *testing.T) {
|
|
dbtest.DoTestTransactions(t, load, true)
|
|
}
|
|
|
|
func TestVersioning(t *testing.T) {
|
|
dbtest.DoTestVersioning(t, load)
|
|
}
|
|
|
|
func TestRevert(t *testing.T) {
|
|
dbtest.DoTestRevert(t, load, false)
|
|
dbtest.DoTestRevert(t, load, true)
|
|
}
|
|
|
|
func TestReloadDB(t *testing.T) {
|
|
dbtest.DoTestReloadDB(t, load)
|
|
}
|
|
|
|
// Test that the DB can be reloaded after a failed Revert
|
|
func TestRevertRecovery(t *testing.T) {
|
|
dir := t.TempDir()
|
|
d, err := NewDB(dir)
|
|
require.NoError(t, err)
|
|
txn := d.Writer()
|
|
require.NoError(t, txn.Set([]byte{1}, []byte{1}))
|
|
require.NoError(t, txn.Commit())
|
|
_, err = d.SaveNextVersion()
|
|
require.NoError(t, err)
|
|
txn = d.Writer()
|
|
require.NoError(t, txn.Set([]byte{2}, []byte{2}))
|
|
require.NoError(t, txn.Commit())
|
|
|
|
// move checkpoints dir temporarily to trigger an error
|
|
hideDir := filepath.Join(dir, "hide_checkpoints")
|
|
require.NoError(t, os.Rename(d.checkpointsDir(), hideDir))
|
|
require.Error(t, d.Revert())
|
|
require.NoError(t, os.Rename(hideDir, d.checkpointsDir()))
|
|
|
|
d, err = NewDB(dir)
|
|
require.NoError(t, err)
|
|
view := d.Reader()
|
|
val, err := view.Get([]byte{1})
|
|
require.NoError(t, err)
|
|
require.Equal(t, []byte{1}, val)
|
|
val, err = view.Get([]byte{2})
|
|
require.NoError(t, err)
|
|
require.Nil(t, val)
|
|
view.Discard()
|
|
}
|