-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathuh.test.ts
More file actions
50 lines (42 loc) · 1.65 KB
/
uh.test.ts
File metadata and controls
50 lines (42 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { expect, beforeAll, describe, test } from 'bun:test';
import { Noir } from '@noir-lang/noir_js';
import { ProofData } from '@noir-lang/types';
import { UltraHonkBackend } from '@aztec/bb.js';
import fs from 'fs';
import { resolve } from 'path';
describe('UltraHonk', () => {
let correctProof: ProofData;
let noir: Noir;
let backend: UltraHonkBackend;
beforeAll(async () => {
const contractsDir = resolve('packages', 'contracts');
if (fs.existsSync(contractsDir)) fs.rmdirSync(contractsDir, { recursive: true });
const hre = require('hardhat');
hre.run('node');
hre.config.noirenberg = { provingSystem: 'UltraHonk' };
console.log(hre);
({ noir, backend } = await hre.noirenberg.compile());
await hre.noirenberg.getSolidityVerifier();
});
test('Should generate valid proof for correct input', async () => {
const input = { x: 1, y: 2 };
const { witness } = await noir.execute(input);
correctProof = await backend.generateProof(witness);
expect(correctProof.proof instanceof Uint8Array).toBe(true);
});
test('Should verify valid proof for correct input', async () => {
const verification = await backend.verifyProof(correctProof);
expect(verification).toBe(true);
});
test('Should fail to generate valid proof for incorrect input', async () => {
try {
const input = { x: 1, y: 1 };
const { witness } = await noir.execute(input);
const incorrectProof = await backend.generateProof(witness);
} catch (err) {
expect(err instanceof Error).toBe(true);
const error = err as Error;
expect(error.message).toContain('Cannot satisfy constraint');
}
});
});