2018-12-06 19:32:49 +03:00
|
|
|
const chai = require("chai");
|
|
|
|
const path = require("path");
|
|
|
|
|
2019-12-13 20:35:29 +03:00
|
|
|
const tester = require("circom").tester;
|
|
|
|
|
|
|
|
const bigInt = require("big-integer");
|
2018-12-06 19:32:49 +03:00
|
|
|
|
|
|
|
const assert = chai.assert;
|
|
|
|
|
2019-12-23 21:36:26 +03:00
|
|
|
describe("Binary sum test", function () {
|
2018-12-06 19:32:49 +03:00
|
|
|
|
2019-12-16 23:35:52 +03:00
|
|
|
this.timeout(100000000);
|
2018-12-06 19:32:49 +03:00
|
|
|
|
2019-12-13 20:35:29 +03:00
|
|
|
it("Should create a constant circuit", async () => {
|
|
|
|
const circuit = await tester(path.join(__dirname, "circuits", "constants_test.circom"));
|
2019-12-16 23:35:52 +03:00
|
|
|
await circuit.loadConstraints();
|
2018-12-06 19:32:49 +03:00
|
|
|
|
2019-12-16 23:35:52 +03:00
|
|
|
assert.equal(circuit.nWires, 2);
|
2018-12-06 19:32:49 +03:00
|
|
|
|
2019-12-13 20:35:29 +03:00
|
|
|
const witness = await circuit.calculateWitness({ "in": bigInt("d807aa98", 16)});
|
|
|
|
|
|
|
|
assert(witness[0].equals(bigInt(1)));
|
|
|
|
assert(witness[1].equals(bigInt("d807aa98", 16)));
|
2018-12-06 19:32:49 +03:00
|
|
|
});
|
|
|
|
it("Should create a sum circuit", async () => {
|
2019-12-13 20:35:29 +03:00
|
|
|
const circuit = await tester(path.join(__dirname, "circuits", "sum_test.circom"));
|
2019-12-16 23:35:52 +03:00
|
|
|
await circuit.loadConstraints();
|
2018-12-06 19:32:49 +03:00
|
|
|
|
2019-12-16 23:35:52 +03:00
|
|
|
assert.equal(circuit.nWires, 97); // 32 (in1) + 32(in2) + 32(out) + 1 (carry)
|
2018-12-06 19:32:49 +03:00
|
|
|
|
2019-12-13 20:35:29 +03:00
|
|
|
const witness = await circuit.calculateWitness({ "a": "111", "b": "222" });
|
2018-12-06 19:32:49 +03:00
|
|
|
|
2019-12-13 20:35:29 +03:00
|
|
|
assert(witness[0].equals(bigInt(1)));
|
|
|
|
assert(witness[1].equals(bigInt("333")));
|
2018-12-06 19:32:49 +03:00
|
|
|
});
|
|
|
|
});
|