* modify light imports * change abci.header to tmproto.header * use rc * rc * fix import * Merge PR #6893: fix key imports * fix rc2 * tendermint: update 3 (#6899) * tendermint: update 4 (#6919) Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * tendermint: update 5 (#6923) Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * bump to latest master * tendermint: update (#6972) Co-authored-by: Aleksandr Bezobchuk <aleks.bezobchuk@gmail.com> Co-authored-by: Cory Levinson <cjlevinson@gmail.com> * Update x/ibc/07-tendermint/types/test_utils.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * address comment * go mod * bring back things * fix test * update tm proto files Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Aleksandr Bezobchuk <aleks.bezobchuk@gmail.com> Co-authored-by: Cory Levinson <cjlevinson@gmail.com> Co-authored-by: Federico Kunze <federico.kunze94@gmail.com>
70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
package cache_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/cosmos/iavl"
|
|
"github.com/stretchr/testify/require"
|
|
dbm "github.com/tendermint/tm-db"
|
|
|
|
"github.com/cosmos/cosmos-sdk/store/cache"
|
|
iavlstore "github.com/cosmos/cosmos-sdk/store/iavl"
|
|
"github.com/cosmos/cosmos-sdk/store/types"
|
|
)
|
|
|
|
func TestGetOrSetStoreCache(t *testing.T) {
|
|
db := dbm.NewMemDB()
|
|
mngr := cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize)
|
|
|
|
sKey := types.NewKVStoreKey("test")
|
|
tree, err := iavl.NewMutableTree(db, 100)
|
|
require.NoError(t, err)
|
|
store := iavlstore.UnsafeNewStore(tree)
|
|
store2 := mngr.GetStoreCache(sKey, store)
|
|
|
|
require.NotNil(t, store2)
|
|
require.Equal(t, store2, mngr.GetStoreCache(sKey, store))
|
|
}
|
|
|
|
func TestUnwrap(t *testing.T) {
|
|
db := dbm.NewMemDB()
|
|
mngr := cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize)
|
|
|
|
sKey := types.NewKVStoreKey("test")
|
|
tree, err := iavl.NewMutableTree(db, 100)
|
|
require.NoError(t, err)
|
|
store := iavlstore.UnsafeNewStore(tree)
|
|
_ = mngr.GetStoreCache(sKey, store)
|
|
|
|
require.Equal(t, store, mngr.Unwrap(sKey))
|
|
require.Nil(t, mngr.Unwrap(types.NewKVStoreKey("test2")))
|
|
}
|
|
|
|
func TestStoreCache(t *testing.T) {
|
|
db := dbm.NewMemDB()
|
|
mngr := cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize)
|
|
|
|
sKey := types.NewKVStoreKey("test")
|
|
tree, err := iavl.NewMutableTree(db, 100)
|
|
require.NoError(t, err)
|
|
store := iavlstore.UnsafeNewStore(tree)
|
|
kvStore := mngr.GetStoreCache(sKey, store)
|
|
|
|
for i := uint(0); i < cache.DefaultCommitKVStoreCacheSize*2; i++ {
|
|
key := []byte(fmt.Sprintf("key_%d", i))
|
|
value := []byte(fmt.Sprintf("value_%d", i))
|
|
|
|
kvStore.Set(key, value)
|
|
|
|
res := kvStore.Get(key)
|
|
require.Equal(t, res, value)
|
|
require.Equal(t, res, store.Get(key))
|
|
|
|
kvStore.Delete(key)
|
|
|
|
require.Nil(t, kvStore.Get(key))
|
|
require.Nil(t, store.Get(key))
|
|
}
|
|
}
|