Skip to content

Commit

Permalink
chore(ante): refactor to run authz anteHander in deliverTx mode (evmo…
Browse files Browse the repository at this point in the history
…s#1403)

* chore(ante) refactor to run authz anteHander in deliverTx mode

* chore(ante) add changelog entry
  • Loading branch information
GAtom22 authored Feb 16, 2023
1 parent 0af5d31 commit 592362e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions app/ante/cosmos/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
41 changes: 20 additions & 21 deletions app/ante/cosmos/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@ func TestAuthzLimiterDecorator(t *testing.T) {
sdk.NewCoins(sdk.NewInt64Coin(evmtypes.DefaultEVMDenom, 100e6)),
),
},
true,
false,
nil,
},
{
"enabled msg MsgEthereumTx - blocked msg not wrapped in MsgExec",
[]sdk.Msg{
&evmtypes.MsgEthereumTx{},
},
true,
false,
nil,
},
{
"enabled msg - blocked msg not wrapped in MsgExec",
[]sdk.Msg{
&stakingtypes.MsgCancelUnbondingDelegation{},
},
true,
false,
nil,
},
{
Expand All @@ -81,7 +81,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
&distantFuture,
),
},
true,
false,
nil,
},
{
Expand All @@ -94,7 +94,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
&distantFuture,
),
},
true,
false,
nil,
},
{
Expand All @@ -107,7 +107,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
&distantFuture,
),
},
true,
false,
sdkerrors.ErrUnauthorized,
},
{
Expand All @@ -120,7 +120,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
&distantFuture,
),
},
true,
false,
sdkerrors.ErrUnauthorized,
},
{
Expand All @@ -134,7 +134,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
sdk.NewCoins(sdk.NewInt64Coin(evmtypes.DefaultEVMDenom, 100e6)),
)}),
},
true,
false,
nil,
},
{
Expand All @@ -147,7 +147,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
},
),
},
true,
false,
sdkerrors.ErrUnauthorized,
},
{
Expand All @@ -171,7 +171,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
},
),
},
true,
false,
sdkerrors.ErrUnauthorized,
},
{
Expand All @@ -185,7 +185,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
},
),
},
true,
false,
sdkerrors.ErrUnauthorized,
},
{
Expand All @@ -203,7 +203,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
},
),
},
true,
false,
sdkerrors.ErrUnauthorized,
},
{
Expand All @@ -221,7 +221,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
},
),
},
true,
false,
sdkerrors.ErrUnauthorized,
},
{
Expand Down Expand Up @@ -250,7 +250,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
},
),
},
true,
false,
sdkerrors.ErrUnauthorized,
},
}
Expand Down Expand Up @@ -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)
})
}
}

0 comments on commit 592362e

Please sign in to comment.