Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: restructure integration tests #2954

Merged
merged 6 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions compiler/integration-tests/package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{
"name": "integration-tests",
"version": "1.0.0",
"license": "(MIT OR Apache-2.0)",
"main": "index.js",
"private": true,
"scripts": {
"build": "echo Integration Test build step",
"test": "yarn test:browser",
"test:browser": "web-test-runner",
"test:integration:browser": "web-test-runner test/integration/browser/**/*.test.ts",
"test:integration:browser:watch": "web-test-runner test/integration/browser/**/*.test.ts --watch",
"lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0"
},
"dependencies": {
"@noir-lang/backend_barretenberg": "workspace:*",
"@noir-lang/noir_js": "workspace:*",
"@noir-lang/noir_wasm": "workspace:*",
"@noir-lang/source-resolver": "workspace:*",
"@web/dev-server-esbuild": "^0.3.6",
"@web/test-runner": "^0.15.3",
"@web/test-runner-webdriver": "^0.7.0",
"eslint": "^8.50.0",
"eslint-plugin-prettier": "^5.0.0",
"ethers": "^6.7.1",
"fflate": "^0.8.0",
"prettier": "3.0.3",
"smol-toml": "^1.1.2",
"tslog": "^4.9.2"
}
"name": "integration-tests",
"version": "1.0.0",
"license": "(MIT OR Apache-2.0)",
"main": "index.js",
"private": true,
"scripts": {
"build": "echo Integration Test build step",
"test": "yarn test:browser",
"test:browser": "web-test-runner",
"test:integration:browser": "web-test-runner test/browser/**/*.test.ts",
"test:integration:browser:watch": "web-test-runner test/browser/**/*.test.ts --watch",
"lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0"
},
"dependencies": {
"@noir-lang/backend_barretenberg": "workspace:*",
"@noir-lang/noir_js": "workspace:*",
"@noir-lang/noir_wasm": "workspace:*",
"@noir-lang/source-resolver": "workspace:*",
"@web/dev-server-esbuild": "^0.3.6",
"@web/test-runner": "^0.15.3",
"@web/test-runner-webdriver": "^0.7.0",
"eslint": "^8.50.0",
"eslint-plugin-prettier": "^5.0.0",
"ethers": "^6.7.1",
"fflate": "^0.8.0",
"prettier": "3.0.3",
"smol-toml": "^1.1.2",
"tslog": "^4.9.2"
}
}
2 changes: 1 addition & 1 deletion compiler/integration-tests/scripts/codegen-verifiers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mul_dir=$repo_root/tooling/nargo_cli/tests/execution_success/1_mul
nargo --program-dir $mul_dir codegen-verifier

# Run codegen-verifier for main
main_dir=$repo_root/compiler/integration-tests/test/circuits/main
main_dir=$repo_root/compiler/integration-tests/circuits/main
nargo --program-dir $main_dir codegen-verifier

# Copy compiled contracts from the root of compiler/integration-tests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { expect } from '@esm-bundle/chai';
import { TEST_LOG_LEVEL } from '../../environment.js';
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 { Noir } from '@noir-lang/noir_js';
import { BarretenbergBackend } from '@noir-lang/backend_barretenberg';
import { ethers } from 'ethers';
import * as TOML from 'smol-toml';
import { getFile } from './utils.js';
import { separatePublicInputsFromProof } from '../shared/proof.js';

const provider = new ethers.JsonRpcProvider('http://localhost:8545');
const logger = new Logger({ name: 'test', minLevel: TEST_LOG_LEVEL });
Expand All @@ -15,17 +17,6 @@ await newCompiler();

compilerLogLevel('INFO');

async function getFile(file_path: string): Promise<string> {
const file_url = new URL(file_path, import.meta.url);
const response = await fetch(file_url);

if (!response.ok) throw new Error('Network response was not OK');

return await response.text();
}

const FIELD_ELEMENT_BYTES = 32;

