|
6 | 6 | commitment, |
7 | 7 | decodeBidPreimage, |
8 | 8 | encodeBidPreimage, |
| 9 | + fromHex, |
9 | 10 | i128ToBeBytes, |
10 | 11 | toHex, |
11 | 12 | } from "./commitment.js"; |
@@ -51,3 +52,23 @@ test("rejects out-of-range and malformed inputs", () => { |
51 | 52 | assert.throws(() => encodeBidPreimage(1n, new Uint8Array(31))); |
52 | 53 | assert.throws(() => decodeBidPreimage(new Uint8Array(47))); |
53 | 54 | }); |
| 55 | + |
| 56 | +test("fromHex decodes lowercase, uppercase, and prefixed values", () => { |
| 57 | + const expected = [0xab, 0xcd, 0xef]; |
| 58 | + assert.deepEqual([...fromHex("abcdef")], expected); |
| 59 | + assert.deepEqual([...fromHex("ABCDEF")], expected); |
| 60 | + assert.deepEqual([...fromHex("0xAbCdEf")], expected); |
| 61 | + assert.deepEqual([...fromHex("0XABCDEF")], expected); |
| 62 | +}); |
| 63 | + |
| 64 | +test("fromHex accepts empty input as an empty byte array", () => { |
| 65 | + assert.deepEqual([...fromHex("")], []); |
| 66 | + assert.deepEqual([...fromHex("0x")], []); |
| 67 | +}); |
| 68 | + |
| 69 | +test("fromHex rejects odd-length and non-hex input", () => { |
| 70 | + assert.throws(() => fromHex("abc"), /odd hex length/); |
| 71 | + assert.throws(() => fromHex("zz"), /invalid hex characters/); |
| 72 | + assert.throws(() => fromHex("12 3"), /invalid hex characters/); |
| 73 | + assert.throws(() => fromHex("0x12gg"), /invalid hex characters/); |
| 74 | +}); |
0 commit comments