Skip to content

Commit

Permalink
chore: add prettier config (noir-lang#2894)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored and Sakapoi committed Oct 19, 2023
1 parent f00c3a8 commit d05b0fa
Show file tree
Hide file tree
Showing 41 changed files with 634 additions and 967 deletions.
22 changes: 11 additions & 11 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", "prettier"],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'prettier'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
rules: {
"comma-spacing": ["error", { before: false, after: true }],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn", // or "error"
'comma-spacing': ['error', { before: false, after: true }],
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'warn', // or "error"
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
"prettier/prettier": "error",
'prettier/prettier': 'error',
},
};
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parser": "typescript",
"printWidth": 120,
"singleQuote": true,
"trailingComma": "all"
}
167 changes: 50 additions & 117 deletions acvm-repo/acvm_js/test/browser/execute_circuit.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from "@esm-bundle/chai";
import { expect } from '@esm-bundle/chai';
import initACVM, {
createBlackBoxSolver,
executeCircuit,
Expand All @@ -7,25 +7,20 @@ import initACVM, {
WitnessMap,
initLogLevel,
ForeignCallHandler,
} from "@noir-lang/acvm_js";
} from '@noir-lang/acvm_js';

beforeEach(async () => {
await initACVM();

initLogLevel("INFO");
initLogLevel('INFO');
});

