Skip to content

Commit

Permalink
Add migration for new params (#1840)
Browse files Browse the repository at this point in the history
* Add migration function for DeliverTxHookWasmGasLimitParam
---------

Co-authored-by: blindchaser <zengyiren@hotmail.com>
  • Loading branch information
blindchaser and blindchaser committed Aug 30, 2024
1 parent 942e73d commit c2a0d85
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
20 changes: 20 additions & 0 deletions x/evm/migrations/migrate_deliver_tx_gas_limit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package migrations

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/sei-protocol/sei-chain/x/evm/keeper"
"github.com/sei-protocol/sei-chain/x/evm/types"
)

func MigrateDeliverTxHookWasmGasLimitParam(ctx sdk.Context, k *keeper.Keeper) error {
// Fetch the current parameters
keeperParams := k.GetParams(ctx)

// Update DeliverTxHookWasmGasLimit to the default value
keeperParams.DeliverTxHookWasmGasLimit = types.DefaultParams().DeliverTxHookWasmGasLimit

// Set the updated parameters back in the keeper
k.SetParams(ctx, keeperParams)

return nil
}
37 changes: 37 additions & 0 deletions x/evm/migrations/migrate_deliver_tx_gas_limit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package migrations_test

import (
"testing"

testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper"
"github.com/sei-protocol/sei-chain/x/evm/migrations"
"github.com/sei-protocol/sei-chain/x/evm/types"
"github.com/stretchr/testify/require"
tmtypes "github.com/tendermint/tendermint/proto/tendermint/types"
)

func TestMigrateDeliverTxHookWasmGasLimitParam(t *testing.T) {
k := testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.NewContext(false, tmtypes.Header{})

currParams := k.GetParams(ctx)

// Keep a copy of the other parameters to compare later
priorityNormalizer := currParams.PriorityNormalizer
baseFeePerGas := currParams.BaseFeePerGas
minimumFeePerGas := currParams.MinimumFeePerGas

// Perform the migration
err := migrations.MigrateDeliverTxHookWasmGasLimitParam(ctx, &k)
require.NoError(t, err)

keeperParams := k.GetParams(ctx)

// Ensure that the DeliverTxHookWasmGasLimit was migrated to the default value
require.Equal(t, keeperParams.GetDeliverTxHookWasmGasLimit(), types.DefaultParams().DeliverTxHookWasmGasLimit)

// Verify that the other parameters were not changed by the migration
require.True(t, keeperParams.PriorityNormalizer.Equal(priorityNormalizer))
require.True(t, keeperParams.BaseFeePerGas.Equal(baseFeePerGas))
require.True(t, keeperParams.MinimumFeePerGas.Equal(minimumFeePerGas))
}
6 changes: 5 additions & 1 deletion x/evm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
_ = cfg.RegisterMigration(types.ModuleName, 10, func(ctx sdk.Context) error {
return migrations.MigrateCastAddressBalances(ctx, am.keeper)
})

_ = cfg.RegisterMigration(types.ModuleName, 11, func(ctx sdk.Context) error {
return migrations.MigrateDeliverTxHookWasmGasLimitParam(ctx, am.keeper)
})
}

// RegisterInvariants registers the capability module's invariants.
Expand Down Expand Up @@ -245,7 +249,7 @@ func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <-
}

// ConsensusVersion implements ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 11 }
func (AppModule) ConsensusVersion() uint64 { return 12 }

// BeginBlock executes all ABCI BeginBlock logic respective to the capability module.
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
Expand Down
2 changes: 1 addition & 1 deletion x/evm/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestModuleExportGenesis(t *testing.T) {
func TestConsensusVersion(t *testing.T) {
k, _ := testkeeper.MockEVMKeeper()
module := evm.NewAppModule(nil, k)
assert.Equal(t, uint64(11), module.ConsensusVersion())
assert.Equal(t, uint64(12), module.ConsensusVersion())
}

func TestABCI(t *testing.T) {
Expand Down

0 comments on commit c2a0d85

Please sign in to comment.