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.

100 lines
2.7 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. const path = require("path");
  2. const bigInt = require("big-integer");
  3. const c_tester = require("../index.js").c_tester;
  4. const __P__ = new bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
  5. async function doTest(circuit, testVectors) {
  6. const cir = await c_tester(path.join(__dirname, "circuits", circuit));
  7. for (let i=0; i<testVectors.length; i++) {
  8. const w = await cir.calculateWitness(testVectors[i][0]);
  9. await cir.assertOut(w, testVectors[i][1] );
  10. }
  11. await cir.release();
  12. }
  13. describe("basic cases", function () {
  14. this.timeout(100000);
  15. it("inout", async () => {
  16. await doTest(
  17. "inout.circom",
  18. [
  19. [{in1: 1, in2: [2,3], in3:[[4,5], [6,7], [8,9]]}, {out1: 1, out2: [2,3], out3: [[4,5], [6,7],[8,9]]}],
  20. ]
  21. );
  22. });
  23. it("add", async () => {
  24. await doTest(
  25. "add.circom",
  26. [
  27. [{in: [0,0]}, {out: 0}],
  28. [{in: [0,1]}, {out: 1}],
  29. [{in: [1,2]}, {out: 3}],
  30. [{in: [__P__.minus(1),1]}, {out: 0}],
  31. ]
  32. );
  33. });
  34. it("add constant", async () => {
  35. await doTest(
  36. "addconst1.circom",
  37. [
  38. [{in: 0}, {out: 15}],
  39. [{in: 10}, {out: 25}],
  40. [{in: __P__.minus(2)}, {out: 13}],
  41. ]
  42. );
  43. });
  44. it("for unrolled", async () => {
  45. await doTest(
  46. "forunrolled.circom",
  47. [
  48. [{in: 0}, {out: [0,1,2]}],
  49. [{in: 10}, {out: [10, 11, 12]}],
  50. [{in: __P__.minus(2)}, {out: [__P__.minus(2), __P__.minus(1), 0]}],
  51. ]
  52. );
  53. });
  54. it("for rolled", async () => {
  55. await doTest(
  56. "forrolled.circom",
  57. [
  58. [{in: 0}, {out: 0}],
  59. [{in: 10}, {out: 10}],
  60. ]
  61. );
  62. });
  63. it("function1", async () => {
  64. await doTest(
  65. "function1.circom",
  66. [
  67. [{in: 0}, {out: 3}],
  68. [{in: 10}, {out: 13}],
  69. [{in: __P__.minus(2)}, {out: 1}],
  70. ]
  71. );
  72. });
  73. it("function2", async () => {
  74. await doTest(
  75. "function2.circom",
  76. [
  77. [{in: 0}, {out: 3}],
  78. [{in: 10}, {out: 13}],
  79. [{in: __P__.minus(2)}, {out: 1}],
  80. ]
  81. );
  82. });
  83. it("constants1", async () => {
  84. await doTest(
  85. "constants1.circom",
  86. [
  87. [{in: 0}, {out: 42}],
  88. [{in: 10}, {out: 52}],
  89. [{in: __P__.minus(2)}, {out: 40}],
  90. ]
  91. );
  92. });
  93. });