UNPKG

postchain-client

Version:

Client library for accessing a Postchain node through REST.

84 lines 3.71 kB
import { isRawGtx } from "../../../src/blockchainClient/validation/rawGtx"; import { mockThirtyTwoBytesBuffer } from "../../common/mocks"; describe("rawGtx validation", () => { const createValidRawGtx = (operations = [], signers = [], signatures = []) => { const body = [mockThirtyTwoBytesBuffer, operations, signers]; return [body, signatures]; }; const createValidRawGtxOp = (opName, args = []) => { return [opName, args]; }; describe("isRawGtx", () => { it("validates a valid RawGtx", () => { const validGtx = createValidRawGtx([createValidRawGtxOp("test", [1, "string", null])], [mockThirtyTwoBytesBuffer], [mockThirtyTwoBytesBuffer]); expect(isRawGtx(validGtx)).toBe(true); }); it("rejects null input", () => { expect(isRawGtx(null)).toBe(false); }); it("rejects undefined input", () => { expect(isRawGtx(undefined)).toBe(false); }); it("rejects object input", () => { expect(isRawGtx({})).toBe(false); }); it("rejects number input", () => { expect(isRawGtx(123)).toBe(false); }); it("rejects string input", () => { expect(isRawGtx("string")).toBe(false); }); it("rejects empty array input", () => { expect(isRawGtx([])).toBe(false); }); it("rejects array with three elements", () => { expect(isRawGtx([1, 2, 3])).toBe(false); }); it("rejects invalid body structure with non-array operations", () => { const invalidBody = [mockThirtyTwoBytesBuffer, "not-an-array", [mockThirtyTwoBytesBuffer]]; expect(isRawGtx([invalidBody, []])).toBe(false); }); it("accepts empty operations array", () => { const validGtx = createValidRawGtx([], [], []); expect(isRawGtx(validGtx)).toBe(true); }); it("accepts empty signers array", () => { const validGtx = createValidRawGtx([], [], []); expect(isRawGtx(validGtx)).toBe(true); }); it("accepts empty signatures array", () => { const validGtx = createValidRawGtx([], [], []); expect(isRawGtx(validGtx)).toBe(true); }); it("accepts operation with object argument", () => { const validGtx = createValidRawGtx([createValidRawGtxOp("test", [{ key: "value" }])]); expect(isRawGtx(validGtx)).toBe(true); }); it("accepts operation with array argument", () => { const validGtx = createValidRawGtx([createValidRawGtxOp("test", [[1, 2, 3]])]); expect(isRawGtx(validGtx)).toBe(true); }); it("accepts operation with primitive arguments", () => { const validGtx = createValidRawGtx([createValidRawGtxOp("test", [null, true, BigInt(123)])]); expect(isRawGtx(validGtx)).toBe(true); }); it("accepts operation with buffer argument", () => { const validGtx = createValidRawGtx([createValidRawGtxOp("test", [Buffer.from("test")])]); expect(isRawGtx(validGtx)).toBe(true); }); it("accepts nested RawGtv values in operation arguments", () => { const validGtx = createValidRawGtx([ createValidRawGtxOp("test", [ { key: "value" }, [1, 2, 3], null, true, BigInt(123), Buffer.from("test"), ]), ]); expect(isRawGtx(validGtx)).toBe(true); }); }); }); //# sourceMappingURL=rawGtx.test.js.map