mirror of
https://github.com/colinear-labs/chain.git
synced 2026-03-05 01:54:26 -08:00
Initialized with Ignite CLI
This commit is contained in:
52
testutil/keeper/cosmostest.go
Normal file
52
testutil/keeper/cosmostest.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"cosmos-test/x/cosmostest/keeper"
|
||||
"cosmos-test/x/cosmostest/types"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/store"
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
tmdb "github.com/tendermint/tm-db"
|
||||
)
|
||||
|
||||
func CosmostestKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
|
||||
storeKey := sdk.NewKVStoreKey(types.StoreKey)
|
||||
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)
|
||||
|
||||
db := tmdb.NewMemDB()
|
||||
stateStore := store.NewCommitMultiStore(db)
|
||||
stateStore.MountStoreWithDB(storeKey, sdk.StoreTypeIAVL, db)
|
||||
stateStore.MountStoreWithDB(memStoreKey, sdk.StoreTypeMemory, nil)
|
||||
require.NoError(t, stateStore.LoadLatestVersion())
|
||||
|
||||
registry := codectypes.NewInterfaceRegistry()
|
||||
cdc := codec.NewProtoCodec(registry)
|
||||
|
||||
paramsSubspace := typesparams.NewSubspace(cdc,
|
||||
types.Amino,
|
||||
storeKey,
|
||||
memStoreKey,
|
||||
"CosmostestParams",
|
||||
)
|
||||
k := keeper.NewKeeper(
|
||||
cdc,
|
||||
storeKey,
|
||||
memStoreKey,
|
||||
paramsSubspace,
|
||||
)
|
||||
|
||||
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
|
||||
|
||||
// Initialize params
|
||||
k.SetParams(ctx, types.DefaultParams())
|
||||
|
||||
return k, ctx
|
||||
}
|
||||
Reference in New Issue
Block a user