2018-03-19 06:27:39 -07:00
|
|
|
package mock
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-06-29 18:10:15 -07:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-03-19 06:27:39 -07:00
|
|
|
|
|
|
|
dbm "github.com/tendermint/tmlibs/db"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStore(t *testing.T) {
|
|
|
|
db := dbm.NewMemDB()
|
2018-06-29 15:22:24 -07:00
|
|
|
cms := NewCommitMultiStore()
|
2018-03-19 06:27:39 -07:00
|
|
|
|
|
|
|
key := sdk.NewKVStoreKey("test")
|
|
|
|
cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db)
|
|
|
|
err := cms.LoadLatestVersion()
|
2018-06-29 18:10:15 -07:00
|
|
|
require.Nil(t, err)
|
2018-03-19 06:27:39 -07:00
|
|
|
|
|
|
|
store := cms.GetKVStore(key)
|
2018-06-29 18:10:15 -07:00
|
|
|
require.NotNil(t, store)
|
2018-03-19 06:27:39 -07:00
|
|
|
|
|
|
|
k := []byte("hello")
|
|
|
|
v := []byte("world")
|
2018-06-29 18:10:15 -07:00
|
|
|
require.False(t, store.Has(k))
|
2018-03-19 06:27:39 -07:00
|
|
|
store.Set(k, v)
|
2018-06-29 18:10:15 -07:00
|
|
|
require.True(t, store.Has(k))
|
|
|
|
require.Equal(t, v, store.Get(k))
|
2018-03-19 06:27:39 -07:00
|
|
|
store.Delete(k)
|
2018-06-29 18:10:15 -07:00
|
|
|
require.False(t, store.Has(k))
|
2018-03-19 06:27:39 -07:00
|
|
|
}
|