Skip to content

Commit

Permalink
add migration handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
jewei1997 committed Sep 14, 2024
1 parent f9522d2 commit 89db5a4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
15 changes: 15 additions & 0 deletions x/evm/migrations/migrate_eip_1559_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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 MigrateEip1559Params(ctx sdk.Context, k *keeper.Keeper) error {
keeperParams := k.GetParamsIfExists(ctx)
keeperParams.MaxDynamicBaseFeeUpwardAdjustment = types.DefaultParams().MaxDynamicBaseFeeUpwardAdjustment
keeperParams.MaxDynamicBaseFeeDownwardAdjustment = types.DefaultParams().MaxDynamicBaseFeeDownwardAdjustment
k.SetParams(ctx, keeperParams)
return nil
}
27 changes: 27 additions & 0 deletions x/evm/migrations/migrate_eip_1559_params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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 TestMigrateEip1559Params(t *testing.T) {
k := testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.NewContext(false, tmtypes.Header{})

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

keeperParams := k.GetParams(ctx)

// Ensure that the EIP-1559 parameters were migrated to the default values
require.Equal(t, keeperParams.BaseFeePerGas, types.DefaultParams().BaseFeePerGas)
require.Equal(t, keeperParams.MaxDynamicBaseFeeUpwardAdjustment, types.DefaultParams().MaxDynamicBaseFeeUpwardAdjustment)
require.Equal(t, keeperParams.MaxDynamicBaseFeeDownwardAdjustment, types.DefaultParams().MaxDynamicBaseFeeDownwardAdjustment)
}
4 changes: 4 additions & 0 deletions x/evm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
_ = cfg.RegisterMigration(types.ModuleName, 12, func(ctx sdk.Context) error {
return migrations.MigrateBlockBloom(ctx, am.keeper)
})

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

Check warning on line 222 in x/evm/module.go

View check run for this annotation

Codecov / codecov/patch

x/evm/module.go#L221-L222

Added lines #L221 - L222 were not covered by tests
}

// RegisterInvariants registers the capability module's invariants.
Expand Down

0 comments on commit 89db5a4

Please sign in to comment.