-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add
noir_wasm
testing workflow (#1921)
* Edit workflow * Output built directory * Fix noir_wasm copy * Fix workflow * Add mkdir to workflow * Remove logs * chore: Ensure that CLI and wasm compilers are sync in `noir_wasm_testing` (#2079) --------- Co-authored-by: jonybur <jobur93@gmail.com> * Update .github/workflows/wasm.yml * chore: run browser tests rather than nodejs tests * chore: fix test command in CI * chore: bring noir-wasm-testing repo contents into wasm crate --------- Co-authored-by: jonybur <jobur93@gmail.com> * chore: update compile command to handle not being at repo root * chore: remove unnecessary checkout * chore: update location to look for nargo binary * chore: add missing $ * chore: remove self-referential dependency * chore: switch to `noir-lang/noir-source-resolver` version which exists * chore: place downloaded wasm artifact in `crates/wasm` so it can resolve the resolver * Revisions * chore: fix CI workflow * chore: remove usage of `matrix.target` * chore: fix path to binary * chore: remove unwanted printing when compiling noir program * chore: update `Nargo.toml` to be compliant with new format * chore: remove unnecessary checkout * chore: add todo to workflow * Update .github/workflows/wasm.yml * Update crates/wasm/noir-script/src/main.nr * Update crates/wasm/test/browser/index.test.ts --------- Co-authored-by: TomAFrench <tom@tomfren.ch> Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
- Loading branch information
1 parent
44df932
commit 08683e1
Showing
14 changed files
with
4,000 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Yarn | ||
.pnp.* | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extension": [ | ||
"ts" | ||
], | ||
"spec": "test/node/**/*.test.ts", | ||
"require": "ts-node/register" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name="noir_wasm_testing" | ||
type="bin" | ||
authors = [""] | ||
compiler_version = "0.1" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main(x : u64, y : pub u64) { | ||
assert(x < y); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { expect } from "@esm-bundle/chai"; | ||
import initNoirWasm from "../../dist"; | ||
import { compileNoirSource, nargoArtifactPath, noirSourcePath } from "../shared"; | ||
|
||
beforeEach(async () => { | ||
await initNoirWasm(); | ||
}); | ||
|
||
async function getFileContent(path: string): Promise<string> { | ||
const mainnrSourceURL = new URL(path, import.meta.url); | ||
const response = await fetch(mainnrSourceURL); | ||
return await response.text(); | ||
} | ||
|
||
async function getSource(): Promise<string> { | ||
return getFileContent(noirSourcePath) | ||
} | ||
|
||
async function getPrecompiledSource(): Promise<string> { | ||
const compiledData = await getFileContent(nargoArtifactPath); | ||
return JSON.parse(compiledData).bytecode; | ||
} | ||
|
||
describe("noir wasm compilation", () => { | ||
it("matches nargos compilation", async () => { | ||
const source = await getSource(); | ||
|
||
const wasmCircuitBase64 = await compileNoirSource(source); | ||
|
||
const cliCircuitBase64 = await getPrecompiledSource(); | ||
|
||
|
||
expect(wasmCircuitBase64).to.equal(cliCircuitBase64); | ||
}).timeout(10e3); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module '@noir-lang/noir-source-resolver'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { expect } from "@esm-bundle/chai"; | ||
import { compileNoirSource, nargoArtifactPath, noirSourcePath } from "../shared"; | ||
import { readFileSync } from "node:fs"; | ||
|
||
async function getFileContent(path: string): Promise<string> { | ||
return readFileSync(path).toString() | ||
} | ||
|
||
async function getSource(): Promise<string> { | ||
return getFileContent(noirSourcePath) | ||
} | ||
|
||
async function getPrecompiledSource(): Promise<string> { | ||
const compiledData = await getFileContent(nargoArtifactPath); | ||
return JSON.parse(compiledData).bytecode; | ||
} | ||
|
||
describe("noir wasm compilation", () => { | ||
it("matches nargos compilation", async () => { | ||
const source = await getSource(); | ||
|
||
const wasmCircuitBase64 = await compileNoirSource(source); | ||
|
||
const cliCircuitBase64 = await getPrecompiledSource(); | ||
|
||
console.log("wasm", wasmCircuitBase64); | ||
|
||
console.log("cli", cliCircuitBase64); | ||
|
||
console.log("Compilation is a match? ", wasmCircuitBase64 === cliCircuitBase64); | ||
|
||
expect(wasmCircuitBase64).to.equal(cliCircuitBase64); | ||
}).timeout(10e3); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { initialiseResolver } from "@noir-lang/noir-source-resolver"; | ||
import { compile } from "../dist/"; | ||
|
||
export const noirSourcePath = "../../noir-script/src/main.nr"; | ||
export const nargoArtifactPath = "../../noir-script/target/noir_wasm_testing.json"; | ||
|
||
export async function compileNoirSource(noir_source: string): Promise<any> { | ||
console.log("Compiling Noir source..."); | ||
|
||
initialiseResolver((id: string) => { | ||
console.log(`Resolving source ${id}`); | ||
|
||
const source = noir_source; | ||
|
||
if (typeof source === "undefined") { | ||
throw Error(`Could not resolve source for '${id}'`); | ||
} else { | ||
return source; | ||
} | ||
}); | ||
|
||
try { | ||
const compiled_noir = compile({}); | ||
|
||
console.log("Noir source compilation done."); | ||
|
||
return compiled_noir.circuit; | ||
} catch (e) { | ||
console.log("Error while compiling:", e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"moduleResolution": "node", | ||
"outDir": "lib", | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"strict": true, | ||
"experimentalDecorators": true, | ||
"esModuleInterop": true, | ||
"noImplicitAny": true, | ||
"removeComments": false, | ||
"preserveConstEnums": true, | ||
"sourceMap": true, | ||
"resolveJsonModule": true, | ||
"importHelpers": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { esbuildPlugin } from "@web/dev-server-esbuild"; | ||
import { playwrightLauncher } from "@web/test-runner-playwright"; | ||
|
||
export default { | ||
browsers: [ | ||
playwrightLauncher({ product: "chromium" }), | ||
playwrightLauncher({ product: "webkit" }), | ||
playwrightLauncher({ product: "firefox" }), | ||
], | ||
plugins: [ | ||
esbuildPlugin({ | ||
ts: true, | ||
}), | ||
], | ||
files: ["test/browser/**/*.test.ts"], | ||
nodeResolve: true, | ||
testFramework: { | ||
config: { | ||
ui: "bdd", | ||
timeout: 40000, | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.