Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: x/authz allow insufficient funds error #11252

Merged
merged 9 commits into from
Mar 1, 2022
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (crypto) [#11027] Remove dependency on Tendermint core for xsalsa20symmetric.
* (x/authz) [\#10447](https://github.com/cosmos/cosmos-sdk/pull/10447) Fix authz `NewGrant` expiration check.
* (x/authz) [\#10633](https://github.com/cosmos/cosmos-sdk/pull/10633) Fixed authorization not found error when executing message.
* (x/authz) [\#11252](https://github.com/cosmos/cosmos-sdk/pull/11252) Allow insufficient funds error for authz simulation

### State Machine Breaking

Expand Down
18 changes: 5 additions & 13 deletions x/authz/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func SimulateMsgExec(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keepe

msg := []sdk.Msg{banktype.NewMsgSend(granterAddr, granteeAddr, coins)}
authorization, err := targetGrant.GetAuthorization()
if err != nil{
if err != nil {
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExec, err.Error()), nil, err
}

Expand All @@ -259,17 +259,9 @@ func SimulateMsgExec(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keepe
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExec, "not a send authorization"), nil, nil
}

if sendAuth.SpendLimit.IsAllLTE(coins) {
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExec, "over spend limit"), nil, nil
}

res, err := sendAuth.Accept(ctx, msg[0])
if err != nil {
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExec, err.Error()), nil, err
}

if !res.Accept {
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExec, "expired or invalid grant"), nil, nil
_, err = sendAuth.Accept(ctx, msg[0])
if sdkerrors.ErrInsufficientFunds.Is(err) {
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExec, err.Error()), nil, nil
}
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved

msgExec := authz.NewMsgExec(granteeAddr, msg)
Expand All @@ -278,9 +270,9 @@ func SimulateMsgExec(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keepe
if err != nil {
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExec, "fee error"), nil, err
}

txCfg := simappparams.MakeTestEncodingConfig().TxConfig
granteeAcc := ak.GetAccount(ctx, granteeAddr)

tx, err := helpers.GenTx(
txCfg,
[]sdk.Msg{&msgExec},
Expand Down