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

fix(evm): revert v4 migration changes #1625

Merged
merged 8 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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