Skip to content

Commit

Permalink
add prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
saleel committed Sep 8, 2024
1 parent c2408e7 commit f4ddc79
Show file tree
Hide file tree
Showing 21 changed files with 684 additions and 914 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages/helpers/src/lib
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": true,
"tabWidth": 2,
"singleQuote": true,
"printWidth": 120
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"license": "MIT",
"private": true,
"scripts": {
"lint": "yarn prettier --write packages/**/**.ts",
"test": "jest"
},
"workspaces": [
Expand All @@ -12,5 +13,8 @@
"packageManager": "[email protected]",
"engines": {
"node": ">=14.0.0"
},
"devDependencies": {
"prettier": "^3.3.3"
}
}
46 changes: 21 additions & 25 deletions packages/circuits/tests/base64.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import { wasm } from "circom_tester";
import path from "path";
import { wasm } from 'circom_tester';
import path from 'path';


describe("Base64 Lookup", () => {
describe('Base64 Lookup', () => {
jest.setTimeout(10 * 60 * 1000); // 10 minutes

let circuit: any;

beforeAll(async () => {
circuit = await wasm(
path.join(__dirname, "./test-circuits/base64-test.circom"),
{
recompile: true,
include: path.join(__dirname, "../../../node_modules"),
// output: path.join(__dirname, "./compiled-test-circuits"),
}
);
circuit = await wasm(path.join(__dirname, './test-circuits/base64-test.circom'), {
recompile: true,
include: path.join(__dirname, '../../../node_modules'),
// output: path.join(__dirname, "./compiled-test-circuits"),
});
});

it("should decode valid base64 chars", async function () {
it('should decode valid base64 chars', async function () {
const inputs = [
[65, 0], // A
[90, 25], // Z
Expand All @@ -29,30 +25,30 @@ describe("Base64 Lookup", () => {
[43, 62], // +
[47, 63], // /
[61, 0], // =
]
];

for (const [input, output] of inputs) {
const witness = await circuit.calculateWitness({
in: input
in: input,
});
await circuit.checkConstraints(witness);
await circuit.assertOut(witness, { out: output })
await circuit.assertOut(witness, { out: output });
}
});

it("should fail with invalid chars", async function () {
it('should fail with invalid chars', async function () {
const inputs = [34, 64, 91, 44];

expect.assertions(inputs.length);
for (const input of inputs) {
try {
const witness = await circuit.calculateWitness({
in: input
});
await circuit.checkConstraints(witness);
} catch (error) {
expect((error as Error).message).toMatch("Assert Failed");
}
try {
const witness = await circuit.calculateWitness({
in: input,
});
await circuit.checkConstraints(witness);
} catch (error) {
expect((error as Error).message).toMatch('Assert Failed');
}
}
});
});
73 changes: 35 additions & 38 deletions packages/circuits/tests/body-masker.test.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
import { wasm as wasm_tester } from "circom_tester";
import path from "path";
import { wasm as wasm_tester } from 'circom_tester';
import path from 'path';

describe("ByteMask Circuit", () => {
let circuit: any;
describe('ByteMask Circuit', () => {
let circuit: any;

beforeAll(async () => {
circuit = await wasm_tester(
path.join(__dirname, "./test-circuits/body-masker-test.circom"),
{
recompile: true,
include: path.join(__dirname, "../../../node_modules"),
output: path.join(__dirname, "./compiled-test-circuits"),
}
);
beforeAll(async () => {
circuit = await wasm_tester(path.join(__dirname, './test-circuits/body-masker-test.circom'), {
recompile: true,
include: path.join(__dirname, '../../../node_modules'),
output: path.join(__dirname, './compiled-test-circuits'),
});
});

it("should mask the body correctly", async () => {
const input = {
body: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
mask: [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],
};
it('should mask the body correctly', async () => {
const input = {
body: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
mask: [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],
};

const witness = await circuit.calculateWitness(input);
await circuit.checkConstraints(witness);
await circuit.assertOut(witness, {
maskedBody: [1, 0, 3, 0, 5, 0, 7, 0, 9, 0],
});
const witness = await circuit.calculateWitness(input);
await circuit.checkConstraints(witness);
await circuit.assertOut(witness, {
maskedBody: [1, 0, 3, 0, 5, 0, 7, 0, 9, 0],
});
});

it("should fail if mask has non-bit numbers", async () => {
const input = {
body: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
mask: [1, 2, 1, 0, 1, 0, 1, 0, 1, 0], // Mask with non-bit number (2)
};
it('should fail if mask has non-bit numbers', async () => {
const input = {
body: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
mask: [1, 2, 1, 0, 1, 0, 1, 0, 1, 0], // Mask with non-bit number (2)
};

try {
const witness = await circuit.calculateWitness(input);
await circuit.checkConstraints(witness);
await circuit.assertOut(witness, {
maskedBody: [1, 0, 3, 0, 5, 0, 7, 0, 9, 0],
});
} catch (error) {
expect(error).toBeTruthy();
}
});
try {
const witness = await circuit.calculateWitness(input);
await circuit.checkConstraints(witness);
await circuit.assertOut(witness, {
maskedBody: [1, 0, 3, 0, 5, 0, 7, 0, 9, 0],
});
} catch (error) {
expect(error).toBeTruthy();
}
});
});
Loading

0 comments on commit f4ddc79

Please sign in to comment.