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

chore(evm): Deprecate x/params usage in x/evm #1472

Merged
merged 70 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
9f3fee9
imp(evm): Migrate from old Cosmos SDK params module to new way of kee…
Vvaradinov Nov 17, 2022
7d8d228
Updated changelog
Vvaradinov Nov 17, 2022
63d4a62
Apply changes from code review
Vvaradinov Nov 18, 2022
9aaa035
Merge branch 'main' into Vvaradinov/refactor-deprecated-evm-params-logic
Vvaradinov Nov 18, 2022
bfb2633
(impv): Added Shanghai and Cancun blocks to current types and latest …
Vvaradinov Nov 18, 2022
fa68d16
(tests): Update unit tests to include Shanghai and Cancun blocks
Vvaradinov Nov 18, 2022
0566f9d
(fix) - ran golangci-lint on the entire project
Vvaradinov Nov 18, 2022
7d09bb8
(fix) - remove deprecated params method
Vvaradinov Nov 18, 2022
4d519d5
(impv): added marshaling of booleans per individual param key
Vvaradinov Nov 18, 2022
72a8d4b
(impv): added individual param getting and setting
Vvaradinov Nov 19, 2022
4c4be05
Merge branch 'main' into Vvaradinov/refactor-deprecated-evm-params-logic
Vvaradinov Nov 19, 2022
86cc0e4
(impv): replaced getters with individual param
Vvaradinov Nov 21, 2022
567043c
Merge branch 'main' into Vvaradinov/refactor-deprecated-evm-params-logic
Vvaradinov Nov 21, 2022
5eb724d
(impv): added amino codec for MsgEthereumTx
Vvaradinov Nov 21, 2022
422a247
Added changes suggested in code review
Vvaradinov Nov 22, 2022
f95e918
(fix): updated the migration files for v4
Vvaradinov Nov 22, 2022
52a45ec
Merge branch 'main' into Vvaradinov/refactor-deprecated-evm-params-logic
Vvaradinov Nov 22, 2022
53b4ab0
(fix): fixed unit tests panic for incorrect interface
Vvaradinov Nov 22, 2022
512ed48
Merge branch 'Vvaradinov/refactor-deprecated-evm-params-logic' of htt…
Vvaradinov Nov 22, 2022
669d8f6
(fix): updated module msg handler
Vvaradinov Nov 23, 2022
ca95892
(fix): rename to original params getter method
Vvaradinov Nov 23, 2022
85d5eff
(refactor): registered implementation for the new msg
Vvaradinov Nov 24, 2022
fe9dc4c
Merge branch 'main' into Vvaradinov/refactor-deprecated-evm-params-logic
Vvaradinov Nov 24, 2022
74b1878
(refactor): added correct amino codec for MsgUpdateParams and removed…
Vvaradinov Nov 25, 2022
42e1405
Applied changes from code review
Vvaradinov Nov 25, 2022
90f7877
(fix): removed unnecessary duplicate
Vvaradinov Nov 25, 2022
6788828
(fix): removed params_legacy from the types and moved logic to migration
Vvaradinov Nov 25, 2022
096f422
(fix): Added v4 mocks to the migrations_test
Vvaradinov Nov 25, 2022
5db39eb
(fix): undo all the non related work regarding the Cancun and Shangha…
Vvaradinov Nov 25, 2022
efd88b3
(fix): reverted linting the entire project - will make a separate PR …
Vvaradinov Nov 25, 2022
960b213
Applied changes from review
Vvaradinov Nov 25, 2022
d8dd162
Applied changes from code review
Vvaradinov Nov 25, 2022
7158f1c
(fix): removed comments
Vvaradinov Nov 25, 2022
7431a28
Merge branch 'main' into Vvaradinov/refactor-deprecated-evm-params-logic
Vvaradinov Nov 25, 2022
a5c3397
Merge branch 'main' into Vvaradinov/refactor-deprecated-evm-params-logic
Vvaradinov Nov 25, 2022
b82775f
(fix): Ran formatter and fixed linting issues on unsed functions
Vvaradinov Nov 25, 2022
19146e6
(fix): Linting issues resolved
Vvaradinov Nov 25, 2022
a5e1e9f
(fix): refactor migrations and added default EIPs
Vvaradinov Nov 28, 2022
f6a4290
Merge branch 'main' into Vvaradinov/refactor-deprecated-evm-params-logic
Vvaradinov Nov 28, 2022
28a315c
(fix): Combined into one call
Vvaradinov Nov 28, 2022
0c48520
(fix): Added more straightforward way to handle migration
Vvaradinov Nov 28, 2022
2995dab
Merge branch 'main' into Vvaradinov/refactor-deprecated-evm-params-logic
Vvaradinov Nov 29, 2022
03e5b52
(fix): corrected migration test
Vvaradinov Nov 29, 2022
42429e5
Merge branch 'main' into Vvaradinov/refactor-deprecated-evm-params-logic
Vvaradinov Nov 29, 2022
5b8f891
Merge branch 'main' into Vvaradinov/refactor-deprecated-evm-params-logic
Vvaradinov Nov 30, 2022
42aefa5
Applied changes from code review
Vvaradinov Nov 30, 2022
36e13cb
(fix): Linter fix
Vvaradinov Nov 30, 2022
4e3fb16
(fix): Linter
Vvaradinov Nov 30, 2022
584a751
Merge branch 'main' into Vvaradinov/refactor-deprecated-evm-params-logic
Vvaradinov Nov 30, 2022
6c9a676
(fix): Lint proto files
Vvaradinov Dec 1, 2022
381df32
Merge branch 'main' into Vvaradinov/refactor-deprecated-evm-params-logic
MalteHerrmann Dec 9, 2022
2153748
Apply suggestions from code review
Vvaradinov Dec 9, 2022
31b1031
(fix): Added new block to migration
Vvaradinov Dec 9, 2022
db4de42
Merge branch 'Vvaradinov/refactor-deprecated-evm-params-logic' of htt…
Vvaradinov Dec 9, 2022
973a7e1
(fix): Added additional comments and formatted proto files
Vvaradinov Dec 9, 2022
953a809
(fix): Added name to unit test cases
Vvaradinov Dec 9, 2022
f7d2ed4
(fix): removed unused import
Vvaradinov Dec 9, 2022
ba122d7
Apply changes from code review
Vvaradinov Dec 12, 2022
6f19bd8
Merge branch 'main' into Vvaradinov/refactor-deprecated-evm-params-logic
Vvaradinov Dec 12, 2022
a91e4a4
(fix): typo
Vvaradinov Dec 12, 2022
83226dd
Merge branch 'Vvaradinov/refactor-deprecated-evm-params-logic' of htt…
Vvaradinov Dec 12, 2022
bfd8e89
(fix): remove HTTP endpoint exposure
Vvaradinov Dec 12, 2022
abceb75
Apply suggestions from code review
Vvaradinov Dec 16, 2022
9cb60cb
applied changes from code review
Vvaradinov Dec 19, 2022
c9a2418
Merge branch 'main' into Vvaradinov/refactor-deprecated-evm-params-logic
Vvaradinov Dec 19, 2022
408d3aa
Merge branch 'main' into Vvaradinov/refactor-deprecated-evm-params-logic
Vvaradinov Jan 3, 2023
0403e57
Merge branch 'main' into Vvaradinov/refactor-deprecated-evm-params-logic
Vvaradinov Jan 3, 2023
3812eee
fix: extra line added in merge removed
Vvaradinov Jan 3, 2023
ddaf663
fix: applied changes from code review
Vvaradinov Jan 4, 2023
aae45b2
Merge branch 'main' into Vvaradinov/refactor-deprecated-evm-params-logic
danburck Jan 4, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### State Machine Breaking

