From 384851a5418ac0aaeed049f58f8e55a00c387bc5 Mon Sep 17 00:00:00 2001 From: Saleel Date: Thu, 27 Jun 2024 19:40:05 +0400 Subject: [PATCH] chore: update sha precompute error message --- packages/helpers/src/sha-utils.ts | 3 +- .../helpers/tests/input-generators.test.ts | 44 +++++++++---------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/packages/helpers/src/sha-utils.ts b/packages/helpers/src/sha-utils.ts index ebc8bbdb6..0db2d8b84 100644 --- a/packages/helpers/src/sha-utils.ts +++ b/packages/helpers/src/sha-utils.ts @@ -48,13 +48,12 @@ export function generatePartialSHA({ }) { let selectorIndex = 0; - // TODO: See if this (no preselector) could be handled at the circuit level if (selectorString) { const selector = new TextEncoder().encode(selectorString); selectorIndex = findIndexInUint8Array(body, selector); if (selectorIndex === -1) { - throw new Error('Provider SHA precompute selector not found in the body'); + throw new Error(`SHA precompute selector "${selectorString}" not found in the body`); } } diff --git a/packages/helpers/tests/input-generators.test.ts b/packages/helpers/tests/input-generators.test.ts index e7d85fad2..04ce0931e 100644 --- a/packages/helpers/tests/input-generators.test.ts +++ b/packages/helpers/tests/input-generators.test.ts @@ -1,14 +1,14 @@ -import fs from 'fs'; -import path from 'path'; -import { generateEmailVerifierInputs } from '../src/input-generators'; -import { bytesToString } from '../src/binary-format'; +import fs from "fs"; +import path from "path"; +import { generateEmailVerifierInputs } from "../src/input-generators"; +import { bytesToString } from "../src/binary-format"; jest.setTimeout(10000); -describe('Input generators', () => { - it('should generate input from raw email', async () => { +describe("Input generators", () => { + it("should generate input from raw email", async () => { const email = fs.readFileSync( - path.join(__dirname, 'test-data/email-good.eml'), + path.join(__dirname, "test-data/email-good.eml") ); const inputs = await generateEmailVerifierInputs(email); @@ -22,9 +22,9 @@ describe('Input generators', () => { expect(inputs.bodyHashIndex).toBeDefined(); }); - it('should generate input without body params when ignoreBodyHash is true', async () => { + it("should generate input without body params when ignoreBodyHash is true", async () => { const email = fs.readFileSync( - path.join(__dirname, 'test-data/email-good.eml'), + path.join(__dirname, "test-data/email-good.eml") ); const inputs = await generateEmailVerifierInputs(email, { @@ -40,37 +40,35 @@ describe('Input generators', () => { expect(inputs.bodyHashIndex).toBeFalsy(); }); - it('should generate input with SHA precompute selector', async () => { + it("should generate input with SHA precompute selector", async () => { const email = fs.readFileSync( - path.join(__dirname, 'test-data/email-good-large.eml'), + path.join(__dirname, "test-data/email-good-large.eml") ); const inputs = await generateEmailVerifierInputs(email, { - shaPrecomputeSelector: 'thousands', + shaPrecomputeSelector: "thousands", }); expect(inputs.emailBody).toBeDefined(); const strBody = bytesToString( - Uint8Array.from(inputs.emailBody!.map((b) => Number(b))), + Uint8Array.from(inputs.emailBody!.map((b) => Number(b))) ); - const expected = 'h hundreds of thousands of blocks.'; // will round till previous 64x th byte + const expected = "h hundreds of thousands of blocks."; // will round till previous 64x th byte expect(strBody.startsWith(expected)).toBeTruthy(); }); - it('should throw if SHA precompute selector is invalid', async () => { + it("should throw if SHA precompute selector is invalid", async () => { const email = fs.readFileSync( - path.join(__dirname, 'test-data/email-good.eml'), + path.join(__dirname, "test-data/email-good.eml") ); - expect(async () => { - await generateEmailVerifierInputs(email, { - shaPrecomputeSelector: 'Bla Bla', - }); - }).rejects.toThrow( - 'Provider SHA precompute selector not found in the body', - ); + await expect(() => + generateEmailVerifierInputs(email, { + shaPrecomputeSelector: "Bla Bla", + }) + ).rejects.toThrow('SHA precompute selector "Bla Bla" not found in the body'); }); });