Skip to content

Commit

Permalink
fix: fixing authz messages decoding issue in antehandlers (#418)
Browse files Browse the repository at this point in the history
* fixing authz messages decoding issue

* Update CHANGELOG.md

* adding test for authz decode
  • Loading branch information
spoo-bar authored Jul 7, 2023
1 parent be633fd commit ee212ab
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Contains all the PRs that improved the code without changing the behaviours.
### Fixed

- [#414](https://github.com/archway-network/archway/pull/414) - Preventing user from setting contract flat fee if rewards address is not set
- [#418](https://github.com/archway-network/archway/pull/418) - Fixing authz msg decoding in x/rewards antehandlers

## [v1.0.1]

Expand Down
14 changes: 7 additions & 7 deletions x/rewards/ante/ante_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ func GetContractFlatFees(ctx sdk.Context, rk RewardsKeeperExpected, codec codec.
}
return nil, true, nil
}
case *authz.MsgExec: // if msg is authz msg, unwrap the msg and check if any are wasmTypes.MsgExecuteContract
case *authz.MsgExec: // if msg is authz msg, get the unwrapped msgs and check if any are wasmTypes.MsgExecuteContract
{
for _, v := range msg.Msgs {
var wrappedMsg sdk.Msg
err := codec.UnpackAny(v, &wrappedMsg)
if err != nil {
return nil, false, sdkErrors.Wrapf(sdkErrors.ErrUnauthorized, "error decoding authz messages")
}
authzMsgs, err := msg.GetMessages()
if err != nil {
return nil, false, sdkErrors.Wrapf(sdkErrors.ErrUnauthorized, "error decoding authz messages")
}

for _, wrappedMsg := range authzMsgs {
cff, hasWasmMsgs, err := GetContractFlatFees(ctx, rk, codec, wrappedMsg)
if err != nil {
return nil, hasWasmMsgs, err
Expand Down
26 changes: 26 additions & 0 deletions x/rewards/ante/min_cons_fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkErrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/authz"
stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -360,3 +361,28 @@ func TestRewardsContractFlatFeeAnteHandler(t *testing.T) {
})
}
}

func TestAuthzDecodeAntehandler(t *testing.T) {
chain := e2eTesting.NewTestChain(t, 1)
minConsFee, _ := sdk.ParseDecCoin("0.1stake") // Set min consensus fee
chain.GetApp().RewardsKeeper.GetState().MinConsensusFee(chain.GetContext()).SetFee(minConsFee)
txFees, _ := sdk.ParseCoinsNormalized("100stake")

// Making a wrapped MsgDelegate
authzMsg := authz.NewMsgExec(sdk.AccAddress{}, []sdk.Msg{&stakingTypes.MsgDelegate{
DelegatorAddress: e2eTesting.TestAccountAddr.String(),
ValidatorAddress: sdk.ValAddress(e2eTesting.TestAccountAddr).String(),
Amount: sdk.NewInt64Coin("stake", 10),
}})

tx := testutils.NewMockFeeTx(
testutils.WithMockFeeTxFees(txFees),
testutils.WithMockFeeTxGas(1000),
testutils.WithMockFeeTxMsgs([]sdk.Msg{&authzMsg}...),
)

anteHandler := ante.NewMinFeeDecorator(chain.GetAppCodec(), chain.GetApp().RewardsKeeper)
_, err := anteHandler.AnteHandle(chain.GetContext(), tx, false, testutils.NoopAnteHandler)

require.NoError(t, err)
}

0 comments on commit ee212ab

Please sign in to comment.