Make IsJSONObjectWithTopLevelKey public

This commit is contained in:
Simon Warta 2022-04-27 16:59:50 +02:00
parent 8fc4714a0b
commit 1e892acd36
2 changed files with 3 additions and 3 deletions

View File

@ -6,9 +6,9 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// isJSONObjectWithTopLevelKey checks if the given bytes are a valid JSON object
// IsJSONObjectWithTopLevelKey checks if the given bytes are a valid JSON object
// with exactly one top-level key that is contained in the list of allowed keys.
func isJSONObjectWithTopLevelKey(jsonBytes []byte, allowedKeys []string) error {
func IsJSONObjectWithTopLevelKey(jsonBytes []byte, allowedKeys []string) error {
document := map[string]interface{}{}
if err := json.Unmarshal(jsonBytes, &document); err != nil {
return sdkerrors.Wrap(ErrNotAJSONObject, "failed to unmarshal JSON to map")

View File

@ -103,7 +103,7 @@ func TestIsJSONObjectWithTopLevelKey(t *testing.T) {
}
for name, spec := range specs {
t.Run(name, func(t *testing.T) {
result := isJSONObjectWithTopLevelKey(spec.src, spec.allowedKeys)
result := IsJSONObjectWithTopLevelKey(spec.src, spec.allowedKeys)
if spec.exp == nil {
require.NoError(t, result)
} else {