Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
critesjosh committed Jul 30, 2024
1 parent 3aff4bd commit 580dc22
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions vite-hardhat/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,35 @@ shelljs.exec('npx hardhat compile');

describe('It compiles noir program code, receiving circuit bytes and abi object.', () => {
let noir: Noir;
let backend: BarretenbergBackend;
let correctProof: ProofData;

beforeEach(async () => {
const circuitFile = readFileSync(resolve('artifacts/circuit.json'), 'utf-8');
const circuit = JSON.parse(circuitFile);

const backend = new BarretenbergBackend(circuit);
noir = new Noir(circuit, backend);
backend = new BarretenbergBackend(circuit);
noir = new Noir(circuit);
});

it('Should generate valid proof for correct input', async () => {
const input = { x: 1, y: 2 };
// Generate proof
correctProof = await noir.generateProof(input);
const { witness } = await noir.execute(input);
correctProof = await backend.generateProof(witness);
expect(correctProof.proof instanceof Uint8Array).to.be.true;
});

it('Should verify valid proof for correct input', async () => {
const verification = await noir.verifyProof(correctProof);
const verification = await backend.verifyProof(correctProof);
expect(verification).to.be.true;
});

it('Should fail to generate valid proof for incorrect input', async () => {
try {
const input = { x: 1, y: 1 };
const incorrectProof = await noir.generateProof(input);
const { witness } = await noir.execute(input);
const incorrectProof = await backend.generateProof(witness);
} catch (err) {
// TODO(Ze): Not sure how detailed we want this it to be
expect(err instanceof Error).to.be.true;
Expand Down

0 comments on commit 580dc22

Please sign in to comment.