Skip to content

Commit 09b267b

Browse files
authored
fix migration and add tests (#51)
1 parent 5231227 commit 09b267b

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

x/dex/migrations/v3_to_v4.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package migrations
22

33
import (
4-
"github.com/cosmos/cosmos-sdk/codec"
54
sdk "github.com/cosmos/cosmos-sdk/types"
65
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
76
"github.com/sei-protocol/sei-chain/x/dex/types"
87
)
98

10-
func PriceSnapshotUpdate(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.BinaryCodec, paramStore paramtypes.Subspace) error {
9+
func PriceSnapshotUpdate(ctx sdk.Context, paramStore paramtypes.Subspace) error {
10+
migratePriceSnapshotParam(ctx, paramStore)
1111
return nil
1212
}
1313

x/dex/migrations/v3_to_v4_test.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package migrations_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/cosmos/cosmos-sdk/codec"
7+
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
8+
"github.com/cosmos/cosmos-sdk/store"
9+
storetypes "github.com/cosmos/cosmos-sdk/store/types"
10+
sdk "github.com/cosmos/cosmos-sdk/types"
11+
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
12+
"github.com/sei-protocol/sei-chain/x/dex/migrations"
13+
"github.com/sei-protocol/sei-chain/x/dex/types"
14+
"github.com/stretchr/testify/require"
15+
"github.com/tendermint/tendermint/libs/log"
16+
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
17+
tmdb "github.com/tendermint/tm-db"
18+
)
19+
20+
func TestMigrate3to4(t *testing.T) {
21+
storeKey := sdk.NewKVStoreKey(types.StoreKey)
22+
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)
23+
24+
db := tmdb.NewMemDB()
25+
stateStore := store.NewCommitMultiStore(db)
26+
stateStore.MountStoreWithDB(storeKey, sdk.StoreTypeIAVL, db)
27+
stateStore.MountStoreWithDB(memStoreKey, sdk.StoreTypeMemory, nil)
28+
require.NoError(t, stateStore.LoadLatestVersion())
29+
30+
registry := codectypes.NewInterfaceRegistry()
31+
cdc := codec.NewProtoCodec(registry)
32+
33+
paramsSubspace := typesparams.NewSubspace(cdc,
34+
types.Amino,
35+
storeKey,
36+
memStoreKey,
37+
"DexParams",
38+
)
39+
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
40+
if !paramsSubspace.HasKeyTable() {
41+
paramsSubspace = paramsSubspace.WithKeyTable(types.ParamKeyTable())
42+
}
43+
migrations.PriceSnapshotUpdate(ctx, paramsSubspace)
44+
45+
params := types.Params{}
46+
paramsSubspace.GetParamSet(ctx, &params)
47+
require.Equal(t, uint64(types.DefaultPriceSnapshotRetention), params.PriceSnapshotRetention)
48+
}

x/dex/module.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
159159
return migrations.DataTypeUpdate(ctx, am.keeper.GetStoreKey(), am.keeper.Cdc)
160160
})
161161
cfg.RegisterMigration(types.ModuleName, 3, func(ctx sdk.Context) error {
162-
return migrations.PriceSnapshotUpdate(ctx, am.keeper.GetStoreKey(), am.keeper.Cdc, am.keeper.Paramstore)
162+
return migrations.PriceSnapshotUpdate(ctx, am.keeper.Paramstore)
163163
})
164164
}
165165

0 commit comments

Comments
 (0)