From ef6fed67de0eead7598eaec305244a150e9ef754 Mon Sep 17 00:00:00 2001 From: atheeshp <59333759+atheeshp@users.noreply.github.com> Date: Thu, 24 Feb 2022 17:58:13 +0530 Subject: [PATCH] fix: case unauthorized message (#11229) * fix: case unauthorized message * changes * Update x/feegrant/client/testutil/suite.go * review changes * Update client/broadcast.go * udpate changelog * update changelog Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com> --- CHANGELOG.md | 5 ++-- client/broadcast.go | 9 +++++++ x/feegrant/client/testutil/suite.go | 38 +++++++++++++---------------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47159c171e2a..70a871a38ee7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -200,7 +200,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#10466](https://github.com/cosmos/cosmos-sdk/issues/10466) Fixes error with simulation tests when genesis start time is randomly created after the year 2262 * [\#10394](https://github.com/cosmos/cosmos-sdk/issues/10394) Fixes issue related to grpc-gateway of account balance by ibc-denom. -* [\#10593](https://github.com/cosmos/cosmos-sdk/pull/10593) Update swagger-ui to v4.1.0 to fix xss vulnerability. +* [\#10593](https://github.com/cosmos/cosmos-sdk/pull/10593) Update swagger-ui to v4.1.0 to fix xss vulnerability. * [\#10842](https://github.com/cosmos/cosmos-sdk/pull/10842) Fix error when `--generate-only`, `--max-msgs` fags set while executing `WithdrawAllRewards` command. * [\#10897](https://github.com/cosmos/cosmos-sdk/pull/10897) Fix: set a non-zero value on gas overflow. * [#9790](https://github.com/cosmos/cosmos-sdk/pull/10687) Fix behavior of `DecCoins.MulDecTruncate`. @@ -208,7 +208,8 @@ 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. -* [#11222](https://github.com/cosmos/cosmos-sdk/pull/11222) reject query with block height in the future +* [#11222](https://github.com/cosmos/cosmos-sdk/pull/11222) reject query with block height in the future +* [#11229](https://github.com/cosmos/cosmos-sdk/pull/11229) Handled the error message of `transaction encountered error` from tendermint. ### State Machine Breaking diff --git a/client/broadcast.go b/client/broadcast.go index 15d6f4fb9d3d..35af14e21aa5 100644 --- a/client/broadcast.go +++ b/client/broadcast.go @@ -98,6 +98,15 @@ func (ctx Context) BroadcastTxCommit(txBytes []byte) (*sdk.TxResponse, error) { return sdk.NewResponseFormatBroadcastTxCommit(res), nil } + // with these changes(https://github.com/tendermint/tendermint/pull/7683) + // in tendermint, we receive both an error and a non-empty res from TM. Here + // we handle the case where both are relevant. Note: without this edge-case handling, + // CLI is breaking (for few transactions ex: executing unathorized messages in feegrant) + // this check is added to tackle the particular case. + if strings.Contains(err.Error(), "transaction encountered error") { + return sdk.NewResponseFormatBroadcastTxCommit(res), nil + } + if errRes := CheckTendermintError(err, txBytes); errRes != nil { return errRes, nil } diff --git a/x/feegrant/client/testutil/suite.go b/x/feegrant/client/testutil/suite.go index 38d01577b20c..5ebbefef81e7 100644 --- a/x/feegrant/client/testutil/suite.go +++ b/x/feegrant/client/testutil/suite.go @@ -912,28 +912,24 @@ func (s *IntegrationTestSuite) TestFilteredFeeAllowance() { &sdk.TxResponse{}, 2, }, - /* TODO(#10559): This case times out after TM v0.35. - Figure out why and fix it. - - { - "should fail with unauthorized msgs", - func() (testutil.BufferWriter, error) { - args := append( - []string{ - grantee.String(), - "cosmos14cm33pvnrv2497tyt8sp9yavhmw83nwej3m0e8", - fmt.Sprintf("--%s=%s", cli.FlagSpendLimit, "100stake"), - fmt.Sprintf("--%s=%s", flags.FlagFeeGranter, granter), - }, - commonFlags..., - ) - cmd := cli.NewCmdFeeGrant() - return clitestutil.ExecTestCLICmd(clientCtx, cmd, args) + { + "should fail with unauthorized msgs", + func() (testutil.BufferWriter, error) { + args := append( + []string{ + grantee.String(), + "cosmos14cm33pvnrv2497tyt8sp9yavhmw83nwej3m0e8", + fmt.Sprintf("--%s=%s", cli.FlagSpendLimit, "100stake"), + fmt.Sprintf("--%s=%s", flags.FlagFeeGranter, granter), }, - &sdk.TxResponse{}, - 7, - }, - */ + commonFlags..., + ) + cmd := cli.NewCmdFeeGrant() + return clitestutil.ExecTestCLICmd(clientCtx, cmd, args) + }, + &sdk.TxResponse{}, + 7, + }, } for _, tc := range cases {