Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions x/dex/migrations/v3_to_v4.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package migrations

import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/sei-protocol/sei-chain/x/dex/types"
)

func PriceSnapshotUpdate(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.BinaryCodec, paramStore paramtypes.Subspace) error {
func PriceSnapshotUpdate(ctx sdk.Context, paramStore paramtypes.Subspace) error {
migratePriceSnapshotParam(ctx, paramStore)
return nil
}

Expand Down
48 changes: 48 additions & 0 deletions x/dex/migrations/v3_to_v4_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package migrations_test

import (
"testing"

"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/sei-protocol/sei-chain/x/dex/migrations"
"github.com/sei-protocol/sei-chain/x/dex/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 TestMigrate3to4(t *testing.T) {
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,
"DexParams",
)
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
if !paramsSubspace.HasKeyTable() {
paramsSubspace = paramsSubspace.WithKeyTable(types.ParamKeyTable())
}
migrations.PriceSnapshotUpdate(ctx, paramsSubspace)

params := types.Params{}
paramsSubspace.GetParamSet(ctx, &params)
require.Equal(t, uint64(types.DefaultPriceSnapshotRetention), params.PriceSnapshotRetention)
}
2 changes: 1 addition & 1 deletion x/dex/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
return migrations.DataTypeUpdate(ctx, am.keeper.GetStoreKey(), am.keeper.Cdc)
})
cfg.RegisterMigration(types.ModuleName, 3, func(ctx sdk.Context) error {
return migrations.PriceSnapshotUpdate(ctx, am.keeper.GetStoreKey(), am.keeper.Cdc, am.keeper.Paramstore)
return migrations.PriceSnapshotUpdate(ctx, am.keeper.Paramstore)
})
}

Expand Down