circomlib/test/multiplexer.js
test/multiplexer.jsRaw
1const path = require("path");
2const bigInt = require("big-integer");
3const tester = require("circom").tester;
4
5describe("Mux4 test", function() {
6 this.timeout(100000);
7 it("Should create a constant multiplexer 4", async () => {
8
9 const circuit = await tester(path.join(__dirname, "circuits", "mux4_1.circom"));
10
11 const ct16 = [
12 bigInt("123"),
13 bigInt("456"),
14 bigInt("789"),
15 bigInt("012"),
16 bigInt("111"),
17 bigInt("222"),
18 bigInt("333"),
19 bigInt("4546"),
20 bigInt("134523"),
21 bigInt("44356"),
22 bigInt("15623"),
23 bigInt("4566"),
24 bigInt("1223"),
25 bigInt("4546"),
26 bigInt("4256"),
27 bigInt("4456")
28 ];
29
30 for (let i=0; i<16; i++) {
31 const w = await circuit.calculateWitness({ "selector": i }, true);
32
33 await circuit.checkConstraints(w);
34
35 await circuit.assertOut(w, {out: ct16[i]});
36 }
37 });
38
39 it("Should create a constant multiplexer 3", async () => {
40
41 const circuit = await tester(path.join(__dirname, "circuits", "mux3_1.circom"));
42
43 const ct8 = [
44 bigInt("37"),
45 bigInt("47"),
46 bigInt("53"),
47 bigInt("71"),
48 bigInt("89"),
49 bigInt("107"),
50 bigInt("163"),
51 bigInt("191")
52 ];
53
54 for (let i=0; i<8; i++) {
55 const w = await circuit.calculateWitness({ "selector": i }, true);
56
57 await circuit.checkConstraints(w);
58
59 await circuit.assertOut(w, {out: ct8[i]});
60 }
61 });
62 it("Should create a constant multiplexer 2", async () => {
63
64 const circuit = await tester(path.join(__dirname, "circuits", "mux2_1.circom"));
65
66 const ct4 = [
67 bigInt("37"),
68 bigInt("47"),
69 bigInt("53"),
70 bigInt("71"),
71 ];
72
73 for (let i=0; i<4; i++) {
74 const w = await circuit.calculateWitness({ "selector": i }, true);
75
76 await circuit.checkConstraints(w);
77
78 await circuit.assertOut(w, {out: ct4[i]});
79 }
80 });
81 it("Should create a constant multiplexer 1", async () => {
82
83 const circuit = await tester(path.join(__dirname, "circuits", "mux1_1.circom"));
84
85 const ct2 = [
86 bigInt("37"),
87 bigInt("47"),
88 ];
89
90 for (let i=0; i<2; i++) {
91 const w = await circuit.calculateWitness({ "selector": i }, true);
92
93 await circuit.checkConstraints(w);
94
95 await circuit.assertOut(w, {out: ct2[i]});
96 }
97 });
98});