Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
fix(evm): revert v4 migration changes (#1625)
Browse files Browse the repository at this point in the history
* fix(evm): revert v4 migration changes

* add check for chainID

* fix: renamed vars to avoid duplicate proto

* test

* fix: set default extraEIPs to nil

* fix: updated tests

Co-authored-by: Vladislav Varadinov <[email protected]>
(cherry picked from commit 9bfa1ff)
  • Loading branch information
fedekunze authored and mergify[bot] committed Jan 23, 2023
1 parent 4f48176 commit dbf7910
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 179 deletions.
26 changes: 21 additions & 5 deletions x/evm/migrations/v4/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"

v4types "github.com/evmos/ethermint/x/evm/migrations/v4/types"
"github.com/evmos/ethermint/x/evm/types"
)

Expand All @@ -17,19 +19,33 @@ func MigrateStore(
cdc codec.BinaryCodec,
) error {
var params types.Params

legacySubspace.GetParamSetIfExists(ctx, &params)

if err := params.Validate(); err != nil {
return err
}

bz, err := cdc.Marshal(&params)
if err != nil {
return err
}
chainCfgBz := cdc.MustMarshal(&params.ChainConfig)
extraEIPsBz := cdc.MustMarshal(&v4types.ExtraEIPs{EIPs: params.ExtraEIPs})

store := ctx.KVStore(storeKey)
store.Set(types.KeyPrefixParams, bz)

store.Set(types.ParamStoreKeyEVMDenom, []byte(params.EvmDenom))
store.Set(types.ParamStoreKeyExtraEIPs, extraEIPsBz)
store.Set(types.ParamStoreKeyChainConfig, chainCfgBz)

if params.AllowUnprotectedTxs {
store.Set(types.ParamStoreKeyAllowUnprotectedTxs, []byte{0x01})
}

if params.EnableCall {
store.Set(types.ParamStoreKeyEnableCall, []byte{0x01})
}

if params.EnableCreate {
store.Set(types.ParamStoreKeyEnableCreate, []byte{0x01})
}

return nil
}
40 changes: 34 additions & 6 deletions x/evm/migrations/v4/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (

"github.com/stretchr/testify/require"

"github.com/evmos/ethermint/x/evm/types"

"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/evmos/ethermint/app"
"github.com/evmos/ethermint/encoding"
v4 "github.com/evmos/ethermint/x/evm/migrations/v4"
"github.com/evmos/ethermint/x/evm/types"
v4types "github.com/evmos/ethermint/x/evm/migrations/v4/types"
)

type mockSubspace struct {
Expand All @@ -38,9 +39,36 @@ func TestMigrate(t *testing.T) {
legacySubspace := newMockSubspace(types.DefaultParams())
require.NoError(t, v4.MigrateStore(ctx, storeKey, legacySubspace, cdc))

paramsBz := kvStore.Get(types.KeyPrefixParams)
var params types.Params
cdc.MustUnmarshal(paramsBz, &params)
// Get all the new parameters from the kvStore
var evmDenom string
bz := kvStore.Get(types.ParamStoreKeyEVMDenom)
evmDenom = string(bz)

allowUnprotectedTx := kvStore.Has(types.ParamStoreKeyAllowUnprotectedTxs)
enableCreate := kvStore.Has(types.ParamStoreKeyEnableCreate)
enableCall := kvStore.Has(types.ParamStoreKeyEnableCall)

var chainCfg v4types.V4ChainConfig
bz = kvStore.Get(types.ParamStoreKeyChainConfig)
cdc.MustUnmarshal(bz, &chainCfg)

var extraEIPs v4types.ExtraEIPs
bz = kvStore.Get(types.ParamStoreKeyExtraEIPs)
cdc.MustUnmarshal(bz, &extraEIPs)
require.Equal(t, []int64(nil), extraEIPs.EIPs)

params := v4types.V4Params{
EvmDenom: evmDenom,
AllowUnprotectedTxs: allowUnprotectedTx,
EnableCreate: enableCreate,
EnableCall: enableCall,
V4ChainConfig: chainCfg,
ExtraEIPs: extraEIPs,
}

require.Equal(t, params, legacySubspace.ps)
require.Equal(t, legacySubspace.ps.EnableCall, params.EnableCall)
require.Equal(t, legacySubspace.ps.EnableCreate, params.EnableCreate)
require.Equal(t, legacySubspace.ps.AllowUnprotectedTxs, params.AllowUnprotectedTxs)
require.Equal(t, legacySubspace.ps.ExtraEIPs, params.ExtraEIPs.EIPs)
require.EqualValues(t, legacySubspace.ps.ChainConfig, params.V4ChainConfig)
}
Loading

0 comments on commit dbf7910

Please sign in to comment.