2020-04-01 18:49:21 +00:00
|
|
|
package ante_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2021-05-31 09:05:32 +00:00
|
|
|
"github.com/ethereum/go-ethereum/params"
|
2020-04-01 18:49:21 +00:00
|
|
|
|
|
|
|
evmtypes "github.com/cosmos/ethermint/x/evm/types"
|
|
|
|
)
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
func (suite AnteTestSuite) TestAnteHandler() {
|
|
|
|
addr, privKey := newTestAddrKey()
|
|
|
|
to, _ := newTestAddrKey()
|
2020-04-01 18:49:21 +00:00
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
signedContractTx := evmtypes.NewMsgEthereumTxContract(suite.app.EvmKeeper.ChainID(), 1, big.NewInt(10), 100000, big.NewInt(1), nil, nil)
|
|
|
|
signedContractTx.From = addr.Hex()
|
2020-04-01 18:49:21 +00:00
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
signedTx := evmtypes.NewMsgEthereumTx(suite.app.EvmKeeper.ChainID(), 2, &to, big.NewInt(10), 100000, big.NewInt(1), nil, nil)
|
|
|
|
signedTx.From = addr.Hex()
|
2020-04-01 18:49:21 +00:00
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
txContract := suite.CreateTestTx(signedContractTx, privKey, 1)
|
2020-04-01 18:49:21 +00:00
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder()
|
|
|
|
tx := suite.CreateTestTx(signedTx, privKey, 1)
|
2020-04-01 18:49:21 +00:00
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, addr.Bytes())
|
|
|
|
suite.Require().NoError(acc.SetSequence(1))
|
2020-04-01 18:49:21 +00:00
|
|
|
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
err := suite.app.BankKeeper.SetBalance(suite.ctx, addr.Bytes(), sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(10000000000)))
|
2020-04-23 15:49:25 +00:00
|
|
|
suite.Require().NoError(err)
|
2020-04-01 18:49:21 +00:00
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
tx sdk.Tx
|
|
|
|
checkTx bool
|
|
|
|
reCheckTx bool
|
|
|
|
expPass bool
|
|
|
|
}{
|
|
|
|
{"success - DeliverTx (contract)", txContract, false, false, true},
|
|
|
|
{"success - CheckTx (contract)", txContract, true, false, true},
|
|
|
|
{"success - ReCheckTx (contract)", txContract, false, true, true},
|
|
|
|
{"success - DeliverTx", tx, false, false, true},
|
|
|
|
{"success - CheckTx", tx, true, false, true},
|
|
|
|
{"success - ReCheckTx", tx, false, true, true},
|
|
|
|
}
|
2020-04-01 18:49:21 +00:00
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
for _, tc := range testCases {
|
|
|
|
suite.Run(tc.name, func() {
|
2020-04-01 18:49:21 +00:00
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
suite.ctx = suite.ctx.WithIsCheckTx(tc.reCheckTx).WithIsReCheckTx(tc.reCheckTx)
|
2020-04-01 18:49:21 +00:00
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
expConsumed := params.TxGasContractCreation + params.TxGas
|
|
|
|
_, err := suite.anteHandler(suite.ctx, tc.tx, false)
|
2020-04-01 18:49:21 +00:00
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
// suite.Require().Equal(consumed, ctx.GasMeter().GasConsumed())
|
2020-04-01 18:49:21 +00:00
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
if tc.expPass {
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
suite.Require().Equal(int(expConsumed), int(suite.ctx.GasMeter().GasConsumed()))
|
|
|
|
} else {
|
|
|
|
suite.Require().Error(err)
|
|
|
|
}
|
2020-04-01 18:49:21 +00:00
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
})
|
|
|
|
}
|
2020-04-23 15:49:25 +00:00
|
|
|
|
2020-04-01 18:49:21 +00:00
|
|
|
}
|