From eee53a9500e5260ddc51fa51d3a4e48b3da65d8e Mon Sep 17 00:00:00 2001 From: yihuang Date: Mon, 21 Jun 2021 15:59:45 +0800 Subject: [PATCH] ante: add `ValidateMemoDecorator` evm tx (#150) fixes #149 --- app/ante/ante.go | 1 + app/ante/ante_test.go | 12 ++++++++++++ app/ante/utils_test.go | 9 ++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/ante/ante.go b/app/ante/ante.go index 05c541ec..55425583 100644 --- a/app/ante/ante.go +++ b/app/ante/ante.go @@ -64,6 +64,7 @@ func NewAnteHandler( authante.NewMempoolFeeDecorator(), authante.NewValidateBasicDecorator(), authante.TxTimeoutHeightDecorator{}, + authante.NewValidateMemoDecorator(ak), NewEthSigVerificationDecorator(evmKeeper), NewEthAccountVerificationDecorator(ak, bankKeeper, evmKeeper), NewEthNonceVerificationDecorator(ak), diff --git a/app/ante/ante_test.go b/app/ante/ante_test.go index 13311ffd..cbac5211 100644 --- a/app/ante/ante_test.go +++ b/app/ante/ante_test.go @@ -2,6 +2,7 @@ package ante_test import ( "math/big" + "strings" sdk "github.com/cosmos/cosmos-sdk/types" @@ -91,6 +92,17 @@ func (suite AnteTestSuite) TestAnteHandler() { return tx }, 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 { diff --git a/app/ante/utils_test.go b/app/ante/utils_test.go index cbc5e753..31589f8f 100644 --- a/app/ante/utils_test.go +++ b/app/ante/utils_test.go @@ -73,6 +73,13 @@ func TestAnteTestSuite(t *testing.T) { func (suite *AnteTestSuite) CreateTestTx( msg *evmtypes.MsgEthereumTx, priv cryptotypes.PrivKey, accNum uint64, ) 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{}) suite.Require().NoError(err) @@ -125,7 +132,7 @@ func (suite *AnteTestSuite) CreateTestTx( err = suite.txBuilder.SetSignatures(sigsV2...) suite.Require().NoError(err) - return suite.txBuilder.GetTx() + return suite.txBuilder } func newTestAddrKey() (common.Address, cryptotypes.PrivKey) {