circomlib/test/binsum.js

34 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2018-12-06 19:32:49 +03:00
const chai = require("chai");
const path = require("path");
const snarkjs = require("@tornado/snarkjs");
2018-12-06 19:32:49 +03:00
const crypto = require("crypto");
const compiler = require("circom");
const assert = chai.assert;
describe("Sum test", () => {
it("Should create a constant circuit", async () => {
const cirDef = await compiler(path.join(__dirname, "circuits", "constants_test.circom"));
assert.equal(cirDef.nVars, 2);
const circuit = new snarkjs.Circuit(cirDef);
const witness = circuit.calculateWitness({ in: "0xd807aa98" });
2018-12-06 19:32:49 +03:00
assert(witness[0].equals(snarkjs.bigInt(1)));
assert(witness[1].equals(snarkjs.bigInt("0xd807aa98")));
});
it("Should create a sum circuit", async () => {
const cirDef = await compiler(path.join(__dirname, "circuits", "sum_test.circom"));
assert.equal(cirDef.nVars, 97); // 32 (in1) + 32(in2) + 32(out) + 1 (carry)
2018-12-06 19:32:49 +03:00
const circuit = new snarkjs.Circuit(cirDef);
const witness = circuit.calculateWitness({ a: "111", b: "222" });
2018-12-06 19:32:49 +03:00
assert(witness[0].equals(snarkjs.bigInt(1)));
assert(witness[1].equals(snarkjs.bigInt("333")));
});
});