2022-10-21 16:59:03 +00:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
|
2023-01-04 11:04:38 +00:00
|
|
|
"github.com/cerc-io/laconicd/x/evm/statedb"
|
|
|
|
"github.com/cerc-io/laconicd/x/evm/types"
|
2022-10-21 16:59:03 +00:00
|
|
|
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
|
|
|
"github.com/ethereum/go-ethereum/params"
|
|
|
|
)
|
|
|
|
|
|
|
|
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())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|