From 592362eb277a01aa1edd48cdbcf1c0c4589a70fd Mon Sep 17 00:00:00 2001 From: Tomas Guerra <54514587+GAtom22@users.noreply.github.com> Date: Thu, 16 Feb 2023 15:54:36 -0300 Subject: [PATCH] chore(ante): refactor to run authz anteHander in deliverTx mode (#1403) * chore(ante) refactor to run authz anteHander in deliverTx mode * chore(ante) add changelog entry --- CHANGELOG.md | 1 + app/ante/cosmos/authz.go | 6 ++--- app/ante/cosmos/authz_test.go | 41 +++++++++++++++++------------------ 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c8f5bed07..51bdd153cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ - (contracts) [#1306](https://github.com/evmos/evmos/pull/1306) Migrate `contracts` directory to evmos repository - (proto) [#1305](https://github.com/evmos/evmos/pull/1305) Migrate Ethermint proto files - (ante) [#1266](https://github.com/evmos/evmos/pull/1266) Use `DynamicFeeChecker` for Cosmos txs. +- (ante) [#1403](https://github.com/evmos/evmos/pull/1403) Update `AnteHandler` decorator for `x/authz` messages to run in deliverTx mode ### API Breaking diff --git a/app/ante/cosmos/authz.go b/app/ante/cosmos/authz.go index 150c3fc03e..9fdee79855 100644 --- a/app/ante/cosmos/authz.go +++ b/app/ante/cosmos/authz.go @@ -42,10 +42,8 @@ func NewAuthzLimiterDecorator(disabledMsgTypes ...string) AuthzLimiterDecorator } func (ald AuthzLimiterDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { - if ctx.IsCheckTx() { - if err := ald.checkDisabledMsgs(tx.GetMsgs(), false, 1); err != nil { - return ctx, errorsmod.Wrapf(errortypes.ErrUnauthorized, err.Error()) - } + if err := ald.checkDisabledMsgs(tx.GetMsgs(), false, 1); err != nil { + return ctx, errorsmod.Wrapf(errortypes.ErrUnauthorized, err.Error()) } return next(ctx, tx, simulate) } diff --git a/app/ante/cosmos/authz_test.go b/app/ante/cosmos/authz_test.go index 461fed8c8e..feb2398b3c 100644 --- a/app/ante/cosmos/authz_test.go +++ b/app/ante/cosmos/authz_test.go @@ -52,7 +52,7 @@ func TestAuthzLimiterDecorator(t *testing.T) { sdk.NewCoins(sdk.NewInt64Coin(evmtypes.DefaultEVMDenom, 100e6)), ), }, - true, + false, nil, }, { @@ -60,7 +60,7 @@ func TestAuthzLimiterDecorator(t *testing.T) { []sdk.Msg{ &evmtypes.MsgEthereumTx{}, }, - true, + false, nil, }, { @@ -68,7 +68,7 @@ func TestAuthzLimiterDecorator(t *testing.T) { []sdk.Msg{ &stakingtypes.MsgCancelUnbondingDelegation{}, }, - true, + false, nil, }, { @@ -81,7 +81,7 @@ func TestAuthzLimiterDecorator(t *testing.T) { &distantFuture, ), }, - true, + false, nil, }, { @@ -94,7 +94,7 @@ func TestAuthzLimiterDecorator(t *testing.T) { &distantFuture, ), }, - true, + false, nil, }, { @@ -107,7 +107,7 @@ func TestAuthzLimiterDecorator(t *testing.T) { &distantFuture, ), }, - true, + false, sdkerrors.ErrUnauthorized, }, { @@ -120,7 +120,7 @@ func TestAuthzLimiterDecorator(t *testing.T) { &distantFuture, ), }, - true, + false, sdkerrors.ErrUnauthorized, }, { @@ -134,7 +134,7 @@ func TestAuthzLimiterDecorator(t *testing.T) { sdk.NewCoins(sdk.NewInt64Coin(evmtypes.DefaultEVMDenom, 100e6)), )}), }, - true, + false, nil, }, { @@ -147,7 +147,7 @@ func TestAuthzLimiterDecorator(t *testing.T) { }, ), }, - true, + false, sdkerrors.ErrUnauthorized, }, { @@ -171,7 +171,7 @@ func TestAuthzLimiterDecorator(t *testing.T) { }, ), }, - true, + false, sdkerrors.ErrUnauthorized, }, { @@ -185,7 +185,7 @@ func TestAuthzLimiterDecorator(t *testing.T) { }, ), }, - true, + false, sdkerrors.ErrUnauthorized, }, { @@ -203,7 +203,7 @@ func TestAuthzLimiterDecorator(t *testing.T) { }, ), }, - true, + false, sdkerrors.ErrUnauthorized, }, { @@ -221,7 +221,7 @@ func TestAuthzLimiterDecorator(t *testing.T) { }, ), }, - true, + false, sdkerrors.ErrUnauthorized, }, { @@ -250,7 +250,7 @@ func TestAuthzLimiterDecorator(t *testing.T) { }, ), }, - true, + false, sdkerrors.ErrUnauthorized, }, } @@ -418,13 +418,12 @@ func (suite *AnteTestSuite) TestRejectMsgsInAuthz() { ) suite.Require().Equal(resCheckTx.Code, tc.expectedCode, resCheckTx.Log) - // TODO uncomment this on v12 release. ATM the anteHandler works on CheckTx mode - // resDeliverTx := suite.app.DeliverTx( - // abci.RequestDeliverTx{ - // Tx: bz, - // }, - // ) - // suite.Require().Equal(resDeliverTx.Code, tc.expectedCode, resDeliverTx.Log) + resDeliverTx := suite.app.DeliverTx( + abci.RequestDeliverTx{ + Tx: bz, + }, + ) + suite.Require().Equal(resDeliverTx.Code, tc.expectedCode, resDeliverTx.Log) }) } }