Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
alrubio authored Sep 14, 2023
2 parents 26fc9e7 + a551eb3 commit d34af46
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,36 @@
# circom_tester
# circom tester
## Setup
1. Create new node js project.
2. Install `circom_tester` and `chai` packges.
3. Install `mocha` packge to run the tests.


## Creating & Running a test file

Create a js file contain the following code or use the src provided in the following section.
<br>Execue `mocha -p -r ts-node/register 'multiplier2.js'` to run the test file.

multiplier2.js ([src](test/multiplier2.js))
``` multiplier2.js
const chai = require("chai");
const path = require("path");
const wasm_tester = require("./../index").wasm;
const c_tester = require("./../index").c;

const F1Field = require("ffjavascript").F1Field;
const Scalar = require("ffjavascript").Scalar;
exports.p = Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");
const Fr = new F1Field(exports.p);

const assert = chai.assert;

describe("Simple test", function () {
this.timeout(100000);

it("Checking the compilation of a simple circuit generating wasm", async function () {
const circuit = await wasm_tester(path.join(__dirname, "Multiplier2circom"));
const w = await circuit.calculateWitness({a: 2, b: 4});
await circuit.checkConstraints(w);
});
});
```
12 changes: 6 additions & 6 deletions c/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ async function compile (baseName, fileName, options) {
if (options.verbose) flags += "--verbose ";

try {
b = await exec("circom " + flags + fileName);
if (options.verbose) {
let b = await exec("circom " + flags + fileName);
if (options.verbose) {
console.log(b.stdout);
}
}
} catch (e) {
assert(false,
"circom compiler error \n" + e);
assert(false,
"circom compiler error \n" + e);
}

const c_folder = path.join(options.output, baseName+"_cpp/")
Expand Down Expand Up @@ -245,7 +245,7 @@ function check_versions ( v1, v2 ) {
async function compiler_above_version(v) {
let output = (await exec('circom --version')).stdout;
let compiler_version = version_to_list(output.slice(output.search(/\d/),-1));
vlist = version_to_list(v);
let vlist = version_to_list(v);
return check_versions ( compiler_version, vlist );
}

Expand Down
16 changes: 8 additions & 8 deletions wasm/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ async function compile (fileName, options) {
if (options.verbose) flags += "--verbose ";

try {
b = await exec("circom " + flags + fileName);
if (options.verbose) {
let b = await exec("circom " + flags + fileName);
if (options.verbose) {
console.log(b.stdout);
}
if (b.stderr != '') {
throw(b.stderr);
}
if (b.stderr != '') {
throw(b.stderr);
}
} catch (e) {
assert(false,
"circom compiler error \n" + e);
assert(false,
"circom compiler error \n" + e);
}
}

Expand Down Expand Up @@ -236,6 +236,6 @@ function check_versions ( v1, v2 ) {
async function compiler_above_version(v) {
let output = (await exec('circom --version')).stdout;
let compiler_version = version_to_list(output.slice(output.search(/\d/),-1));
vlist = version_to_list(v);
let vlist = version_to_list(v);
return check_versions ( compiler_version, vlist );
}

0 comments on commit d34af46

Please sign in to comment.