Skip to content

Commit

Permalink
imp: add not allowed keys to error message of authorization (cosmos#5417
Browse files Browse the repository at this point in the history
)

* imp: add not allowed keys to error message of authorization

* alternative to getting the keys from the map
  • Loading branch information
crodriguezvega committed Dec 18, 2023
1 parent 10ac5ff commit d270e75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
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")
}

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
1 change: 1 addition & 0 deletions modules/apps/transfer/types/transfer_authorization_test.go
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

0 comments on commit d270e75

Please sign in to comment.