Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Add minor code-quality refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
0a1c committed Apr 6, 2023
1 parent 44da689 commit aeabde4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 82 deletions.
12 changes: 6 additions & 6 deletions app/ante/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ func (ald AuthzLimiterDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate

// checkDisabledMsgs iterates through the msgs and returns an error if it finds any unauthorized msgs.
//
// This method is recursive as MsgExec's can wrap other MsgExecs. The check for nested messages is capped at
// maxNestedMsgs total MsgExec messages.
func (ald AuthzLimiterDecorator) checkDisabledMsgs(msgs []sdk.Msg, isAuthzInnerMsg bool, totalMsgs int) error {
if totalMsgs >= maxNestedMsgs {
// This method is recursive as MsgExec's can wrap other MsgExecs. nestedMsgs sets a reasonable limit on
// the total messages, regardless of how they are nested.
func (ald AuthzLimiterDecorator) checkDisabledMsgs(msgs []sdk.Msg, isAuthzInnerMsg bool, nestedMsgs int) error {
if nestedMsgs >= maxNestedMsgs {
return fmt.Errorf("found more nested msgs than permitted. Limit is : %d", maxNestedMsgs)
}
for _, msg := range msgs {
Expand All @@ -69,8 +69,8 @@ func (ald AuthzLimiterDecorator) checkDisabledMsgs(msgs []sdk.Msg, isAuthzInnerM
if err != nil {
return err
}
totalMsgs++
if err := ald.checkDisabledMsgs(innerMsgs, true, totalMsgs); err != nil {
nestedMsgs++
if err := ald.checkDisabledMsgs(innerMsgs, true, nestedMsgs); err != nil {
return err
}
case *authz.MsgGrant:
Expand Down
14 changes: 6 additions & 8 deletions app/ante/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (suite *AnteTestSuite) TestAuthzLimiterDecorator() {
{
"enabled msg - blocked msg not wrapped in MsgExec",
[]sdk.Msg{
&stakingtypes.MsgCancelUnbondingDelegation{},
&stakingtypes.MsgUndelegate{},
},
nil,
},
Expand Down Expand Up @@ -104,7 +104,7 @@ func (suite *AnteTestSuite) TestAuthzLimiterDecorator() {
[]sdk.Msg{
newGenericMsgGrant(
testAddresses,
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
sdk.MsgTypeURL(testMsgEthereumTx),
),
},
sdkerrors.ErrUnauthorized,
Expand All @@ -126,7 +126,8 @@ func (suite *AnteTestSuite) TestAuthzLimiterDecorator() {
testAddresses[1],
[]sdk.Msg{
testMsgSend,
}),
},
),
},
nil,
},
Expand Down Expand Up @@ -180,7 +181,7 @@ func (suite *AnteTestSuite) TestAuthzLimiterDecorator() {
[]sdk.Msg{
newGenericMsgGrant(
testAddresses,
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
sdk.MsgTypeURL(testMsgEthereumTx),
),
},
),
Expand All @@ -195,7 +196,7 @@ func (suite *AnteTestSuite) TestAuthzLimiterDecorator() {
sdkerrors.ErrUnauthorized,
},
{
"disabled msg - multiple two nested MsgExec messages NOT containing a blocked msg over the limit",
"disabled msg - two multiple nested MsgExec messages NOT containing a blocked msg over the limit",
[]sdk.Msg{
createNestedExecMsgSend(testAddresses, 5),
createNestedExecMsgSend(testAddresses, 5),
Expand Down Expand Up @@ -418,9 +419,6 @@ func (suite *AnteTestSuite) createTx(priv cryptotypes.PrivKey, msgs ...sdk.Msg)
Msgs: msgs,
}

acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, addr)
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)

return utiltx.PrepareCosmosTx(suite.ctx, suite.app, args)
}

Expand Down
5 changes: 2 additions & 3 deletions app/ante/eip712.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ func init() {
func NewLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
RejectMessagesDecorator{}, // reject MsgEthereumTxs
NewAuthzLimiterDecorator( // disable the Msg types that cannot be included on an authz.MsgExec msgs field
options.DisabledAuthzMsgs,
),
// disable the Msg types that cannot be included on an authz.MsgExec msgs field
NewAuthzLimiterDecorator(options.DisabledAuthzMsgs),
authante.NewSetUpContextDecorator(),
authante.NewValidateBasicDecorator(),
authante.NewTxTimeoutHeightDecorator(),
Expand Down
Loading

0 comments on commit aeabde4

Please sign in to comment.