arnaucube
arnaucube/circomPublic Self-hosted repository
circom/test/basiccases.js
test/basiccases.jsRaw
 1const path = require("path");
 2
 3const bigInt = require("big-integer");
 4const c_tester = require("../index.js").c_tester;
 5
 6const __P__ = new bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
 7
 8
 9async function doTest(circuit, testVectors) {
10    const cir = await c_tester(path.join(__dirname, "circuits", circuit));
11
12    for (let i=0; i<testVectors.length; i++) {
13        const w = await cir.calculateWitness(testVectors[i][0]);
14        await cir.assertOut(w, testVectors[i][1] );
15    }
16
17    await cir.release();
18}
19
20describe("basic cases", function () {
21    this.timeout(100000);
22    it("add", async () => {
23        await doTest(
24            "add.circom",
25            [
26                [{in: [0,0]}, {out: 0}],
27                [{in: [0,1]}, {out: 1}],
28                [{in: [1,2]}, {out: 3}],
29                [{in: [__P__.minus(1),1]}, {out: 0}],
30            ]
31        );
32    });
33    it("add constant", async () => {
34        await doTest(
35            "addconst1.circom",
36            [
37                [{in: 0}, {out: 15}],
38                [{in: 10}, {out: 25}],
39                [{in: __P__.minus(2)}, {out: 13}],
40            ]
41        );
42    });
43    it("for unrolled", async () => {
44        await doTest(
45            "forunrolled.circom",
46            [
47                [{in: 0}, {out: [0,1,2]}],
48                [{in: 10}, {out: [10, 11, 12]}],
49                [{in: __P__.minus(2)}, {out: [__P__.minus(2), __P__.minus(1), 0]}],
50            ]
51        );
52    });
53    it("for rolled", async () => {
54        await doTest(
55            "forrolled.circom",
56            [
57                [{in: 0}, {out: 0}],
58                [{in: 10}, {out: 10}],
59            ]
60        );
61    });
62});