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.

77 lines
3.0 KiB

  1. const chai = require("chai");
  2. const path = require("path");
  3. const snarkjs = require("snarkjs");
  4. const crypto = require("crypto");
  5. const compiler = require("circom");
  6. const assert = chai.assert;
  7. describe("Sum test", () => {
  8. it("Should create a iszero circuit", async() => {
  9. const cirDef = await compiler(path.join(__dirname, "circuits", "iszero.circom"));
  10. const circuit = new snarkjs.Circuit(cirDef);
  11. let witness;
  12. witness = circuit.calculateWitness({ "in": 111});
  13. assert(witness[0].equals(snarkjs.bigInt(1)));
  14. assert(witness[1].equals(snarkjs.bigInt(0)));
  15. witness = circuit.calculateWitness({ "in": 0 });
  16. assert(witness[0].equals(snarkjs.bigInt(1)));
  17. assert(witness[1].equals(snarkjs.bigInt(1)));
  18. });
  19. it("Should create a isequal circuit", async() => {
  20. const cirDef = await compiler(path.join(__dirname, "circuits", "isequal.circom"));
  21. const circuit = new snarkjs.Circuit(cirDef);
  22. let witness;
  23. witness = circuit.calculateWitness({ "in[0]": "111", "in[1]": "222" });
  24. assert(witness[0].equals(snarkjs.bigInt(1)));
  25. assert(witness[1].equals(snarkjs.bigInt(0)));
  26. witness = circuit.calculateWitness({ "in[0]": "444", "in[1]": "444" });
  27. assert(witness[0].equals(snarkjs.bigInt(1)));
  28. assert(witness[1].equals(snarkjs.bigInt(1)));
  29. });
  30. it("Should create a comparison", async() => {
  31. const cirDef = await compiler(path.join(__dirname, "circuits", "lessthan.circom"));
  32. const circuit = new snarkjs.Circuit(cirDef);
  33. let witness;
  34. witness = circuit.calculateWitness({ "in[0]": "333", "in[1]": "444" });
  35. assert(witness[0].equals(snarkjs.bigInt(1)));
  36. assert(witness[1].equals(snarkjs.bigInt(1)));
  37. witness = circuit.calculateWitness({ "in[0]": "1", "in[1]": "1" });
  38. assert(witness[0].equals(snarkjs.bigInt(1)));
  39. assert(witness[1].equals(snarkjs.bigInt(0)));
  40. witness = circuit.calculateWitness({ "in[0]": "661", "in[1]": "660" });
  41. assert(witness[0].equals(snarkjs.bigInt(1)));
  42. assert(witness[1].equals(snarkjs.bigInt(0)));
  43. witness = circuit.calculateWitness({ "in[0]": "0", "in[1]": "1" });
  44. assert(witness[0].equals(snarkjs.bigInt(1)));
  45. assert(witness[1].equals(snarkjs.bigInt(1)));
  46. witness = circuit.calculateWitness({ "in[0]": "0", "in[1]": "444" });
  47. assert(witness[0].equals(snarkjs.bigInt(1)));
  48. assert(witness[1].equals(snarkjs.bigInt(1)));
  49. witness = circuit.calculateWitness({ "in[0]": "1", "in[1]": "0" });
  50. assert(witness[0].equals(snarkjs.bigInt(1)));
  51. assert(witness[1].equals(snarkjs.bigInt(0)));
  52. witness = circuit.calculateWitness({ "in[0]": "555", "in[1]": "0" });
  53. assert(witness[0].equals(snarkjs.bigInt(1)));
  54. assert(witness[1].equals(snarkjs.bigInt(0)));
  55. witness = circuit.calculateWitness({ "in[0]": "0", "in[1]": "0" });
  56. assert(witness[0].equals(snarkjs.bigInt(1)));
  57. assert(witness[1].equals(snarkjs.bigInt(0)));
  58. });
  59. });