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("inout", async () => {
23        await doTest(
24            "inout.circom",
25            [
26                [{in1: 1, in2: [2,3], in3:[[4,5], [6,7], [8,9]]}, {out1: 1, out2: [2,3], out3: [[4,5], [6,7],[8,9]]}],
27            ]
28        );
29    });
30    it("add", async () => {
31        await doTest(
32            "add.circom",
33            [
34                [{in: [0,0]}, {out: 0}],
35                [{in: [0,1]}, {out: 1}],
36                [{in: [1,2]}, {out: 3}],
37                [{in: [__P__.minus(1),1]}, {out: 0}],
38            ]
39        );
40    });
41    it("add constant", async () => {
42        await doTest(
43            "addconst1.circom",
44            [
45                [{in: 0}, {out: 15}],
46                [{in: 10}, {out: 25}],
47                [{in: __P__.minus(2)}, {out: 13}],
48            ]
49        );
50    });
51    it("for unrolled", async () => {
52        await doTest(
53            "forunrolled.circom",
54            [
55                [{in: 0}, {out: [0,1,2]}],
56                [{in: 10}, {out: [10, 11, 12]}],
57                [{in: __P__.minus(2)}, {out: [__P__.minus(2), __P__.minus(1), 0]}],
58            ]
59        );
60    });
61    it("for rolled", async () => {
62        await doTest(
63            "forrolled.circom",
64            [
65                [{in: 0}, {out: 0}],
66                [{in: 10}, {out: 10}],
67            ]
68        );
69    });
70    it("function1", async () => {
71        await doTest(
72            "function1.circom",
73            [
74                [{in: 0}, {out: 3}],
75                [{in: 10}, {out: 13}],
76                [{in: __P__.minus(2)}, {out: 1}],
77            ]
78        );
79    });
80    it("function2", async () => {
81        await doTest(
82            "function2.circom",
83            [
84                [{in: 0}, {out: 3}],
85                [{in: 10}, {out: 13}],
86                [{in: __P__.minus(2)}, {out: 1}],
87            ]
88        );
89    });
90});