laconicd-deprecated/x/evm/keeper/msg_server_test.go
Vladislav Varadinov 0f7bdceaa0
chore(evm): Deprecate x/params usage in x/evm (#1472)
* imp(evm): Migrate from old Cosmos SDK params module to new way of keeping params in module Keeper

* Updated changelog

* Apply changes from code review

* (impv): Added Shanghai and Cancun blocks to current types and latest migration

* (tests): Update unit tests to include Shanghai and Cancun blocks

* (fix) - ran golangci-lint on the entire project

* (fix) - remove deprecated params method

* (impv): added marshaling of booleans per individual param key

* (impv): added individual param getting and setting

* (impv): replaced getters with individual param

* (impv): added amino codec for MsgEthereumTx

* Added changes suggested in code review

* (fix): updated the migration files for v4

* (fix): fixed unit tests panic for incorrect interface

* (fix): updated module msg handler

* (fix): rename to original params getter method

* (refactor): registered implementation for the new msg

* (refactor): added correct amino codec for MsgUpdateParams and removed for MsgEthTx

* Applied changes from code review

* (fix): removed unnecessary duplicate

* (fix): removed params_legacy from the types and moved logic to migration

* (fix): Added v4 mocks to the migrations_test

* (fix): undo all the non related work regarding the Cancun and Shanghai blocks

* (fix): reverted linting the entire project - will make a separate PR for it

* Applied changes from review

* Applied changes from code review

* (fix): removed comments

* (fix): Ran formatter and fixed linting issues on unsed functions

* (fix): Linting issues resolved

* (fix): refactor migrations and added default EIPs

* (fix): Combined into one call

* (fix): Added more straightforward way to handle migration

* (fix): corrected migration test

* Applied changes from code review

* (fix): Linter fix

* (fix): Linter

* (fix): Lint proto files

* Apply suggestions from code review

Co-authored-by: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com>

* (fix): Added new block to migration

* (fix): Added additional comments and formatted proto files

* (fix): Added name to unit test cases

* (fix): removed unused import

* Apply changes from code review

* (fix): typo

* (fix): remove HTTP endpoint exposure

* Apply suggestions from code review

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>

* applied changes from code review

* fix: extra line added in merge removed

* fix: applied changes from code review

Co-authored-by: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com>
Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
2023-01-04 16:28:45 +02:00

118 lines
2.6 KiB
Go

package keeper_test
import (
"math/big"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/evmos/ethermint/x/evm/statedb"
"github.com/evmos/ethermint/x/evm/types"
)
func (suite *KeeperTestSuite) TestEthereumTx() {
var (
err error
msg *types.MsgEthereumTx
signer ethtypes.Signer
vmdb *statedb.StateDB
chainCfg *params.ChainConfig
expectedGasUsed uint64
)
testCases := []struct {
name string
malleate func()
expErr bool
}{
{
"Deploy contract tx - insufficient gas",
func() {
msg, err = suite.createContractMsgTx(
vmdb.GetNonce(suite.address),
signer,
chainCfg,
big.NewInt(1),
)
suite.Require().NoError(err)
},
true,
},
{
"Transfer funds tx",
func() {
msg, _, err = newEthMsgTx(
vmdb.GetNonce(suite.address),
suite.ctx.BlockHeight(),
suite.address,
chainCfg,
suite.signer,
signer,
ethtypes.AccessListTxType,
nil,
nil,
)
suite.Require().NoError(err)
expectedGasUsed = params.TxGas
},
false,
},
}
for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.SetupTest()
keeperParams := suite.app.EvmKeeper.GetParams(suite.ctx)
chainCfg = keeperParams.ChainConfig.EthereumConfig(suite.app.EvmKeeper.ChainID())
signer = ethtypes.LatestSignerForChainID(suite.app.EvmKeeper.ChainID())
vmdb = suite.StateDB()
tc.malleate()
res, err := suite.app.EvmKeeper.EthereumTx(suite.ctx, msg)
if tc.expErr {
suite.Require().Error(err)
return
}
suite.Require().NoError(err)
suite.Require().Equal(expectedGasUsed, res.GasUsed)
suite.Require().False(res.Failed())
})
}
}
func (suite *KeeperTestSuite) TestUpdateParams() {
testCases := []struct {
name string
request *types.MsgUpdateParams
expectErr bool
}{
{
name: "fail - invalid authority",
request: &types.MsgUpdateParams{Authority: "foobar"},
expectErr: true,
},
{
name: "pass - valid Update msg",
request: &types.MsgUpdateParams{
Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Params: types.DefaultParams(),
},
expectErr: false,
},
}
for _, tc := range testCases {
tc := tc
suite.Run("MsgUpdateParams", func() {
_, err := suite.app.EvmKeeper.UpdateParams(suite.ctx, tc.request)
if tc.expectErr {
suite.Require().Error(err)
} else {
suite.Require().NoError(err)
}
})
}
}