Files
2026-09-01 13:04:49 +02:00

33 lines
936 B
TypeScript

import { describe, expect, it } from "vitest";
import {
decodeBase32,
decodeBase58,
decodeInput,
encodeBase32,
encodeBase58,
formatHexRows,
} from "../../src/core/encoding";
describe("binary encodings", () => {
it("round-trips RFC 4648 Base32", () => {
const bytes = new TextEncoder().encode("foobar");
expect(encodeBase32(bytes)).toBe("MZXW6YTBOI======");
expect(new TextDecoder().decode(decodeBase32("MZXW6YTBOI======"))).toBe(
"foobar",
);
});
it("round-trips Base58 including leading zeros", () => {
const bytes = Uint8Array.of(0, 0, 1, 2, 255);
expect(decodeBase58(encodeBase58(bytes))).toEqual(bytes);
});
it("rejects malformed hex", () => {
expect(() => decodeInput("abc", "hex")).toThrow(/byte pairs/u);
});
it("retains absolute offsets for paged byte inspection", () => {
expect(formatHexRows(Uint8Array.of(1, 2, 3), 4_096)[0]?.offset).toBe(4_096);
});
});