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