Skip to content

Commit d270e75

Browse files
imp: add not allowed keys to error message of authorization (#5417)
* imp: add not allowed keys to error message of authorization * alternative to getting the keys from the map
1 parent 10ac5ff commit d270e75

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

modules/apps/transfer/types/transfer_authorization.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"math/big"
7+
"sort"
78
"strings"
89

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

179-
if len(jsonObject) > len(allowedPacketDataList) {
180-
return errorsmod.Wrapf(ErrInvalidAuthorization, "packet contains more packet data keys than packet allow list has")
181-
}
182-
183180
gasCostPerIteration := ctx.KVGasConfig().IterNextCostFlat
184181

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

191+
var keys []string
192+
for k := range jsonObject {
193+
keys = append(keys, k)
194+
}
195+
sort.Strings(keys)
196+
194197
if len(jsonObject) != 0 {
195-
return errorsmod.Wrapf(ErrInvalidAuthorization, "packet data not allowed")
198+
return errorsmod.Wrapf(ErrInvalidAuthorization, "not allowed packet data keys: %s", keys)
196199
}
197200

198201
return nil

modules/apps/transfer/types/transfer_authorization_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() {
167167
},
168168
func(res authz.AcceptResponse, err error) {
169169
suite.Require().Error(err)
170+
suite.Require().ErrorContains(err, "not allowed packet data keys: [wasm]")
170171
},
171172
},
172173
{

0 commit comments

Comments
 (0)