Skip to content

Commit

Permalink
fix: update tests to use new compile return type
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Oct 30, 2023
1 parent 8cb4aba commit 81b3551
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Logger } from 'tslog';
import * as TOML from 'smol-toml';

import { initializeResolver } from '@noir-lang/source-resolver';
import newCompiler, { compile, init_log_level as compilerLogLevel } from '@noir-lang/noir_wasm';
import newCompiler, { CompiledProgram, compile, init_log_level as compilerLogLevel } from '@noir-lang/noir_wasm';
import { Noir } from '@noir-lang/noir_js';
import { InputMap } from '@noir-lang/noirc_abi';
import { BarretenbergBackend } from '@noir-lang/backend_barretenberg';
Expand Down Expand Up @@ -32,15 +32,20 @@ const suite = Mocha.Suite.create(mocha.suite, 'Noir end to end test');

suite.timeout(60 * 20e3); //20mins

async function getCircuit(noirSource: string) {
function getCircuit(noirSource: string): CompiledProgram {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
initializeResolver((id: string) => {
logger.debug('source-resolver: resolving:', id);
return noirSource;
});

// We're ignoring this in the resolver but pass in something sensible.
return compile('/main.nr');
const result = compile('/main.nr');
if (!('program' in result)) {
throw new Error('Compilation failed');
}

return result.program;
}

test_cases.forEach((testInfo) => {
Expand All @@ -51,11 +56,11 @@ test_cases.forEach((testInfo) => {

const noir_source = await getFile(`${base_relative_path}/${test_case}/src/main.nr`);

let noir_program;
let noir_program: CompiledProgram;
try {
noir_program = await getCircuit(noir_source);
noir_program = getCircuit(noir_source);

expect(await noir_program, 'Compile output ').to.be.an('object');
expect(noir_program, 'Compile output ').to.be.an('object');
} catch (e) {
expect(e, 'Compilation Step').to.not.be.an('error');
throw e;
Expand Down
13 changes: 9 additions & 4 deletions compiler/integration-tests/test/browser/recursion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect } from '@esm-bundle/chai';
import { TEST_LOG_LEVEL } from '../environment.js';
import { Logger } from 'tslog';
import { initializeResolver } from '@noir-lang/source-resolver';
import newCompiler, { compile, init_log_level as compilerLogLevel } from '@noir-lang/noir_wasm';
import newCompiler, { CompiledProgram, compile, init_log_level as compilerLogLevel } from '@noir-lang/noir_wasm';
import { acvm, abi, Noir } from '@noir-lang/noir_js';

import * as TOML from 'smol-toml';
Expand All @@ -26,15 +26,20 @@ const base_relative_path = '../../../../..';
const circuit_main = 'compiler/integration-tests/circuits/main';
const circuit_recursion = 'compiler/integration-tests/circuits/recursion';

async function getCircuit(noirSource: string) {
function getCircuit(noirSource: string): CompiledProgram {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
initializeResolver((id: string) => {
logger.debug('source-resolver: resolving:', id);
return noirSource;
});

// We're ignoring this in the resolver but pass in something sensible.
return compile('./main.nr');
const result = compile('/main.nr');
if (!('program' in result)) {
throw new Error('Compilation failed');
}

return result.program;
}

describe('It compiles noir program code, receiving circuit bytes and abi object.', () => {
Expand All @@ -50,7 +55,7 @@ describe('It compiles noir program code, receiving circuit bytes and abi object.
});

it('Should generate valid inner proof for correct input, then verify proof within a proof', async () => {
const main_program = await getCircuit(circuit_main_source);
const main_program = getCircuit(circuit_main_source);
const main_inputs: InputMap = TOML.parse(circuit_main_toml) as InputMap;

const main_backend = new BarretenbergBackend(main_program);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ test_cases.forEach((testInfo) => {

const noir_source_path = resolve(`${base_relative_path}/${test_case}/src/main.nr`);

const noir_program = compile(noir_source_path);
const compileResult = compile(noir_source_path);
if (!('program' in compileResult)) {
throw new Error('Compilation failed');
}

const noir_program = compileResult.program;

const backend = new BarretenbergBackend(noir_program);
const program = new Noir(noir_program, backend);
Expand Down

0 comments on commit 81b3551

Please sign in to comment.