Skip to content

Commit

Permalink
chore(ci): run noir_js tests in CI (noir-lang#2843)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored and Sakapoi committed Oct 19, 2023
1 parent b30010f commit 6fba5d9
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 74 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/acvm-test-acvm-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ jobs:
uses: actions/download-artifact@v3
with:
name: acvm-js
path: ./acvm-repo/result
path: ./result

- name: Move build artifacts
run: |
mv ./result/acvm_js/nodejs ./acvm-repo/acvm_js/nodejs
mv ./result/acvm_js/web ./acvm-repo/acvm_js/web
- name: Set up test environment
uses: ./.github/actions/setup
Expand All @@ -72,7 +77,12 @@ jobs:
uses: actions/download-artifact@v3
with:
name: acvm-js
path: ./acvm-repo/result
path: ./result

- name: Move build artifacts
run: |
mv ./result/acvm_js/nodejs ./acvm-repo/acvm_js/nodejs
mv ./result/acvm_js/web ./acvm-repo/acvm_js/web
- name: Set up test environment
uses: ./.github/actions/setup
Expand Down
59 changes: 59 additions & 0 deletions .github/workflows/test-noir-js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Noir JS

on:
pull_request:
merge_group:
push:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Yarn dependencies
uses: ./.github/actions/setup

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.66.0
with:
targets: wasm32-unknown-unknown

- uses: Swatinem/rust-cache@v2
with:
key: wasm32-unknown-unknown-noir-js
cache-on-failure: true
save-if: ${{ github.event_name != 'merge_group' }}

- name: Install jq
run: sudo apt-get install jq

- name: Install wasm-bindgen-cli
uses: taiki-e/install-action@v2
with:
tool: wasm-bindgen-cli@0.2.86

- name: Install toml2json
uses: taiki-e/install-action@v2
with:
tool: toml2json@1.3.1

- name: Install wasm-opt
run: |
npm i wasm-opt -g
- name: Build acvm_js
run: yarn workspace @noir-lang/acvm_js build

- name: Build noirc_abi
run: yarn workspace @noir-lang/noirc_abi build

- name: Run noir_js tests
run: |
yarn workspace @noir-lang/noir_js build
yarn workspace @noir-lang/noir_js test
14 changes: 5 additions & 9 deletions acvm-repo/acvm_js/.gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
/target
.DS_Store
examples/**/target/
examples/9
.vscode
node_modules
pkg/
lib/

# Build outputs
result
.direnv
**/outputs
nodejs
web

# Yarn
.pnp.*
Expand All @@ -17,4 +13,4 @@ result
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
!.yarn/versions
11 changes: 7 additions & 4 deletions acvm-repo/acvm_js/buildPhaseCargoCommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ function run_if_available {

export self_path=$(dirname "$(readlink -f "$0")")


NODE_DIR=$self_path/nodejs/
BROWSER_DIR=$self_path/web/

# Clear out the existing build artifacts as these aren't automatically removed by wasm-pack.
if [ -d ./pkg/ ]; then
rm -rf $self_path/pkg/
rm -r $NODE_DIR
rm -r $BROWSER_DIR
fi

TARGET=wasm32-unknown-unknown
WASM_BINARY=$CARGO_TARGET_DIR/$TARGET/release/${pname}.wasm

NODE_DIR=$self_path/pkg/nodejs/
BROWSER_DIR=$self_path/pkg/web/
NODE_WASM=${NODE_DIR}/${pname}_bg.wasm
BROWSER_WASM=${BROWSER_DIR}/${pname}_bg.wasm

Expand All @@ -36,4 +39,4 @@ run_or_fail cargo build --lib --release --target $TARGET --package ${pname}
run_or_fail wasm-bindgen $WASM_BINARY --out-dir $NODE_DIR --typescript --target nodejs
run_or_fail wasm-bindgen $WASM_BINARY --out-dir $BROWSER_DIR --typescript --target web
run_if_available wasm-opt $NODE_WASM -o $NODE_WASM -O
run_if_available wasm-opt $BROWSER_WASM -o $BROWSER_WASM -O
run_if_available wasm-opt $BROWSER_WASM -o $BROWSER_WASM -O
16 changes: 6 additions & 10 deletions acvm-repo/acvm_js/installPhase.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#!/usr/bin/env bash
export self_path=$(dirname "$(readlink -f "$0")")

mkdir -p $out
cp $self_path/README.md $out/
cp -r $self_path/pkg/* $out/
export out_path=$out/acvm_js

# The main package.json contains several keys which are incorrect/unwanted when distributing.
cat $self_path/package.json \
| jq 'del(.private, .devDependencies, .scripts, .packageManager)' \
> $out/package.json

# Cleanup temporary pkg directory
rm -r $self_path/pkg
mkdir -p $out_path
cp $self_path/README.md $out_path/
cp $self_path/package.json $out_path/
cp -r $self_path/nodejs $out_path/
cp -r $self_path/web $out_path/
37 changes: 0 additions & 37 deletions acvm-repo/acvm_js/nix/wasm-bindgen-cli/default.nix

This file was deleted.

2 changes: 1 addition & 1 deletion acvm-repo/acvm_js/test/browser/execute_circuit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import initACVM, {
WitnessMap,
initLogLevel,
ForeignCallHandler,
} from "../../../result/";
} from "@noir-lang/acvm_js";

beforeEach(async () => {
await initACVM();
Expand Down
5 changes: 4 additions & 1 deletion acvm-repo/acvm_js/test/browser/witness_conversion.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { expect } from "@esm-bundle/chai";
import initACVM, { compressWitness, decompressWitness } from "../../../result/";
import initACVM, {
compressWitness,
decompressWitness,
} from "@noir-lang/acvm_js";
import {
expectedCompressedWitnessMap,
expectedWitnessMap,
Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm_js/test/node/build_info.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "chai";
import { BuildInfo, buildInfo } from "../../../result/";
import { BuildInfo, buildInfo } from "@noir-lang/acvm_js";
import child_process from "child_process";
import pkg from "../../package.json";

Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm_js/test/node/execute_circuit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
WasmBlackBoxFunctionSolver,
WitnessMap,
ForeignCallHandler,
} from "../../../result/";
} from "@noir-lang/acvm_js";

it("successfully executes circuit and extracts return value", async () => {
const { bytecode, initialWitnessMap, resultWitness, expectedResult } =
Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm_js/test/node/witness_conversion.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "chai";
import { compressWitness, decompressWitness } from "../../../result/";
import { compressWitness, decompressWitness } from "@noir-lang/acvm_js";
import {
expectedCompressedWitnessMap,
expectedWitnessMap,
Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm_js/test/shared/addition.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WitnessMap } from "../../../result/";
import { WitnessMap } from "@noir-lang/acvm_js";

// See `addition_circuit` integration test in `acir/tests/test_program_serialization.rs`.
export const bytecode = Uint8Array.from([
Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm_js/test/shared/complex_foreign_call.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WitnessMap } from "../../../result/";
import { WitnessMap } from "@noir-lang/acvm_js";

// See `complex_brillig_foreign_call` integration test in `acir/tests/test_program_serialization.rs`.
export const bytecode = Uint8Array.from([
Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm_js/test/shared/foreign_call.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WitnessMap } from "../../../result/";
import { WitnessMap } from "@noir-lang/acvm_js";

// See `simple_brillig_foreign_call` integration test in `acir/tests/test_program_serialization.rs`.
export const bytecode = Uint8Array.from([
Expand Down
4 changes: 2 additions & 2 deletions tooling/noir_js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"dev": "tsc-multi --watch",
"build": "tsc-multi",
"test": "yarn test:node:esm && yarn test:node:cjs",
"test:node:esm": "mocha --timeout 25000 --config ./.mocharc.json",
"test:node:cjs": "mocha --timeout 25000 --config ./.mocharc.cjs.json",
"test:node:esm": "mocha --timeout 25000 --exit --config ./.mocharc.json",
"test:node:cjs": "mocha --timeout 25000 --exit --config ./.mocharc.cjs.json",
"prettier": "prettier 'src/**/*.ts'",
"prettier:fix": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
"lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0"
Expand Down
4 changes: 2 additions & 2 deletions tooling/noir_js/src/witness_generation.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { abiEncode } from '@noir-lang/noirc_abi';
import { validateInputs } from './input_validation.js';
import { base64Decode } from './base64_decode.js';
import { WitnessMap, executeCircuit } from '@noir-lang/acvm_js';
import { executeCircuit } from '@noir-lang/acvm_js';
import { witnessMapToUint8Array } from './serialize.js';

// Generates the witnesses needed to feed into the chosen proving system
export async function generateWitness(compiledProgram, inputs): Promise<WitnessMap> {
export async function generateWitness(compiledProgram, inputs): Promise<Uint8Array> {
// Validate inputs
const { isValid, error } = validateInputs(inputs, compiledProgram.abi);
if (!isValid) {
Expand Down

0 comments on commit 6fba5d9

Please sign in to comment.