laconicd-deprecated/x/evm/keeper/msg_server_test.go
Tomas Guerra f04b289e75
ime(evm): improve code coverage for EVM keeper (#1396)
* [issue-1018] add new tests on evm module keeper

* [issue-1018] add more new tests on evm module keeper

* [issue-1018] add more new tests on evm module keeper (state_transition, statedb, utils)

* [issue-1018] add more new tests on evm module keeper (msg_server)

* [issue-1018] fix code style

* [issue-1018] add changes in CHANGELOG

* [issue-1018] add missing error check in grpc_query_test

* [issue-1018] fix failing tests

* [issue-1018] add changes based on review comments (grpc_query_test & abci_test)

* [issue-1018] add GenerateAddress in TestEthCall (grpc_query_test)

* [issue-1018] remove unnecessary SetupTest calls

* [issue-1018] refactor SetupTest calls (grpc_query_test & statedb_test)
2022-10-21 18:59:03 +02:00

81 lines
1.7 KiB
Go

package keeper_test
import (
"math/big"
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())
})
}
}