* (evm) [#1470](https://github.com/evmos/ethermint/pull/1470) Refactor deprecated Cosmos SDK x/params module
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
* (deps) [#1361](https://github.com/evmos/ethermint/pull/1361) Bump ibc-go to [`v5.0.0`](https://github.com/cosmos/ibc-go/releases/tag/v5.0.0)
* (evm) [\#1272](https://github.com/evmos/ethermint/pull/1272) Implement modular interface for the EVM.
* (deps) [#1168](https://github.com/evmos/ethermint/pull/1168) Upgrade Cosmos SDK to `v0.46`.
Expand Down
24 changes: 14 additions & 10 deletions app/ante/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ func NewEthSigVerificationDecorator(ek EVMKeeper) EthSigVerificationDecorator {
// Failure in RecheckTx will prevent tx to be included into block, especially when CheckTx succeed, in which case user
// won't see the error message.
func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
params := esvd.evmKeeper.GetParams(ctx)
chainID := esvd.evmKeeper.ChainID()
chainCfg := esvd.evmKeeper.GetChainConfig(ctx)
chainCfg := params.GetChainConfig()
ethCfg := chainCfg.EthereumConfig(chainID)
blockNum := big.NewInt(ctx.BlockHeight())
signer := ethtypes.MakeSigner(ethCfg, blockNum)
Expand All @@ -52,7 +53,7 @@ func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, s
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil))
}

allowUnprotectedTxs := esvd.evmKeeper.GetAllowUnprotectedTxs(ctx)
allowUnprotectedTxs := params.GetAllowUnprotectedTxs()
ethTx := msgEthTx.AsTransaction()
if !allowUnprotectedTxs && !ethTx.Protected() {
return ctx, sdkerrors.Wrapf(
Expand Down Expand Up @@ -176,7 +177,8 @@ func NewEthGasConsumeDecorator(
// - transaction or block gas meter runs out of gas
// - sets the gas meter limit
func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
chainCfg := egcd.evmKeeper.GetChainConfig(ctx)
params := egcd.evmKeeper.GetParams(ctx)
chainCfg := params.ChainConfig
ethCfg := chainCfg.EthereumConfig(egcd.evmKeeper.ChainID())

blockHeight := big.NewInt(ctx.BlockHeight())
Expand Down Expand Up @@ -211,7 +213,7 @@ func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
gasWanted += txData.GetGas()
}

evmDenom := egcd.evmKeeper.GetEVMDenom(ctx)
evmDenom := params.EvmDenom
fees, priority, err := egcd.evmKeeper.DeductTxCostsFromUserBalance(
ctx,
*msgEthTx,
Expand Down Expand Up @@ -435,13 +437,14 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
txFee := sdk.Coins{}
txGasLimit := uint64(0)

chainCfg := vbd.evmKeeper.GetChainConfig(ctx)
params := vbd.evmKeeper.GetParams(ctx)
chainCfg := params.ChainConfig
chainID := vbd.evmKeeper.ChainID()
ethCfg := chainCfg.EthereumConfig(chainID)
baseFee := vbd.evmKeeper.GetBaseFee(ctx, ethCfg)
enableCreate := vbd.evmKeeper.GetEnableCreate(ctx)
enableCall := vbd.evmKeeper.GetEnableCall(ctx)
evmDenom := vbd.evmKeeper.GetEVMDenom(ctx)
enableCreate := params.EnableCreate
enableCall := params.EnableCall
evmDenom := params.EvmDenom

for _, msg := range protoTx.GetMsgs() {
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
Expand Down Expand Up @@ -552,10 +555,11 @@ func NewEthMempoolFeeDecorator(ek EVMKeeper) EthMempoolFeeDecorator {
// It only do the check if london hardfork not enabled or feemarket not enabled, because in that case feemarket will take over the task.
func (mfd EthMempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
if ctx.IsCheckTx() && !simulate {
chainCfg := mfd.evmKeeper.GetChainConfig(ctx)
params := mfd.evmKeeper.GetParams(ctx)
chainCfg := params.ChainConfig
evmDenom := params.EvmDenom
ethCfg := chainCfg.EthereumConfig(mfd.evmKeeper.ChainID())
baseFee := mfd.evmKeeper.GetBaseFee(ctx, ethCfg)
evmDenom := mfd.evmKeeper.GetEVMDenom(ctx)

if baseFee == nil {
for _, msg := range tx.GetMsgs() {
Expand Down
3 changes: 2 additions & 1 deletion app/ante/fee_market.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func NewGasWantedDecorator(
}

func (gwd GasWantedDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
chainCfg := gwd.evmKeeper.GetChainConfig(ctx)
params := gwd.evmKeeper.GetParams(ctx)
chainCfg := params.ChainConfig
ethCfg := chainCfg.EthereumConfig(gwd.evmKeeper.ChainID())

blockHeight := big.NewInt(ctx.BlockHeight())
Expand Down
6 changes: 4 additions & 2 deletions app/ante/fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func (mpd MinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
return next(ctx, tx, simulate)
}

evmDenom := mpd.evmKeeper.GetEVMDenom(ctx)
params := mpd.evmKeeper.GetParams(ctx)
evmDenom := params.EvmDenom
minGasPrices := sdk.DecCoins{
{
Denom: evmDenom,
Expand Down Expand Up @@ -93,7 +94,8 @@ func (empd EthMinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul
return next(ctx, tx, simulate)
}

chainCfg := empd.evmKeeper.GetChainConfig(ctx)
params := empd.evmKeeper.GetParams(ctx)
chainCfg := params.ChainConfig
ethCfg := chainCfg.EthereumConfig(empd.evmKeeper.ChainID())
baseFee := empd.evmKeeper.GetBaseFee(ctx, ethCfg)

Expand Down
5 changes: 0 additions & 5 deletions app/ante/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ type EVMKeeper interface {
GetBalance(ctx sdk.Context, addr common.Address) *big.Int
ResetTransientGasUsed(ctx sdk.Context)
GetTxIndexTransient(ctx sdk.Context) uint64
GetChainConfig(ctx sdk.Context) evmtypes.ChainConfig
GetEVMDenom(ctx sdk.Context) string
GetEnableCreate(ctx sdk.Context) bool
GetEnableCall(ctx sdk.Context) bool
GetAllowUnprotectedTxs(ctx sdk.Context) bool
}

type protoTxProvider interface {
Expand Down
4 changes: 3 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,10 @@ func NewEthermintApp(
appCodec, app.GetSubspace(feemarkettypes.ModuleName), keys[feemarkettypes.StoreKey], tkeys[feemarkettypes.TransientKey],
)

// Create EVM keeper with a new field authority which is defaulted to the
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
// Cosmos SDK gov module account
app.EvmKeeper = evmkeeper.NewKeeper(
appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey], app.GetSubspace(evmtypes.ModuleName),
appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey], authtypes.NewModuleAddress(govtypes.ModuleName).String(),
app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.FeeMarketKeeper,
nil, geth.NewEVM, tracer,
)
Expand Down
25 changes: 25 additions & 0 deletions proto/ethermint/evm/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "google/api/annotations.proto";
import "google/protobuf/any.proto";
import "cosmos_proto/cosmos.proto";
import "ethermint/evm/v1/evm.proto";
import "cosmos/msg/v1/msg.proto";

option go_package = "github.com/evmos/ethermint/x/evm/types";

Expand All @@ -15,6 +16,11 @@ service Msg {
rpc EthereumTx(MsgEthereumTx) returns (MsgEthereumTxResponse) {
option (google.api.http).post = "/ethermint/evm/v1/ethereum_tx";
};
// UpdateParams defined a governance operation for updating the x/evm module parameters.
// The authority is hard-coded to the Cosmos SDK x/gov module account
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse) {
option (google.api.http).post = "/ethermint/evm/v1/update_params";
};
}

// MsgEthereumTx encapsulates an Ethereum transaction as an SDK message.
Expand Down Expand Up @@ -156,3 +162,22 @@ message MsgEthereumTxResponse {
// gas consumed by the transaction
uint64 gas_used = 5;
}

Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved

// MsgUpdateParams is the Msg/UpdateParams request type for EVM parameters.
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
// Since: cosmos-sdk 0.47
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved

// authority is the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the x/evm parameters to update.
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false];
}

// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
// Since: cosmos-sdk 0.47
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
message MsgUpdateParamsResponse {}
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
15 changes: 15 additions & 0 deletions x/evm/exported/exported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package exported
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved

import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

type (
Params = paramtypes.ParamSet
// Subspace defines an interface that implements the legacy Cosmos SDK x/params Subspace type.
// NOTE: This is used solely for migration of the Cosmos SDK x/params managed parameters.
Subspace interface {
GetParams(ctx sdk.Context, params Params)
}
)
5 changes: 4 additions & 1 deletion x/evm/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ func InitGenesis(
) []abci.ValidatorUpdate {
k.WithChainID(ctx)

k.SetParams(ctx, data.Params)
err := k.SetParams(ctx, data.Params)
if err != nil {
panic(err)
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
}

// ensure evm module account is set
if addr := accountKeeper.GetModuleAddress(types.ModuleName); addr == nil {
Expand Down
22 changes: 10 additions & 12 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/cosmos/cosmos-sdk/store/prefix"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -36,8 +35,8 @@ type Keeper struct {
// key to access the transient store, which is reset on every block during Commit
transientKey storetypes.StoreKey

// module specific parameter space that can be configured through governance
paramSpace paramtypes.Subspace
// the address capable of executing a MsgUpdateParams message. Typically, this should be the x/gov module account.
authority string
// access to account state
accountKeeper types.AccountKeeper
// update balance and accounting operations with coins
Expand Down Expand Up @@ -67,7 +66,7 @@ type Keeper struct {
func NewKeeper(
cdc codec.BinaryCodec,
storeKey, transientKey storetypes.StoreKey,
paramSpace paramtypes.Subspace,
authority string,
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
ak types.AccountKeeper,
bankKeeper types.BankKeeper,
sk types.StakingKeeper,
Expand All @@ -81,15 +80,10 @@ func NewKeeper(
panic("the EVM module account has not been set")
}

// set KeyTable if it has not already been set
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
}

// NOTE: we pass in the parameter space to the CommitStateDB in order to use custom denominations for the EVM operations
return &Keeper{
cdc: cdc,
paramSpace: paramSpace,
authority: authority,
accountKeeper: ak,
bankKeeper: bankKeeper,
stakingKeeper: sk,
Expand Down Expand Up @@ -141,6 +135,11 @@ func (k Keeper) EmitBlockBloomEvent(ctx sdk.Context, bloom ethtypes.Bloom) {
)
}

// GetAuthority returns the x/evm module's authority address
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
func (k Keeper) GetAuthority() string {
return k.authority
}

// GetBlockBloomTransient returns bloom bytes for the current block height
func (k Keeper) GetBlockBloomTransient(ctx sdk.Context) *big.Int {
store := prefix.NewStore(ctx.TransientStore(k.transientKey), types.KeyPrefixTransientBloom)
Expand Down Expand Up @@ -297,8 +296,7 @@ func (k *Keeper) GetNonce(ctx sdk.Context, addr common.Address) uint64 {
// GetBalance load account's balance of gas token
func (k *Keeper) GetBalance(ctx sdk.Context, addr common.Address) *big.Int {
cosmosAddr := sdk.AccAddress(addr.Bytes())
evmDenom := ""
k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyEVMDenom, &evmDenom)
evmDenom := k.GetParams(ctx).EvmDenom
// if node is pruned, params is empty. Return invalid value
if evmDenom == "" {
return big.NewInt(-1)
Expand Down
2 changes: 2 additions & 0 deletions x/evm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (suite *KeeperTestSuite) SetupTest() {
// SetupApp setup test environment, it uses`require.TestingT` to support both `testing.T` and `testing.B`.
func (suite *KeeperTestSuite) SetupApp(checkTx bool) {
t := suite.T()

// account key, use a constant account to keep unit test deterministic.
ecdsaPriv, err := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
require.NoError(t, err)
Expand Down Expand Up @@ -212,6 +213,7 @@ func (suite *KeeperTestSuite) SetupApp(checkTx bool) {
suite.ethSigner = ethtypes.LatestSignerForChainID(suite.app.EvmKeeper.ChainID())
suite.appCodec = encodingConfig.Codec
suite.denom = evmtypes.DefaultEVMDenom

}

func (suite *KeeperTestSuite) EvmDenom() string {
Expand Down
32 changes: 21 additions & 11 deletions x/evm/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,38 @@ package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
v2 "github.com/evmos/ethermint/x/evm/migrations/v2"
v3 "github.com/evmos/ethermint/x/evm/migrations/v3"
"github.com/evmos/ethermint/x/evm/exported"
v4 "github.com/evmos/ethermint/x/evm/migrations/v4"
)

// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper Keeper
keeper Keeper
legacySubspace exported.Subspace
}

// NewMigrator returns a new Migrator.
func NewMigrator(keeper Keeper) Migrator {
func NewMigrator(keeper Keeper, legacySubspace exported.Subspace) Migrator {
return Migrator{
keeper: keeper,
keeper: keeper,
legacySubspace: legacySubspace,
}
}

// TODO: Figure out if these will be deleted
// Migrate1to2 migrates the store from consensus version v1 to v2
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v2.MigrateStore(ctx, &m.keeper.paramSpace)
}

// NOTE: This migration handler is no longer valid as it's missing deprecated Cosmos SDK params module
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
// func (m Migrator) Migrate1to2(ctx sdk.Context) error {
// return v2.MigrateStore(ctx, &m.keeper.paramSpace)
// }
// TODO: Figure out if these will be deleted
// Migrate2to3 migrates the store from consensus version v2 to v3
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
return v3.MigrateStore(ctx, &m.keeper.paramSpace)
// NOTE: This migration handler is no longer valid as it's missing deprecated Cosmos SDK params module
// func (m Migrator) Migrate2to3(ctx sdk.Context) error {
// return v3.MigrateStore(ctx, &m.keeper.paramSpace)
// }

// Migrate3to4 migrates the store from consensus version v3 to v4
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
func (m Migrator) Migrate3to4(ctx sdk.Context) error {
return v4.MigrateStore(ctx, ctx.KVStore(m.keeper.storeKey), m.legacySubspace, m.keeper.cdc)
}
34 changes: 27 additions & 7 deletions x/evm/keeper/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,43 @@ package keeper_test

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/evmos/ethermint/x/evm/exported"
evmkeeper "github.com/evmos/ethermint/x/evm/keeper"
"github.com/evmos/ethermint/x/evm/types"
)

type mockSubspace struct {
ps types.Params
}

func newMockSubspace(ps types.Params) mockSubspace {
return mockSubspace{ps: ps}
}

func (ms mockSubspace) GetParams(ctx sdk.Context, ps exported.Params) {
*ps.(*types.Params) = ms.ps
}

func (suite *KeeperTestSuite) TestMigrations() {
migrator := evmkeeper.NewMigrator(*suite.app.EvmKeeper)
legacySubspace := newMockSubspace(types.DefaultParams())
migrator := evmkeeper.NewMigrator(*suite.app.EvmKeeper, legacySubspace)

testCases := []struct {
name string
migrateFunc func(ctx sdk.Context) error
}{
// TODO: Figure out if these will be deleted
//{
// "Run Migrate1to2",
// migrator.Migrate1to2,
//},
//{
// "Run Migrate2to3",
// migrator.Migrate2to3,
//},
{
"Run Migrate1to2",
migrator.Migrate1to2,
},
{
"Run Migrate2to3",
migrator.Migrate2to3,
"Run Migrate3to4",
migrator.Migrate3to4,
},
}

Expand Down
Loading