ante: add ValidateMemoDecorator evm tx (#150)

fixes #149
This commit is contained in:
yihuang 2021-06-21 15:59:45 +08:00 committed by GitHub
parent 6be18a1cb4
commit eee53a9500
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View File

@ -64,6 +64,7 @@ func NewAnteHandler(
authante.NewMempoolFeeDecorator(), authante.NewMempoolFeeDecorator(),
authante.NewValidateBasicDecorator(), authante.NewValidateBasicDecorator(),
authante.TxTimeoutHeightDecorator{}, authante.TxTimeoutHeightDecorator{},
authante.NewValidateMemoDecorator(ak),
NewEthSigVerificationDecorator(evmKeeper), NewEthSigVerificationDecorator(evmKeeper),
NewEthAccountVerificationDecorator(ak, bankKeeper, evmKeeper), NewEthAccountVerificationDecorator(ak, bankKeeper, evmKeeper),
NewEthNonceVerificationDecorator(ak), NewEthNonceVerificationDecorator(ak),

View File

@ -2,6 +2,7 @@ package ante_test
import ( import (
"math/big" "math/big"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
@ -91,6 +92,17 @@ func (suite AnteTestSuite) TestAnteHandler() {
return tx return tx
}, false, true, true, }, false, true, true,
}, },
{
"fail - CheckTx (memo too long)",
func() sdk.Tx {
signedTx := evmtypes.NewMsgEthereumTx(suite.app.EvmKeeper.ChainID(), 3, &to, big.NewInt(10), 100000, big.NewInt(1), nil, nil)
signedTx.From = addr.Hex()
txBuilder := suite.CreateTestTxBuilder(signedTx, privKey, 1)
txBuilder.SetMemo(strings.Repeat("*", 257))
return txBuilder.GetTx()
}, true, false, false,
},
} }
for _, tc := range testCases { for _, tc := range testCases {

View File

@ -73,6 +73,13 @@ func TestAnteTestSuite(t *testing.T) {
func (suite *AnteTestSuite) CreateTestTx( func (suite *AnteTestSuite) CreateTestTx(
msg *evmtypes.MsgEthereumTx, priv cryptotypes.PrivKey, accNum uint64, msg *evmtypes.MsgEthereumTx, priv cryptotypes.PrivKey, accNum uint64,
) authsigning.Tx { ) authsigning.Tx {
return suite.CreateTestTxBuilder(msg, priv, accNum).GetTx()
}
// CreateTestTxBuilder is a helper function to create a tx builder given multiple inputs.
func (suite *AnteTestSuite) CreateTestTxBuilder(
msg *evmtypes.MsgEthereumTx, priv cryptotypes.PrivKey, accNum uint64,
) client.TxBuilder {
option, err := codectypes.NewAnyWithValue(&evmtypes.ExtensionOptionsEthereumTx{}) option, err := codectypes.NewAnyWithValue(&evmtypes.ExtensionOptionsEthereumTx{})
suite.Require().NoError(err) suite.Require().NoError(err)
@ -125,7 +132,7 @@ func (suite *AnteTestSuite) CreateTestTx(
err = suite.txBuilder.SetSignatures(sigsV2...) err = suite.txBuilder.SetSignatures(sigsV2...)
suite.Require().NoError(err) suite.Require().NoError(err)
return suite.txBuilder.GetTx() return suite.txBuilder
} }
func newTestAddrKey() (common.Address, cryptotypes.PrivKey) { func newTestAddrKey() (common.Address, cryptotypes.PrivKey) {