UNPKG

@cosmology/ast

Version:
875 lines (873 loc) 31.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Timestamp = exports.Grant = exports.GenericAuthorization = exports.CustomizedAuthorization = exports.Authorization_ToSDK = exports.Authorization_ToAmino = exports.Authorization_InterfaceEncoder = exports.Authorization_InterfaceDecoder = exports.Authorization_FromSDK = exports.Authorization_FromPartial = exports.Authorization_FromAmino = exports.Any = void 0; exports.asCustomizedAuthorization = asCustomizedAuthorization; exports.isGenericAuthorization = isGenericAuthorization; var _helpers = require("../../../test-utils/helpers"); var _binary = require("../../../test-utils/binary"); function createBaseTimestamp() { return { seconds: BigInt(0), nanos: 0 }; } var Timestamp = { encode: function encode(message) { var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create(); if (message.seconds !== BigInt(0)) { writer.uint32(8).int64(message.seconds); } if (message.nanos !== 0) { writer.uint32(16).int32(message.nanos); } return writer; }, decode: function decode(input, length) { var reader = input instanceof _binary.BinaryReader ? input : new _binary.BinaryReader(input); var end = length === undefined ? reader.len : reader.pos + length; var message = createBaseTimestamp(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: message.seconds = reader.int64(); break; case 2: message.nanos = reader.int32(); break; default: reader.skipType(tag & 7); break; } } return message; }, fromJSON: function fromJSON(object) { return { seconds: (0, _helpers.isSet)(object.seconds) ? BigInt(object.seconds.toString()) : BigInt(0), nanos: (0, _helpers.isSet)(object.nanos) ? Number(object.nanos) : 0 }; }, toJSON: function toJSON(message) { var obj = {}; message.seconds !== undefined && (obj.seconds = (message.seconds || BigInt(0)).toString()); message.nanos !== undefined && (obj.nanos = Math.round(message.nanos)); return obj; }, fromPartial: function fromPartial(object) { var _object$nanos; var message = createBaseTimestamp(); message.seconds = object.seconds !== undefined && object.seconds !== null ? BigInt(object.seconds.toString()) : BigInt(0); message.nanos = (_object$nanos = object.nanos) !== null && _object$nanos !== void 0 ? _object$nanos : 0; return message; } }; exports.Timestamp = Timestamp; function createBaseAny() { return { typeUrl: "", value: new Uint8Array() }; } var Any = { encode: function encode(message) { var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create(); if (message.typeUrl !== "") { writer.uint32(10).string(message.typeUrl); } if (message.value.length !== 0) { writer.uint32(18).bytes(message.value); } return writer; }, decode: function decode(input, length) { var reader = input instanceof _binary.BinaryReader ? input : new _binary.BinaryReader(input); var end = length === undefined ? reader.len : reader.pos + length; var message = createBaseAny(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: message.typeUrl = reader.string(); break; case 2: message.value = reader.bytes(); break; default: reader.skipType(tag & 7); break; } } return message; }, fromJSON: function fromJSON(object) { return { typeUrl: (0, _helpers.isSet)(object.typeUrl) ? String(object.typeUrl) : "", value: (0, _helpers.isSet)(object.value) ? (0, _helpers.bytesFromBase64)(object.value) : new Uint8Array() }; }, toJSON: function toJSON(message) { var obj = {}; message.typeUrl !== undefined && (obj.typeUrl = message.typeUrl); message.value !== undefined && (obj.value = (0, _helpers.base64FromBytes)(message.value !== undefined ? message.value : new Uint8Array())); return obj; }, fromPartial: function fromPartial(object) { var _object$typeUrl, _object$value; var message = createBaseAny(); message.typeUrl = (_object$typeUrl = object.typeUrl) !== null && _object$typeUrl !== void 0 ? _object$typeUrl : ""; message.value = (_object$value = object.value) !== null && _object$value !== void 0 ? _object$value : new Uint8Array(); return message; }, fromSDK: function fromSDK(object) { return { typeUrl: object === null || object === void 0 ? void 0 : object.type_url, value: object === null || object === void 0 ? void 0 : object.value }; }, fromSDKJSON: function fromSDKJSON(object) { return { type_url: (0, _helpers.isSet)(object.type_url) ? String(object.type_url) : "", value: (0, _helpers.isSet)(object.value) ? (0, _helpers.bytesFromBase64)(object.value) : new Uint8Array() }; }, toSDK: function toSDK(message) { var obj = {}; obj.type_url = message.typeUrl; obj.value = message.value; return obj; }, fromAmino: function fromAmino(object) { return { typeUrl: object.type, value: object.value }; }, toAmino: function toAmino(message) { var obj = {}; obj.type = message.typeUrl; obj.value = message.value; return obj; } }; exports.Any = Any; function isGenericAuthorization(message) { return message.typeUrl === "/cosmos.authz.v1beta1.GenericAuthorization"; } function asCustomizedAuthorization(message) { if (message.value instanceof Uint8Array) { message.value = CustomizedAuthorization.decode(message.value); } return message.typeUrl === "/cosmos.authz.v1beta1.CustomizedAuthorization"; } function createBaseGenericAuthorization() { return { msg: "" }; } var GenericAuthorization = { encode: function encode(message) { var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create(); if (message.msg !== "") { writer.uint32(10).string(message.msg); } return writer; }, decode: function decode(input, length) { var reader = input instanceof _binary.BinaryReader ? input : new _binary.BinaryReader(input); var end = length === undefined ? reader.len : reader.pos + length; var message = createBaseGenericAuthorization(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: message.msg = reader.string(); break; default: reader.skipType(tag & 7); break; } } return message; }, fromJSON: function fromJSON(object) { return { msg: (0, _helpers.isSet)(object.msg) ? String(object.msg) : "" }; }, toJSON: function toJSON(message) { var obj = {}; message.msg !== undefined && (obj.msg = message.msg); return obj; }, fromPartial: function fromPartial(object) { var _object$msg; var message = createBaseGenericAuthorization(); message.msg = (_object$msg = object.msg) !== null && _object$msg !== void 0 ? _object$msg : ""; return message; }, fromSDK: function fromSDK(object) { return { msg: object === null || object === void 0 ? void 0 : object.msg }; }, fromSDKJSON: function fromSDKJSON(object) { return { msg: (0, _helpers.isSet)(object.msg) ? String(object.msg) : "" }; }, toSDK: function toSDK(message) { var obj = {}; obj.msg = message.msg; return obj; }, fromAmino: function fromAmino(object) { return { msg: object.msg }; }, toAmino: function toAmino(message) { var obj = {}; obj.msg = message.msg; return obj; } }; exports.GenericAuthorization = GenericAuthorization; function createBaseCustomizedAuthorization() { return { customizedMsg: "" }; } var CustomizedAuthorization = { encode: function encode(message) { var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create(); if (message.customizedMsg !== "") { writer.uint32(10).string(message.customizedMsg); } return writer; }, decode: function decode(input, length) { var reader = input instanceof _binary.BinaryReader ? input : new _binary.BinaryReader(input); var end = length === undefined ? reader.len : reader.pos + length; var message = createBaseCustomizedAuthorization(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: message.customizedMsg = reader.string(); break; default: reader.skipType(tag & 7); break; } } return message; }, fromJSON: function fromJSON(object) { return { customizedMsg: (0, _helpers.isSet)(object.customizedMsg) ? String(object.customizedMsg) : "" }; }, toJSON: function toJSON(message) { var obj = {}; message.customizedMsg !== undefined && (obj.customizedMsg = message.customizedMsg); return obj; }, fromPartial: function fromPartial(object) { var _object$customizedMsg; var message = createBaseCustomizedAuthorization(); message.customizedMsg = (_object$customizedMsg = object.customizedMsg) !== null && _object$customizedMsg !== void 0 ? _object$customizedMsg : ""; return message; }, fromSDK: function fromSDK(object) { return { customizedMsg: object === null || object === void 0 ? void 0 : object.customized_msg }; }, fromSDKJSON: function fromSDKJSON(object) { return { customized_msg: (0, _helpers.isSet)(object.customizedMsg) ? String(object.customizedMsg) : "" }; }, toSDK: function toSDK(message) { var obj = {}; obj.customized_msg = message.customizedMsg; return obj; }, fromAmino: function fromAmino(object) { return { customizedMsg: object.customizedMsg }; }, toAmino: function toAmino(message) { var obj = {}; obj.customizedMsg = message.customizedMsg; return obj; } }; exports.CustomizedAuthorization = CustomizedAuthorization; function createBaseGrant() { return { authorization: Any.fromPartial({}), expiration: undefined }; } var Grant = { encode: function encode(message) { var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create(); if (message.authorization !== undefined) { Authorization_InterfaceEncoder(message.authorization, writer.uint32(10).fork()).ldelim(); } if (message.expiration !== undefined) { Timestamp.encode((0, _helpers.toTimestamp)(message.expiration), writer.uint32(18).fork()).ldelim(); } return writer; }, decode: function decode(input, length) { var reader = input instanceof _binary.BinaryReader ? input : new _binary.BinaryReader(input); var end = length === undefined ? reader.len : reader.pos + length; var message = createBaseGrant(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: message.authorization = Authorization_InterfaceDecoder(reader); break; case 2: message.expiration = (0, _helpers.fromTimestamp)(Timestamp.decode(reader, reader.uint32())); break; default: reader.skipType(tag & 7); break; } } return message; }, fromJSON: function fromJSON(object) { return { authorization: (0, _helpers.isSet)(object.authorization) ? object.authorization : undefined, expiration: (0, _helpers.isSet)(object.expiration) ? new Date(object.expiration) : undefined }; }, toJSON: function toJSON(message) { var obj = {}; message.authorization !== undefined && (obj.authorization = message.authorization); message.expiration !== undefined && (obj.expiration = message.expiration.toISOString()); return obj; }, fromPartial: function fromPartial(object, customizedFromPartialMapping) { var _object$expiration; var message = createBaseGrant(); message.authorization = object.authorization !== undefined && object.authorization !== null ? Authorization_FromPartial(object.authorization, customizedFromPartialMapping) : undefined; message.expiration = (_object$expiration = object.expiration) !== null && _object$expiration !== void 0 ? _object$expiration : undefined; return message; }, fromSDK: function fromSDK(object, customizedFromSDKMapping) { var _object$expiration2; return { authorization: object.authorization ? Authorization_FromSDK(object.authorization, customizedFromSDKMapping) : undefined, expiration: (_object$expiration2 = object.expiration) !== null && _object$expiration2 !== void 0 ? _object$expiration2 : undefined }; }, fromSDKJSON: function fromSDKJSON(object) { return { authorization: (0, _helpers.isSet)(object.authorization) ? Any.fromSDKJSON(object.authorization) : undefined, expiration: (0, _helpers.isSet)(object.expiration) ? new Date(object.expiration) : undefined }; }, toSDK: function toSDK(message, customizedToSDKMapping) { var _message$expiration; var obj = {}; message.authorization !== undefined && (obj.authorization = message.authorization ? Authorization_ToSDK(message.authorization, customizedToSDKMapping) : undefined); message.expiration !== undefined && (obj.expiration = (_message$expiration = message.expiration) !== null && _message$expiration !== void 0 ? _message$expiration : undefined); return obj; }, fromAmino: function fromAmino(object) { return { authorization: object !== null && object !== void 0 && object.authorization ? Authorization_FromAmino(object.authorization) : undefined, expiration: object === null || object === void 0 ? void 0 : object.expiration }; }, toAmino: function toAmino(message) { var obj = {}; obj.authorization = message.authorization ? Authorization_ToAmino(message.authorization) : undefined; obj.expiration = message.expiration; return obj; } }; exports.Grant = Grant; var Authorization_InterfaceEncoder = function Authorization_InterfaceEncoder(message, writer) { if ("encode" in message) { return Any.encode({ typeUrl: message.typeUrl, value: message.encode().finish() }, writer); } else { if (message.value instanceof Uint8Array) { return Any.encode(message, writer); } else { switch (message.typeUrl) { case "/cosmos.authz.v1beta1.GenericAuthorization": return Any.encode({ typeUrl: message.typeUrl, value: GenericAuthorization.encode(message.value).finish() }, writer); default: throw new Error("A valid typeUrl has to be provided if encode method is undefined."); } } } }; exports.Authorization_InterfaceEncoder = Authorization_InterfaceEncoder; var Authorization_InterfaceDecoder = function Authorization_InterfaceDecoder(input) { var reader = input instanceof _binary.BinaryReader ? input : new _binary.BinaryReader(input); var data = Any.decode(reader, reader.uint32()); switch (data.typeUrl) { case "/cosmos.authz.v1beta1.GenericAuthorization": return { typeUrl: data.typeUrl, value: GenericAuthorization.decode(data.value) }; default: return data; } }; exports.Authorization_InterfaceDecoder = Authorization_InterfaceDecoder; var Authorization_FromPartial = function Authorization_FromPartial(object, customizedFromPartialMapping) { var _object$value2; if (object.typeUrl && object.value && object.value instanceof Uint8Array) { return Any.fromPartial(object); } else { switch (object.typeUrl) { case "/cosmos.authz.v1beta1.GenericAuthorization": return { typeUrl: object.typeUrl, value: GenericAuthorization.fromPartial((_object$value2 = object.value) !== null && _object$value2 !== void 0 ? _object$value2 : {}) }; default: if (customizedFromPartialMapping && Object.keys(customizedFromPartialMapping).some(function (item) { return item === object.typeUrl; })) { var _object$value3; var fromPartial = customizedFromPartialMapping[object.typeUrl]; return { typeUrl: object.typeUrl, value: fromPartial((_object$value3 = object.value) !== null && _object$value3 !== void 0 ? _object$value3 : {}) }; } throw new Error("Input object has to be a valid Any type mapped with fromPartial function or decoded Any type."); } } }; exports.Authorization_FromPartial = Authorization_FromPartial; var Authorization_FromSDK = function Authorization_FromSDK(object, customizedFromSDKMapping) { if (object.type_url && object.value && object.value instanceof Uint8Array) { return Any.fromSDK(object); } else { switch (object.type_url) { case "/cosmos.authz.v1beta1.GenericAuthorization": return { typeUrl: object.type_url, value: GenericAuthorization.fromSDK(object.value) }; default: if (customizedFromSDKMapping && Object.keys(customizedFromSDKMapping).some(function (item) { return item === object.type_url; })) { var fromSDK = customizedFromSDKMapping[object.type_url]; return { typeUrl: object.type_url, value: fromSDK(object.value) }; } throw new Error("Input object has to be a valid Any type mapped with fromSDK function or decoded Any type."); } } }; exports.Authorization_FromSDK = Authorization_FromSDK; var Authorization_ToSDK = function Authorization_ToSDK(object, customizedToSDKMapping) { if (object.typeUrl && object.value && object.value instanceof Uint8Array) { return Any.toSDK(object); } else { switch (object.typeUrl) { case "/cosmos.authz.v1beta1.GenericAuthorization": return { type_url: object.typeUrl, value: GenericAuthorization.toSDK(object.value) }; default: if (customizedToSDKMapping && Object.keys(customizedToSDKMapping).some(function (item) { return item === object.typeUrl; })) { var fromSDK = customizedToSDKMapping[object.typeUrl]; return { type_url: object.typeUrl, value: fromSDK(object.value) }; } throw new Error("Input object has to be a valid Any type mapped with toSDK function or decoded Any type."); } } }; exports.Authorization_ToSDK = Authorization_ToSDK; var Authorization_FromAmino = function Authorization_FromAmino(content) { switch (content.type) { case "cosmos-sdk/GenericAuthorization": return Any.fromPartial({ typeUrl: "/cosmos.authz.v1beta1.GenericAuthorization", value: GenericAuthorization.encode(GenericAuthorization.fromPartial(GenericAuthorization.fromAmino(content.value))).finish() }); default: return Any.fromAmino(content); } }; exports.Authorization_FromAmino = Authorization_FromAmino; var Authorization_ToAmino = function Authorization_ToAmino(content) { switch (content.typeUrl) { case "/cosmos.authz.v1beta1.GenericAuthorization": return { type: "cosmos-sdk/GenericAuthorization", value: GenericAuthorization.toAmino(GenericAuthorization.decode(content.value)) }; default: return Any.toAmino(content); } }; exports.Authorization_ToAmino = Authorization_ToAmino; describe("implements interface works", function () { it("encodes and decodes", function () { var data = Grant.encode({ authorization: { typeUrl: "/cosmos.authz.v1beta1.GenericAuthorization", value: { msg: "pass" } }, expiration: new Date() }).finish(); var message = Grant.decode(data); expect(message.authorization.value.msg).toBe("pass"); if (message.authorization) { if (isGenericAuthorization(message.authorization)) { expect(message.authorization.value.msg).toBe("pass"); } else if (asCustomizedAuthorization(message.authorization)) { throw new Error("should be GenericAuthorization"); } } }); it("encodes and decodes customized type", function () { var data = Grant.encode({ authorization: { typeUrl: "/cosmos.authz.v1beta1.CustomizedAuthorization", encode: function encode(writer) { return CustomizedAuthorization.encode({ customizedMsg: "custom pass" }, writer); } }, expiration: new Date() }).finish(); var message = Grant.decode(data); if (message.authorization) { if (isGenericAuthorization(message.authorization)) { throw new Error("should be CustomizedAuthorization"); } else if (asCustomizedAuthorization(message.authorization)) { expect(message.authorization.value.customizedMsg).toBe("custom pass"); } } }); it("encodes and decodes Any", function () { var data = Grant.encode({ authorization: { typeUrl: "/cosmos.TestAny", value: new Uint8Array([100, 101]) }, expiration: new Date() }).finish(); var message = Grant.decode(data); expect(message.authorization.value).toStrictEqual(new Uint8Array([100, 101])); }); it("encodes and decodes wrong types with error", function () { expect(function () { Grant.encode({ authorization: { typeUrl: "/cosmos.TestAny", value: { num: 1 } }, expiration: new Date() }); }).toThrowError("A valid typeUrl has to be provided if encode method is undefined."); }); it("toJson for extended interface", function () { var data = Grant.encode({ authorization: { typeUrl: "/cosmos.authz.v1beta1.GenericAuthorization", value: { msg: "pass" } }, expiration: new Date("2020-01-01") }).finish(); var message = Grant.decode(data); var json = Grant.toJSON(message); expect(json).toMatchSnapshot(); }); it("toJson for customized interface", function () { var data = Grant.encode({ authorization: { typeUrl: "/cosmos.authz.v1beta1.CustomizedAuthorization", encode: function encode(writer) { return CustomizedAuthorization.encode({ customizedMsg: "custom pass" }, writer); } }, expiration: new Date("2020-01-01") }).finish(); var message = Grant.decode(data); var json = Grant.toJSON(message); expect(json).toMatchSnapshot(); //decode authorization by asCustomizedAuthorization if (message.authorization && asCustomizedAuthorization(message.authorization)) { var _json = Grant.toJSON(message); expect(_json).toMatchSnapshot(); } }); it("toJson for Any", function () { var data = Grant.encode({ authorization: { typeUrl: "/cosmos.TestAny", value: new Uint8Array([100, 101]) }, expiration: new Date("2020-01-01") }).finish(); var message = Grant.decode(data); var json = Grant.toJSON(message); expect(json).toMatchSnapshot(); }); it("fromJSON for extended interface", function () { var message = Grant.fromJSON({ authorization: { typeUrl: "/cosmos.authz.v1beta1.GenericAuthorization", value: { msg: "pass" } }, expiration: new Date("2020-01-01") }); var data = Grant.encode(message).finish(); var decodedMessage = Grant.decode(data); if (decodedMessage.authorization) { if (isGenericAuthorization(decodedMessage.authorization)) { expect(decodedMessage.authorization.value.msg).toBe("pass"); } else if (asCustomizedAuthorization(decodedMessage.authorization)) { throw new Error("should be GenericAuthorization"); } } }); it("fromJSON for customized interface", function () { var message = Grant.fromJSON({ authorization: { typeUrl: "/cosmos.authz.v1beta1.CustomizedAuthorization", encode: function encode(writer) { return CustomizedAuthorization.encode({ customizedMsg: "custom pass" }, writer); } }, expiration: new Date("2020-01-01") }); var data = Grant.encode(message).finish(); var decodedMessage = Grant.decode(data); if (decodedMessage.authorization) { if (isGenericAuthorization(decodedMessage.authorization)) { throw new Error("should be CustomizedAuthorization"); } else if (asCustomizedAuthorization(decodedMessage.authorization)) { expect(decodedMessage.authorization.value.customizedMsg).toBe("custom pass"); } } }); it("fromJSON for Any", function () { var message = Grant.fromJSON({ authorization: { typeUrl: "/cosmos.TestAny", value: new Uint8Array([100, 101]) }, expiration: new Date("2020-01-01") }); var data = Grant.encode(message).finish(); var decodedMessage = Grant.decode(data); expect(decodedMessage.authorization.value).toStrictEqual(new Uint8Array([100, 101])); }); it("fromPartial for Any", function () { var message = Grant.fromPartial({ authorization: { typeUrl: "/cosmos.TestAny", value: new Uint8Array([100, 101]) } }); var data = Grant.encode(message).finish(); var decodedMessage = Grant.decode(data); expect(decodedMessage.authorization.value).toStrictEqual(new Uint8Array([100, 101])); }); it("fromPartial for encoded extended interface", function () { var message = Grant.fromPartial({ authorization: { typeUrl: "/cosmos.authz.v1beta1.GenericAuthorization", value: GenericAuthorization.encode({ msg: "pass" }).finish() } }); var data = Grant.encode(message).finish(); var decodedMessage = Grant.decode(data); if (decodedMessage.authorization) { if (isGenericAuthorization(decodedMessage.authorization)) { expect(decodedMessage.authorization.value.msg).toBe("pass"); } else if (asCustomizedAuthorization(decodedMessage.authorization)) { throw new Error("should be GenericAuthorization"); } } }); it("fromPartial for customized interface", function () { var message = Grant.fromPartial({ authorization: { typeUrl: "/cosmos.authz.v1beta1.CustomizedAuthorization", value: {} } }, { "/cosmos.authz.v1beta1.CustomizedAuthorization": CustomizedAuthorization.fromPartial }); if (message.authorization) { if (isGenericAuthorization(message.authorization)) { throw new Error("should be CustomizedAuthorization"); } else if (asCustomizedAuthorization(message.authorization)) { expect(message.authorization.value.customizedMsg).toBe(""); } } }); it("fromPartial for no mapped customized interface with error", function () { expect(function () { return Grant.fromPartial({ authorization: { typeUrl: "/TestAny", value: {} } }, { "/cosmos.authz.v1beta1.CustomizedAuthorization": CustomizedAuthorization.fromPartial }); }).toThrowError("Input object has to be a valid Any type mapped with fromPartial function or decoded Any type."); }); it("fromSDK for Any", function () { var message = Grant.fromSDK({ authorization: { type_url: "/cosmos.TestAny", value: new Uint8Array([100, 101]) } }); var data = Grant.encode(message).finish(); var decodedMessage = Grant.decode(data); expect(decodedMessage.authorization.value).toStrictEqual(new Uint8Array([100, 101])); }); it("fromSDK for encoded extended interface", function () { var message = Grant.fromSDK({ authorization: { type_url: "/cosmos.authz.v1beta1.GenericAuthorization", value: GenericAuthorization.encode({ msg: "pass" }).finish() } }); var data = Grant.encode(message).finish(); var decodedMessage = Grant.decode(data); if (decodedMessage.authorization) { if (isGenericAuthorization(decodedMessage.authorization)) { expect(decodedMessage.authorization.value.msg).toBe("pass"); } else if (asCustomizedAuthorization(decodedMessage.authorization)) { throw new Error("should be GenericAuthorization"); } } }); it("fromSDK for customized interface", function () { var message = Grant.fromSDK({ authorization: { type_url: "/cosmos.authz.v1beta1.CustomizedAuthorization", value: { customized_msg: "custom pass" } } }, { "/cosmos.authz.v1beta1.CustomizedAuthorization": CustomizedAuthorization.fromSDK }); if (message.authorization) { if (isGenericAuthorization(message.authorization)) { throw new Error("should be CustomizedAuthorization"); } else if (asCustomizedAuthorization(message.authorization)) { expect(message.authorization.value.customizedMsg).toBe("custom pass"); } } }); it("fromSDK for no mapped customized interface with error", function () { expect(function () { return Grant.fromSDK({ authorization: { type_url: "/TestAny", value: {} } }, { "/cosmos.authz.v1beta1.CustomizedAuthorization": CustomizedAuthorization.fromSDK }); }).toThrowError("Input object has to be a valid Any type mapped with fromSDK function or decoded Any type."); }); it("toSDK for Any", function () { var message = Grant.toSDK({ authorization: { typeUrl: "/cosmos.TestAny", value: new Uint8Array([100, 101]) } }); expect(message.authorization.value).toStrictEqual(new Uint8Array([100, 101])); }); it("toSDK for encoded extended interface", function () { var _message$authorizatio; var message = Grant.toSDK({ authorization: { typeUrl: "/cosmos.authz.v1beta1.GenericAuthorization", value: { msg: "pass" } } }); expect(((_message$authorizatio = message.authorization) === null || _message$authorizatio === void 0 ? void 0 : _message$authorizatio.value).msg).toBe("pass"); }); it("toSDK for customized interface", function () { var _message$authorizatio2; var message = Grant.toSDK({ authorization: { typeUrl: "/cosmos.authz.v1beta1.CustomizedAuthorization", value: { customizedMsg: "custom pass" } } }, { "/cosmos.authz.v1beta1.CustomizedAuthorization": CustomizedAuthorization.toSDK }); expect(((_message$authorizatio2 = message.authorization) === null || _message$authorizatio2 === void 0 ? void 0 : _message$authorizatio2.value).customized_msg).toBe("custom pass"); }); it("toSDK for no mapped customized interface with error", function () { expect(function () { return Grant.toSDK({ authorization: { typeUrl: "/TestAny", value: {} } }, { "/cosmos.authz.v1beta1.CustomizedAuthorization": CustomizedAuthorization.toSDK }); }).toThrowError("Input object has to be a valid Any type mapped with toSDK function or decoded Any type."); }); });