diff --git a/compiler/integration-tests/test/circuits/main/Nargo.toml b/compiler/integration-tests/circuits/main/Nargo.toml similarity index 100% rename from compiler/integration-tests/test/circuits/main/Nargo.toml rename to compiler/integration-tests/circuits/main/Nargo.toml diff --git a/compiler/integration-tests/test/circuits/main/Prover.toml b/compiler/integration-tests/circuits/main/Prover.toml similarity index 100% rename from compiler/integration-tests/test/circuits/main/Prover.toml rename to compiler/integration-tests/circuits/main/Prover.toml diff --git a/compiler/integration-tests/test/circuits/main/src/main.nr b/compiler/integration-tests/circuits/main/src/main.nr similarity index 100% rename from compiler/integration-tests/test/circuits/main/src/main.nr rename to compiler/integration-tests/circuits/main/src/main.nr diff --git a/compiler/integration-tests/test/circuits/recursion/Nargo.toml b/compiler/integration-tests/circuits/recursion/Nargo.toml similarity index 100% rename from compiler/integration-tests/test/circuits/recursion/Nargo.toml rename to compiler/integration-tests/circuits/recursion/Nargo.toml diff --git a/compiler/integration-tests/test/circuits/recursion/Prover.toml b/compiler/integration-tests/circuits/recursion/Prover.toml similarity index 100% rename from compiler/integration-tests/test/circuits/recursion/Prover.toml rename to compiler/integration-tests/circuits/recursion/Prover.toml diff --git a/compiler/integration-tests/test/circuits/recursion/src/main.nr b/compiler/integration-tests/circuits/recursion/src/main.nr similarity index 100% rename from compiler/integration-tests/test/circuits/recursion/src/main.nr rename to compiler/integration-tests/circuits/recursion/src/main.nr diff --git a/compiler/integration-tests/package.json b/compiler/integration-tests/package.json index cc48ebd5449..b2c0cae1c0a 100644 --- a/compiler/integration-tests/package.json +++ b/compiler/integration-tests/package.json @@ -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" + } } diff --git a/compiler/integration-tests/scripts/codegen-verifiers.sh b/compiler/integration-tests/scripts/codegen-verifiers.sh index 8fd3cb7eccc..ed35cfe3b05 100644 --- a/compiler/integration-tests/scripts/codegen-verifiers.sh +++ b/compiler/integration-tests/scripts/codegen-verifiers.sh @@ -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 diff --git a/compiler/integration-tests/test/integration/browser/compile_prove_verify.test.ts b/compiler/integration-tests/test/browser/compile_prove_verify.test.ts similarity index 79% rename from compiler/integration-tests/test/integration/browser/compile_prove_verify.test.ts rename to compiler/integration-tests/test/browser/compile_prove_verify.test.ts index fb183e46dbe..649b8facb27 100644 --- a/compiler/integration-tests/test/integration/browser/compile_prove_verify.test.ts +++ b/compiler/integration-tests/test/browser/compile_prove_verify.test.ts @@ -1,5 +1,5 @@ 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'; @@ -7,6 +7,8 @@ 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 }); @@ -15,17 +17,6 @@ await newCompiler(); compilerLogLevel('INFO'); -async function getFile(file_path: string): Promise { - 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', @@ -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, @@ -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 () => { diff --git a/compiler/integration-tests/test/integration/browser/recursion.test.ts b/compiler/integration-tests/test/browser/recursion.test.ts similarity index 78% rename from compiler/integration-tests/test/integration/browser/recursion.test.ts rename to compiler/integration-tests/test/browser/recursion.test.ts index 7f2140a8e8e..6d5e976d5dc 100644 --- a/compiler/integration-tests/test/integration/browser/recursion.test.ts +++ b/compiler/integration-tests/test/browser/recursion.test.ts @@ -1,6 +1,6 @@ /* 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'; @@ -8,6 +8,7 @@ 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 }); @@ -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 { - 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 @@ -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 () => { diff --git a/compiler/integration-tests/test/browser/utils.ts b/compiler/integration-tests/test/browser/utils.ts new file mode 100644 index 00000000000..35588407193 --- /dev/null +++ b/compiler/integration-tests/test/browser/utils.ts @@ -0,0 +1,8 @@ +export async function getFile(file_path: string): Promise { + 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(); +} diff --git a/compiler/integration-tests/test/environment.js b/compiler/integration-tests/test/environment.ts similarity index 100% rename from compiler/integration-tests/test/environment.js rename to compiler/integration-tests/test/environment.ts diff --git a/compiler/integration-tests/test/index.d.ts b/compiler/integration-tests/test/index.d.ts deleted file mode 100644 index 7ae9da01261..00000000000 --- a/compiler/integration-tests/test/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module '@aztec/bb.js'; diff --git a/compiler/integration-tests/test/shared/proof.ts b/compiler/integration-tests/test/shared/proof.ts new file mode 100644 index 00000000000..e792a8f509e --- /dev/null +++ b/compiler/integration-tests/test/shared/proof.ts @@ -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, + }; +} diff --git a/compiler/integration-tests/web-test-runner.config.mjs b/compiler/integration-tests/web-test-runner.config.mjs index d8388dac091..2daa14f93fa 100644 --- a/compiler/integration-tests/web-test-runner.config.mjs +++ b/compiler/integration-tests/web-test-runner.config.mjs @@ -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;'; } }, }); @@ -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'], }, }, }), @@ -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], };