arnaucube
arnaucube/circomPublic Self-hosted repository
circom/test/cases.js
test/cases.jsRaw
 1const chai = require("chai");
 2const path = require("path");
 3const snarkjs = require("snarkjs");
 4
 5const bigInt = snarkjs.bigInt;
 6
 7const compiler = require("../index.js");
 8
 9const assert = chai.assert;
10
11async function assertThrowsAsync(fn, regExp) {
12    let f = () => {};
13    try {
14        await fn();
15    } catch(e) {
16        f = () => { throw e; };
17    } finally {
18        assert.throws(f, regExp);
19    }
20}
21
22describe("Sum test", () => {
23    it("Should compile a code with an undefined if", async () => {
24        await compiler(path.join(__dirname, "circuits", "undefinedif.circom"));
25    });
26    it("Should compile a code with vars inside a for", async () => {
27        const cirDef = await compiler(path.join(__dirname, "circuits", "forvariables.circom"));
28
29        const circuit = new snarkjs.Circuit(cirDef);
30
31        const witness = circuit.calculateWitness({ "in": 111});
32        assert(witness[0].equals(bigInt(1)));
33        assert(witness[1].equals(bigInt(114)));
34        assert(witness[2].equals(bigInt(111)));
35
36    });
37    it("Should compile a code with an undefined if", async () => {
38        const cirDef = await compiler(path.join(__dirname, "circuits", "mixvarsignal.circom"));
39
40        const circuit = new snarkjs.Circuit(cirDef);
41
42        const witness = circuit.calculateWitness({ "i": 111});
43        assert(witness[0].equals(bigInt(1)));
44        assert(witness[1].equals(bigInt(111*111)));
45        assert(witness[2].equals(bigInt(111)));
46    });
47//    it("Should assign signal ERROR", async () => {
48//        await assertThrowsAsync(async () => {
49//            await compiler(path.join(__dirname, "circuits", "assignsignal.circom"));
50//        }, /Cannot assign to a signal .*/);
51//    });
52});