Skip to content

Commit

Permalink
fix: use GetParamsIfExists() to fetch old params (#1842)
Browse files Browse the repository at this point in the history
Co-authored-by: blindchaser <[email protected]>
  • Loading branch information
blindchaser and blindchaser authored Sep 3, 2024
1 parent c2a0d85 commit 7e79510
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
6 changes: 6 additions & 0 deletions x/evm/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ func (k *Keeper) GetParams(ctx sdk.Context) types.Params {
return params
}

func (k *Keeper) GetParamsIfExists(ctx sdk.Context) types.Params {
params := types.Params{}
k.Paramstore.GetParamSetIfExists(ctx, &params)
return params
}

func (k *Keeper) GetBaseDenom(ctx sdk.Context) string {
return BaseDenom
}
Expand Down
26 changes: 26 additions & 0 deletions x/evm/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper"
"github.com/sei-protocol/sei-chain/x/evm/types"
"github.com/stretchr/testify/require"
Expand All @@ -20,3 +21,28 @@ func TestParams(t *testing.T) {

require.Nil(t, k.GetParams(ctx).Validate())
}

func TestGetParamsIfExists(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())

// Define the expected parameters
expectedParams := types.Params{
PriorityNormalizer: sdk.NewDec(1),
BaseFeePerGas: sdk.NewDec(1),
}

// Set only a subset of the parameters in the keeper
k.Paramstore.Set(ctx, types.KeyPriorityNormalizer, expectedParams.PriorityNormalizer)
k.Paramstore.Set(ctx, types.KeyBaseFeePerGas, expectedParams.BaseFeePerGas)

// Retrieve the parameters using GetParamsIfExists
params := k.GetParamsIfExists(ctx)

// Assert that the retrieved parameters match the expected parameters
require.Equal(t, expectedParams.PriorityNormalizer, params.PriorityNormalizer)
require.Equal(t, expectedParams.BaseFeePerGas, params.BaseFeePerGas)

// Assert that the missing parameter has its default value
require.Equal(t, types.DefaultParams().DeliverTxHookWasmGasLimit, params.DeliverTxHookWasmGasLimit)
}
6 changes: 3 additions & 3 deletions x/evm/migrations/migrate_deliver_tx_gas_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
)

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

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

// Set the updated parameters back in the keeper
Expand Down

0 comments on commit 7e79510

Please sign in to comment.