circomlib/test/multiplexer.js
2020-04-18 22:33:59 +02:00

99 lines
2.6 KiB
JavaScript

const path = require("path");
const tester = require("circom").tester;
const Fr = require("ffjavascript").bn128.Fr;
describe("Mux4 test", function() {
this.timeout(100000);
it("Should create a constant multiplexer 4", async () => {
const circuit = await tester(path.join(__dirname, "circuits", "mux4_1.circom"));
const ct16 = [
Fr.e("123"),
Fr.e("456"),
Fr.e("789"),
Fr.e("012"),
Fr.e("111"),
Fr.e("222"),
Fr.e("333"),
Fr.e("4546"),
Fr.e("134523"),
Fr.e("44356"),
Fr.e("15623"),
Fr.e("4566"),
Fr.e("1223"),
Fr.e("4546"),
Fr.e("4256"),
Fr.e("4456")
];
for (let i=0; i<16; i++) {
const w = await circuit.calculateWitness({ "selector": i }, true);
await circuit.checkConstraints(w);
await circuit.assertOut(w, {out: ct16[i]});
}
});
it("Should create a constant multiplexer 3", async () => {
const circuit = await tester(path.join(__dirname, "circuits", "mux3_1.circom"));
const ct8 = [
Fr.e("37"),
Fr.e("47"),
Fr.e("53"),
Fr.e("71"),
Fr.e("89"),
Fr.e("107"),
Fr.e("163"),
Fr.e("191")
];
for (let i=0; i<8; i++) {
const w = await circuit.calculateWitness({ "selector": i }, true);
await circuit.checkConstraints(w);
await circuit.assertOut(w, {out: ct8[i]});
}
});
it("Should create a constant multiplexer 2", async () => {
const circuit = await tester(path.join(__dirname, "circuits", "mux2_1.circom"));
const ct4 = [
Fr.e("37"),
Fr.e("47"),
Fr.e("53"),
Fr.e("71"),
];
for (let i=0; i<4; i++) {
const w = await circuit.calculateWitness({ "selector": i }, true);
await circuit.checkConstraints(w);
await circuit.assertOut(w, {out: ct4[i]});
}
});
it("Should create a constant multiplexer 1", async () => {
const circuit = await tester(path.join(__dirname, "circuits", "mux1_1.circom"));
const ct2 = [
Fr.e("37"),
Fr.e("47"),
];
for (let i=0; i<2; i++) {
const w = await circuit.calculateWitness({ "selector": i }, true);
await circuit.checkConstraints(w);
await circuit.assertOut(w, {out: ct2[i]});
}
});
});