You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.2 KiB

  1. const chai = require("chai");
  2. const path = require("path");
  3. const tester = require("circom").tester;
  4. const bigInt = require("big-integer");
  5. const assert = chai.assert;
  6. describe("Binary sum test", function () {
  7. this.timeout(100000000);
  8. it("Should create a constant circuit", async () => {
  9. const circuit = await tester(path.join(__dirname, "circuits", "constants_test.circom"));
  10. await circuit.loadConstraints();
  11. assert.equal(circuit.nVars, 2);
  12. assert.equal(circuit.constraints.length, 1);
  13. const witness = await circuit.calculateWitness({ "in": bigInt("d807aa98", 16)}, true);
  14. assert(witness[0].equals(bigInt(1)));
  15. assert(witness[1].equals(bigInt("d807aa98", 16)));
  16. });
  17. it("Should create a sum circuit", async () => {
  18. const circuit = await tester(path.join(__dirname, "circuits", "sum_test.circom"));
  19. await circuit.loadConstraints();
  20. assert.equal(circuit.constraints.length, 97); // 32 (in1) + 32(in2) + 32(out) + 1 (carry)
  21. const witness = await circuit.calculateWitness({ "a": "111", "b": "222" }, true);
  22. assert(witness[0].equals(bigInt(1)));
  23. assert(witness[1].equals(bigInt("333")));
  24. });
  25. });