mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-05-24 07:46:40 +00:00
63 lines
2.0 KiB
Go
63 lines
2.0 KiB
Go
package keeper
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"planetmint-go/x/machine/keeper"
|
|
"planetmint-go/x/machine/types"
|
|
|
|
tmdb "github.com/cometbft/cometbft-db"
|
|
"github.com/cometbft/cometbft/libs/log"
|
|
tmproto "github.com/cometbft/cometbft/proto/tendermint/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"
|
|
)
|
|
|
|
func MachineKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
|
|
storeKey := sdk.NewKVStoreKey(types.StoreKey)
|
|
taIndexStoreKey := sdk.NewKVStoreKey(types.TAIndexKey)
|
|
issuerPlanetmintIndexStoreKey := sdk.NewKVStoreKey(types.IssuerPlanetmintIndexKey)
|
|
issuerLiquidIndexStoreKey := sdk.NewKVStoreKey(types.IssuerLiquidIndexKey)
|
|
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)
|
|
|
|
db := tmdb.NewMemDB()
|
|
stateStore := store.NewCommitMultiStore(db)
|
|
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
|
|
stateStore.MountStoreWithDB(taIndexStoreKey, storetypes.StoreTypeIAVL, db)
|
|
stateStore.MountStoreWithDB(issuerPlanetmintIndexStoreKey, storetypes.StoreTypeIAVL, db)
|
|
stateStore.MountStoreWithDB(issuerLiquidIndexStoreKey, storetypes.StoreTypeIAVL, db)
|
|
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil)
|
|
require.NoError(t, stateStore.LoadLatestVersion())
|
|
|
|
registry := codectypes.NewInterfaceRegistry()
|
|
cdc := codec.NewProtoCodec(registry)
|
|
|
|
paramsSubspace := typesparams.NewSubspace(cdc,
|
|
types.Amino,
|
|
storeKey,
|
|
memStoreKey,
|
|
"MachineParams",
|
|
)
|
|
k := keeper.NewKeeper(
|
|
cdc,
|
|
storeKey,
|
|
taIndexStoreKey,
|
|
issuerPlanetmintIndexStoreKey,
|
|
issuerLiquidIndexStoreKey,
|
|
memStoreKey,
|
|
paramsSubspace,
|
|
)
|
|
|
|
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
|
|
|
|
// Initialize params
|
|
k.SetParams(ctx, types.DefaultParams())
|
|
|
|
return k, ctx
|
|
}
|