it("successfully executes circuit and extracts return value", async () => {
const { bytecode, initialWitnessMap, resultWitness, expectedResult } =
await import("../shared/addition");
it('successfully executes circuit and extracts return value', async () => {
const { bytecode, initialWitnessMap, resultWitness, expectedResult } = await import('../shared/addition');

const solvedWitness: WitnessMap = await executeCircuit(
bytecode,
initialWitnessMap,
() => {
throw Error("unexpected oracle");
},
);
const solvedWitness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, () => {
throw Error('unexpected oracle');
});

// Solved witness should be consistent with initial witness
initialWitnessMap.forEach((value, key) => {
Expand All @@ -36,22 +31,13 @@ it("successfully executes circuit and extracts return value", async () => {
expect(solvedWitness.get(resultWitness)).to.be.eq(expectedResult);
});

it("successfully processes simple brillig foreign call opcodes", async () => {
const {
bytecode,
initialWitnessMap,
expectedWitnessMap,
oracleResponse,
oracleCallName,
oracleCallInputs,
} = await import("../shared/foreign_call");

let observedName = "";
it('successfully processes simple brillig foreign call opcodes', async () => {
const { bytecode, initialWitnessMap, expectedWitnessMap, oracleResponse, oracleCallName, oracleCallInputs } =
await import('../shared/foreign_call');

let observedName = '';
let observedInputs: string[][] = [];
const foreignCallHandler: ForeignCallHandler = async (
name: string,
inputs: string[][],
) => {
const foreignCallHandler: ForeignCallHandler = async (name: string, inputs: string[][]) => {
// Throwing inside the oracle callback causes a timeout so we log the observed values
// and defer the check against expected values until after the execution is complete.
observedName = name;
Expand All @@ -60,11 +46,7 @@ it("successfully processes simple brillig foreign call opcodes", async () => {
return oracleResponse;
};

const solved_witness: WitnessMap = await executeCircuit(
bytecode,
initialWitnessMap,
foreignCallHandler,
);
const solved_witness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, foreignCallHandler);

// Check that expected values were passed to oracle callback.
expect(observedName).to.be.eq(oracleCallName);
Expand All @@ -75,22 +57,13 @@ it("successfully processes simple brillig foreign call opcodes", async () => {
expect(solved_witness).to.be.deep.eq(expectedWitnessMap);
});

it("successfully processes complex brillig foreign call opcodes", async () => {
const {
bytecode,
initialWitnessMap,
expectedWitnessMap,
oracleResponse,
oracleCallName,
oracleCallInputs,
} = await import("../shared/complex_foreign_call");

let observedName = "";
it('successfully processes complex brillig foreign call opcodes', async () => {
const { bytecode, initialWitnessMap, expectedWitnessMap, oracleResponse, oracleCallName, oracleCallInputs } =
await import('../shared/complex_foreign_call');

let observedName = '';
let observedInputs: string[][] = [];
const foreignCallHandler: ForeignCallHandler = async (
name: string,
inputs: string[][],
) => {
const foreignCallHandler: ForeignCallHandler = async (name: string, inputs: string[][]) => {
// Throwing inside the oracle callback causes a timeout so we log the observed values
// and defer the check against expected values until after the execution is complete.
observedName = name;
Expand All @@ -99,11 +72,7 @@ it("successfully processes complex brillig foreign call opcodes", async () => {
return oracleResponse;
};

const solved_witness: WitnessMap = await executeCircuit(
bytecode,
initialWitnessMap,
foreignCallHandler,
);
const solved_witness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, foreignCallHandler);

// Check that expected values were passed to oracle callback.
expect(observedName).to.be.eq(oracleCallName);
Expand All @@ -114,98 +83,62 @@ it("successfully processes complex brillig foreign call opcodes", async () => {
expect(solved_witness).to.be.deep.eq(expectedWitnessMap);
});

it("successfully executes a Pedersen opcode", async function () {
const { bytecode, initialWitnessMap, expectedWitnessMap } = await import(
"../shared/pedersen"
);
it('successfully executes a Pedersen opcode', async function () {
const { bytecode, initialWitnessMap, expectedWitnessMap } = await import('../shared/pedersen');

const solvedWitness: WitnessMap = await executeCircuit(
bytecode,
initialWitnessMap,
() => {
throw Error("unexpected oracle");
},
);
const solvedWitness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, () => {
throw Error('unexpected oracle');
});

expect(solvedWitness).to.be.deep.eq(expectedWitnessMap);
});

it("successfully executes a FixedBaseScalarMul opcode", async () => {
const { bytecode, initialWitnessMap, expectedWitnessMap } = await import(
"../shared/fixed_base_scalar_mul"
);
it('successfully executes a FixedBaseScalarMul opcode', async () => {
const { bytecode, initialWitnessMap, expectedWitnessMap } = await import('../shared/fixed_base_scalar_mul');

const solvedWitness: WitnessMap = await executeCircuit(
bytecode,
initialWitnessMap,
() => {
throw Error("unexpected oracle");
},
);
const solvedWitness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, () => {
throw Error('unexpected oracle');
});

expect(solvedWitness).to.be.deep.eq(expectedWitnessMap);
});

it("successfully executes a SchnorrVerify opcode", async () => {
const { bytecode, initialWitnessMap, expectedWitnessMap } = await import(
"../shared/schnorr_verify"
);
it('successfully executes a SchnorrVerify opcode', async () => {
const { bytecode, initialWitnessMap, expectedWitnessMap } = await import('../shared/schnorr_verify');

const solvedWitness: WitnessMap = await executeCircuit(
bytecode,
initialWitnessMap,
() => {
throw Error("unexpected oracle");
},
);
const solvedWitness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, () => {
throw Error('unexpected oracle');
});

expect(solvedWitness).to.be.deep.eq(expectedWitnessMap);
});

it("successfully executes a MemoryOp opcode", async () => {
const { bytecode, initialWitnessMap, expectedWitnessMap } = await import(
"../shared/memory_op"
);
it('successfully executes a MemoryOp opcode', async () => {
const { bytecode, initialWitnessMap, expectedWitnessMap } = await import('../shared/memory_op');

const solvedWitness: WitnessMap = await executeCircuit(
bytecode,
initialWitnessMap,
() => {
throw Error("unexpected oracle");
},
);
const solvedWitness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, () => {
throw Error('unexpected oracle');
});

expect(solvedWitness).to.be.deep.eq(expectedWitnessMap);
});

it("successfully executes two circuits with same backend", async function () {
it('successfully executes two circuits with same backend', async function () {
// chose pedersen op here because it is the one with slow initialization
// that led to the decision to pull backend initialization into a separate
// function/wasmbind
const solver: WasmBlackBoxFunctionSolver = await createBlackBoxSolver();

const { bytecode, initialWitnessMap, expectedWitnessMap } = await import(
"../shared/pedersen"
);
const { bytecode, initialWitnessMap, expectedWitnessMap } = await import('../shared/pedersen');

const solvedWitness0: WitnessMap = await executeCircuitWithBlackBoxSolver(
solver,
bytecode,
initialWitnessMap,
() => {
throw Error("unexpected oracle");
},
);
const solvedWitness0: WitnessMap = await executeCircuitWithBlackBoxSolver(solver, bytecode, initialWitnessMap, () => {
throw Error('unexpected oracle');
});

expect(solvedWitness0).to.be.deep.eq(expectedWitnessMap);

const solvedWitness1: WitnessMap = await executeCircuitWithBlackBoxSolver(
solver,
bytecode,
initialWitnessMap,
() => {
throw Error("unexpected oracle");
},
);
const solvedWitness1: WitnessMap = await executeCircuitWithBlackBoxSolver(solver, bytecode, initialWitnessMap, () => {
throw Error('unexpected oracle');
});
expect(solvedWitness1).to.be.deep.eq(expectedWitnessMap);
});
16 changes: 5 additions & 11 deletions acvm-repo/acvm_js/test/browser/witness_conversion.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
import { expect } from "@esm-bundle/chai";
import initACVM, {
compressWitness,
decompressWitness,
} from "@noir-lang/acvm_js";
import {
expectedCompressedWitnessMap,
expectedWitnessMap,
} from "../shared/witness_compression";
import { expect } from '@esm-bundle/chai';
import initACVM, { compressWitness, decompressWitness } from '@noir-lang/acvm_js';
import { expectedCompressedWitnessMap, expectedWitnessMap } from '../shared/witness_compression';

beforeEach(async () => {
await initACVM();
});

it("successfully compresses the witness", async () => {
it('successfully compresses the witness', async () => {
const compressedWitnessMap = compressWitness(expectedWitnessMap);

expect(compressedWitnessMap).to.be.deep.eq(expectedCompressedWitnessMap);
});

it("successfully decompresses the witness", async () => {
it('successfully decompresses the witness', async () => {
const witnessMap = decompressWitness(expectedCompressedWitnessMap);

expect(witnessMap).to.be.deep.eq(expectedWitnessMap);
Expand Down
15 changes: 6 additions & 9 deletions acvm-repo/acvm_js/test/node/build_info.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { expect } from "chai";
import { BuildInfo, buildInfo } from "@noir-lang/acvm_js";
import child_process from "child_process";
import pkg from "../../package.json";
import { expect } from 'chai';
import { BuildInfo, buildInfo } from '@noir-lang/acvm_js';
import child_process from 'child_process';
import pkg from '../../package.json';

it("returns the correct build into", () => {
it('returns the correct build into', () => {
const info: BuildInfo = buildInfo();

// TODO: enforce that `package.json` and `Cargo.toml` are consistent.
expect(info.version).to.be.eq(pkg.version);

const revision = child_process
.execSync("git rev-parse HEAD")
.toString()
.trim();
const revision = child_process.execSync('git rev-parse HEAD').toString().trim();
expect(info.gitHash).to.be.eq(revision);
});
Loading

0 comments on commit d05b0fa

Please sign in to comment.