const test_cases = [
{
case: 'tooling/nargo_cli/tests/execution_success/1_mul',
Expand All @@ -34,7 +25,7 @@ const test_cases = [
numPublicInputs: 0,
},
{
case: 'compiler/integration-tests/test/circuits/main',
case: 'compiler/integration-tests/circuits/main',
compiled: 'compiler/integration-tests/foundry-project/out/main.sol/UltraVerifier.json',
deployInformation: 'compiler/integration-tests/foundry-project/main_output.json',
numPublicInputs: 1,
Expand All @@ -55,22 +46,6 @@ async function getCircuit(noirSource: string) {
return compile({});
}

function separatePublicInputsFromProof(
proof: Uint8Array,
numPublicInputs: number,
): { proof: Uint8Array; publicInputs: Uint8Array[] } {
const publicInputs = Array.from({ length: numPublicInputs }, (_, i) => {
const offset = i * FIELD_ELEMENT_BYTES;
return proof.slice(offset, offset + FIELD_ELEMENT_BYTES);
});
const slicedProof = proof.slice(numPublicInputs * FIELD_ELEMENT_BYTES);

return {
proof: slicedProof,
publicInputs,
};
}

test_cases.forEach((testInfo) => {
const test_name = testInfo.case.split('/').pop();
const mochaTest = new Mocha.Test(`${test_name} (Compile, Execute, Prove, Verify)`, async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { expect } from '@esm-bundle/chai';
import { TEST_LOG_LEVEL } from '../../environment.js';
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 { acvm, abi, generateWitness } from '@noir-lang/noir_js';

import * as TOML from 'smol-toml';
import { BarretenbergBackend } from '@noir-lang/backend_barretenberg';
import { getFile } from './utils.js';

const logger = new Logger({ name: 'test', minLevel: TEST_LOG_LEVEL });

Expand All @@ -21,16 +22,8 @@ await initACVM();
compilerLogLevel('INFO');

const base_relative_path = '../../../../..';
const circuit_main = 'compiler/integration-tests/test/circuits/main';
const circuit_recursion = 'compiler/integration-tests/test/circuits/recursion';

async function getFile(url: URL): Promise<string> {
const response = await fetch(url);

if (!response.ok) throw new Error('Network response was not OK');

return await response.text();
}
const circuit_main = 'compiler/integration-tests/circuits/main';
const circuit_recursion = 'compiler/integration-tests/circuits/recursion';

async function getCircuit(noirSource: string) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -48,18 +41,10 @@ describe('It compiles noir program code, receiving circuit bytes and abi object.
let circuit_recursion_source;

before(async () => {
const circuit_main_source_url = new URL(`${base_relative_path}/${circuit_main}/src/main.nr`, import.meta.url);
const circuit_main_toml_url = new URL(`${base_relative_path}/${circuit_main}/Prover.toml`, import.meta.url);

circuit_main_source = await getFile(circuit_main_source_url);
circuit_main_toml = await getFile(circuit_main_toml_url);

const circuit_recursion_source_url = new URL(
`${base_relative_path}/${circuit_recursion}/src/main.nr`,
import.meta.url,
);
circuit_main_source = await getFile(`${base_relative_path}/${circuit_main}/src/main.nr`);
circuit_main_toml = await getFile(`${base_relative_path}/${circuit_main}/Prover.toml`);

circuit_recursion_source = await getFile(circuit_recursion_source_url);
circuit_recursion_source = await getFile(`${base_relative_path}/${circuit_recursion}/src/main.nr`);
});

it('Should generate valid inner proof for correct input, then verify proof within a proof', async () => {
Expand Down
8 changes: 8 additions & 0 deletions compiler/integration-tests/test/browser/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export async function getFile(file_path: string): Promise<string> {
const file_url = new URL(file_path, import.meta.url);
const response = await fetch(file_url);

if (!response.ok) throw new Error('Network response was not OK');

return await response.text();
}
1 change: 0 additions & 1 deletion compiler/integration-tests/test/index.d.ts

This file was deleted.

17 changes: 17 additions & 0 deletions compiler/integration-tests/test/shared/proof.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const FIELD_ELEMENT_BYTES = 32;

export function separatePublicInputsFromProof(
proof: Uint8Array,
numPublicInputs: number,
): { proof: Uint8Array; publicInputs: Uint8Array[] } {
const publicInputs = Array.from({ length: numPublicInputs }, (_, i) => {
const offset = i * FIELD_ELEMENT_BYTES;
return proof.slice(offset, offset + FIELD_ELEMENT_BYTES);
});
const slicedProof = proof.slice(numPublicInputs * FIELD_ELEMENT_BYTES);

return {
proof: slicedProof,
publicInputs,
};
}
32 changes: 16 additions & 16 deletions compiler/integration-tests/web-test-runner.config.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { defaultReporter } from "@web/test-runner";
import { summaryReporter } from "@web/test-runner";
import { fileURLToPath } from "url";
import { esbuildPlugin } from "@web/dev-server-esbuild";
import { webdriverLauncher } from "@web/test-runner-webdriver";
import { defaultReporter } from '@web/test-runner';
import { summaryReporter } from '@web/test-runner';
import { fileURLToPath } from 'url';
import { esbuildPlugin } from '@web/dev-server-esbuild';
import { webdriverLauncher } from '@web/test-runner-webdriver';

let reporter = summaryReporter();
const debugPlugins = [];
// eslint-disable-next-line no-undef
if (process.env.CI !== "true" || process.env.RUNNER_DEBUG === "1") {
if (process.env.CI !== 'true' || process.env.RUNNER_DEBUG === '1') {
reporter = defaultReporter();
debugPlugins.push({
name: "environment",
name: 'environment',
serve(context) {
if (context.path === "/compiler/integration-tests/test/environment.js") {
return "export const TEST_LOG_LEVEL = 2;";
if (context.path === '/compiler/integration-tests/test/environment.js') {
return 'export const TEST_LOG_LEVEL = 2;';
}
},
});
Expand All @@ -22,11 +22,11 @@ if (process.env.CI !== "true" || process.env.RUNNER_DEBUG === "1") {
export default {
browsers: [
webdriverLauncher({
automationProtocol: "webdriver",
automationProtocol: 'webdriver',
capabilities: {
browserName: "firefox",
"moz:firefoxOptions": {
args: ["-headless"],
browserName: 'firefox',
'moz:firefoxOptions': {
args: ['-headless'],
},
},
}),
Expand All @@ -37,15 +37,15 @@ export default {
}),
...debugPlugins,
],
files: ["test/integration/browser/**/*.test.ts"],
files: ['test/browser/**/*.test.ts'],
nodeResolve: { browser: true },
testFramework: {
config: {
ui: "bdd",
ui: 'bdd',
},
},
// eslint-disable-next-line no-undef
rootDir: fileURLToPath(new URL("./../..", import.meta.url)),
rootDir: fileURLToPath(new URL('./../..', import.meta.url)),
testsFinishTimeout: 60 * 20e3, // 20 minutes
reporters: [reporter],
};
Loading