Skip to content

Commit d6a3e60

Browse files
authored
Add param migration handler (#756)
* Add param migration handle * Add param migration handle * test * test * test * test * test * test * test
1 parent 7db23a1 commit d6a3e60

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

x/dex/ante_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestCheckDexGasDecorator(t *testing.T) {
8181
types.NewMsgPlaceOrders("someone", []*types.Order{{}, {}}, keepertest.TestContract, sdk.NewCoins()),
8282
types.NewMsgCancelOrders("someone", []*types.Cancellation{{}, {}, {}}, keepertest.TestContract),
8383
},
84-
fee: sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(27499))),
84+
fee: sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(25499))),
8585
}
8686
_, err = decorator.AnteHandle(ctx, tx, false, terminator)
8787
require.NotNil(t, err)

x/dex/migrations/v12_to_v13.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package migrations
2+
3+
import (
4+
sdk "github.com/cosmos/cosmos-sdk/types"
5+
"github.com/sei-protocol/sei-chain/x/dex/keeper"
6+
"github.com/sei-protocol/sei-chain/x/dex/types"
7+
)
8+
9+
func V12ToV13(ctx sdk.Context, dexkeeper keeper.Keeper) error {
10+
// This isn't the cleanest migration since it could potentially revert any dex params we have changed
11+
// but we haven't, so we'll just do this.
12+
defaultParams := types.DefaultParams()
13+
dexkeeper.SetParams(ctx, defaultParams)
14+
return nil
15+
}

x/dex/migrations/v12_to_v13_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package migrations_test
2+
3+
import (
4+
"testing"
5+
6+
sdk "github.com/cosmos/cosmos-sdk/types"
7+
keepertest "github.com/sei-protocol/sei-chain/testutil/keeper"
8+
"github.com/sei-protocol/sei-chain/x/dex/migrations"
9+
"github.com/sei-protocol/sei-chain/x/dex/types"
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
func TestMigrate12to13(t *testing.T) {
14+
dexkeeper, ctx := keepertest.DexKeeper(t)
15+
// write old params
16+
prevParams := types.Params{
17+
PriceSnapshotRetention: 1,
18+
SudoCallGasPrice: sdk.OneDec(),
19+
BeginBlockGasLimit: 1,
20+
EndBlockGasLimit: 1,
21+
DefaultGasPerOrder: 1,
22+
DefaultGasPerCancel: 1,
23+
}
24+
dexkeeper.SetParams(ctx, prevParams)
25+
26+
// migrate to default params
27+
err := migrations.V12ToV13(ctx, *dexkeeper)
28+
require.NoError(t, err)
29+
params := dexkeeper.GetParams(ctx)
30+
require.Equal(t, params.GasAllowancePerSettlement, uint64(types.DefaultGasAllowancePerSettlement))
31+
require.Equal(t, params.MinProcessableRent, uint64(types.DefaultMinProcessableRent))
32+
}

x/dex/module.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
197197
_ = cfg.RegisterMigration(types.ModuleName, 11, func(ctx sdk.Context) error {
198198
return migrations.V11ToV12(ctx, am.keeper)
199199
})
200+
_ = cfg.RegisterMigration(types.ModuleName, 12, func(ctx sdk.Context) error {
201+
return migrations.V12ToV13(ctx, am.keeper)
202+
})
200203
}
201204

202205
// RegisterInvariants registers the capability module's invariants.
@@ -221,7 +224,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
221224
}
222225

223226
// ConsensusVersion implements ConsensusVersion.
224-
func (AppModule) ConsensusVersion() uint64 { return 12 }
227+
func (AppModule) ConsensusVersion() uint64 { return 13 }
225228

226229
func (am AppModule) getAllContractInfo(ctx sdk.Context) []types.ContractInfoV2 {
227230
// Do not process any contract that has zero rent balance

x/dex/types/params.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525
DefaultBeginBlockGasLimit = 200000000 // 200M
2626
DefaultEndBlockGasLimit = 1000000000 // 1B
2727
DefaultDefaultGasPerOrder = 55000
28-
DefaultDefaultGasPerCancel = 55000
28+
DefaultDefaultGasPerCancel = 53000
2929
DefaultMinRentDeposit = 10000000 // 10 sei
3030
DefaultGasAllowancePerSettlement = 10000
3131
DefaultMinProcessableRent = 100000

0 commit comments

Comments
 (0)