|
| 1 | +import { |
| 2 | + uint8ArrayToHex, |
| 3 | + hexToUint8Array, |
| 4 | + stringToUint8Array, |
| 5 | +} from "../../src/utils/codec"; |
| 6 | +import falso from "@ngneat/falso"; |
| 7 | +import { describe, test, expect } from "vitest"; |
| 8 | + |
| 9 | +describe("Codec", () => { |
| 10 | + test("uint8ArrayToHex", () => { |
| 11 | + const input = new Uint8Array([1, 2, 3, 4]); |
| 12 | + const expected = "01020304"; |
| 13 | + expect(uint8ArrayToHex(input)).toBe(expected); |
| 14 | + }); |
| 15 | + |
| 16 | + test("hexToUint8Array", () => { |
| 17 | + const input = "01020304"; |
| 18 | + const expected = new Uint8Array([1, 2, 3, 4]); |
| 19 | + expect(hexToUint8Array(input)).toEqual(expected); |
| 20 | + }); |
| 21 | + |
| 22 | + test("hexToUint8Array (Odd Length)", () => { |
| 23 | + const input = "010203045"; |
| 24 | + expect(() => hexToUint8Array(input)).toThrow( |
| 25 | + "Hex string must have an even length", |
| 26 | + ); |
| 27 | + }); |
| 28 | + |
| 29 | + test("stringToUint8Array", () => { |
| 30 | + const input = "hello"; |
| 31 | + const expected = new Uint8Array([104, 101, 108, 108, 111]); |
| 32 | + expect(stringToUint8Array(input)).toEqual(expected); |
| 33 | + }); |
| 34 | +}); |
0 commit comments