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

imp: add not allowed keys to error message of authorization #5417

Merged
merged 4 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions modules/apps/transfer/types/transfer_authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"math/big"
"sort"
"strings"

"github.com/cosmos/gogoproto/proto"
Expand Down Expand Up @@ -176,10 +177,6 @@ func validateMemo(ctx sdk.Context, memo string, allowedPacketDataList []string)
return err
}

if len(jsonObject) > len(allowedPacketDataList) {
return errorsmod.Wrapf(ErrInvalidAuthorization, "packet contains more packet data keys than packet allow list has")
}
Comment on lines -179 to -181
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this because I thought it would not add much value if the error doesn't tell the user what keys are not allowed.


gasCostPerIteration := ctx.KVGasConfig().IterNextCostFlat

for _, key := range allowedPacketDataList {
Expand All @@ -191,8 +188,14 @@ func validateMemo(ctx sdk.Context, memo string, allowedPacketDataList []string)
}
}

var keys []string
for k := range jsonObject {
keys = append(keys, k)
}
sort.Strings(keys)

if len(jsonObject) != 0 {
return errorsmod.Wrapf(ErrInvalidAuthorization, "packet data not allowed")
return errorsmod.Wrapf(ErrInvalidAuthorization, "not allowed packet data keys: %s", keys)
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() {
},
func(res authz.AcceptResponse, err error) {
suite.Require().Error(err)
suite.Require().ErrorContains(err, "not allowed packet data keys: [wasm]")
},
},
{
Expand Down
Loading