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.

184 lines
7.0 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  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("Sum test", function () {
  7. this.timeout(100000);
  8. it("Should create a iszero circuit", async() => {
  9. const circuit = await tester(path.join(__dirname, "circuits", "iszero.circom"));
  10. let witness;
  11. witness = await circuit.calculateWitness({ "in": 111});
  12. assert(witness[0].equals(bigInt(1)));
  13. assert(witness[1].equals(bigInt(0)));
  14. witness = await circuit.calculateWitness({ "in": 0 });
  15. assert(witness[0].equals(bigInt(1)));
  16. assert(witness[1].equals(bigInt(1)));
  17. });
  18. it("Should create a isequal circuit", async() => {
  19. const circuit = await tester(path.join(__dirname, "circuits", "isequal.circom"));
  20. let witness;
  21. witness = await circuit.calculateWitness({ "in": [111,222] });
  22. assert(witness[0].equals(bigInt(1)));
  23. assert(witness[1].equals(bigInt(0)));
  24. witness = await circuit.calculateWitness({ "in": [444,444] });
  25. assert(witness[0].equals(bigInt(1)));
  26. assert(witness[1].equals(bigInt(1)));
  27. });
  28. it("Should create a comparison lessthan", async() => {
  29. const circuit = await tester(path.join(__dirname, "circuits", "lessthan.circom"));
  30. let witness;
  31. witness = await circuit.calculateWitness({ "in": [333,444] });
  32. assert(witness[0].equals(bigInt(1)));
  33. assert(witness[1].equals(bigInt(1)));
  34. witness = await circuit.calculateWitness({ "in":[1,1] });
  35. assert(witness[0].equals(bigInt(1)));
  36. assert(witness[1].equals(bigInt(0)));
  37. witness = await circuit.calculateWitness({ "in": [661, 660] });
  38. assert(witness[0].equals(bigInt(1)));
  39. assert(witness[1].equals(bigInt(0)));
  40. witness = await circuit.calculateWitness({ "in": [0, 1] });
  41. assert(witness[0].equals(bigInt(1)));
  42. assert(witness[1].equals(bigInt(1)));
  43. witness = await circuit.calculateWitness({ "in": [0, 444] });
  44. assert(witness[0].equals(bigInt(1)));
  45. assert(witness[1].equals(bigInt(1)));
  46. witness = await circuit.calculateWitness({ "in": [1, 0] });
  47. assert(witness[0].equals(bigInt(1)));
  48. assert(witness[1].equals(bigInt(0)));
  49. witness = await circuit.calculateWitness({ "in": [555, 0] });
  50. assert(witness[0].equals(bigInt(1)));
  51. assert(witness[1].equals(bigInt(0)));
  52. witness = await circuit.calculateWitness({ "in": [0, 0] });
  53. assert(witness[0].equals(bigInt(1)));
  54. assert(witness[1].equals(bigInt(0)));
  55. });
  56. it("Should create a comparison lesseqthan", async() => {
  57. const circuit = await tester(path.join(__dirname, "circuits", "lesseqthan.circom"));
  58. let witness;
  59. witness = await circuit.calculateWitness({ "in": [333,444] });
  60. assert(witness[0].equals(bigInt(1)));
  61. assert(witness[1].equals(bigInt(1)));
  62. witness = await circuit.calculateWitness({ "in":[1,1] });
  63. assert(witness[0].equals(bigInt(1)));
  64. assert(witness[1].equals(bigInt(1)));
  65. witness = await circuit.calculateWitness({ "in": [661, 660] });
  66. assert(witness[0].equals(bigInt(1)));
  67. assert(witness[1].equals(bigInt(0)));
  68. witness = await circuit.calculateWitness({ "in": [0, 1] });
  69. assert(witness[0].equals(bigInt(1)));
  70. assert(witness[1].equals(bigInt(1)));
  71. witness = await circuit.calculateWitness({ "in": [0, 444] });
  72. assert(witness[0].equals(bigInt(1)));
  73. assert(witness[1].equals(bigInt(1)));
  74. witness = await circuit.calculateWitness({ "in": [1, 0] });
  75. assert(witness[0].equals(bigInt(1)));
  76. assert(witness[1].equals(bigInt(0)));
  77. witness = await circuit.calculateWitness({ "in": [555, 0] });
  78. assert(witness[0].equals(bigInt(1)));
  79. assert(witness[1].equals(bigInt(0)));
  80. witness = await circuit.calculateWitness({ "in": [0, 0] });
  81. assert(witness[0].equals(bigInt(1)));
  82. assert(witness[1].equals(bigInt(1)));
  83. });
  84. it("Should create a comparison greaterthan", async() => {
  85. const circuit = await tester(path.join(__dirname, "circuits", "greaterthan.circom"));
  86. let witness;
  87. witness = await circuit.calculateWitness({ "in": [333,444] });
  88. assert(witness[0].equals(bigInt(1)));
  89. assert(witness[1].equals(bigInt(0)));
  90. witness = await circuit.calculateWitness({ "in":[1,1] });
  91. assert(witness[0].equals(bigInt(1)));
  92. assert(witness[1].equals(bigInt(0)));
  93. witness = await circuit.calculateWitness({ "in": [661, 660] });
  94. assert(witness[0].equals(bigInt(1)));
  95. assert(witness[1].equals(bigInt(1)));
  96. witness = await circuit.calculateWitness({ "in": [0, 1] });
  97. assert(witness[0].equals(bigInt(1)));
  98. assert(witness[1].equals(bigInt(0)));
  99. witness = await circuit.calculateWitness({ "in": [0, 444] });
  100. assert(witness[0].equals(bigInt(1)));
  101. assert(witness[1].equals(bigInt(0)));
  102. witness = await circuit.calculateWitness({ "in": [1, 0] });
  103. assert(witness[0].equals(bigInt(1)));
  104. assert(witness[1].equals(bigInt(1)));
  105. witness = await circuit.calculateWitness({ "in": [555, 0] });
  106. assert(witness[0].equals(bigInt(1)));
  107. assert(witness[1].equals(bigInt(1)));
  108. witness = await circuit.calculateWitness({ "in": [0, 0] });
  109. assert(witness[0].equals(bigInt(1)));
  110. assert(witness[1].equals(bigInt(0)));
  111. });
  112. it("Should create a comparison greatereqthan", async() => {
  113. const circuit = await tester(path.join(__dirname, "circuits", "greatereqthan.circom"));
  114. let witness;
  115. witness = await circuit.calculateWitness({ "in": [333,444] });
  116. assert(witness[0].equals(bigInt(1)));
  117. assert(witness[1].equals(bigInt(0)));
  118. witness = await circuit.calculateWitness({ "in":[1,1] });
  119. assert(witness[0].equals(bigInt(1)));
  120. assert(witness[1].equals(bigInt(1)));
  121. witness = await circuit.calculateWitness({ "in": [661, 660] });
  122. assert(witness[0].equals(bigInt(1)));
  123. assert(witness[1].equals(bigInt(1)));
  124. witness = await circuit.calculateWitness({ "in": [0, 1] });
  125. assert(witness[0].equals(bigInt(1)));
  126. assert(witness[1].equals(bigInt(0)));
  127. witness = await circuit.calculateWitness({ "in": [0, 444] });
  128. assert(witness[0].equals(bigInt(1)));
  129. assert(witness[1].equals(bigInt(0)));
  130. witness = await circuit.calculateWitness({ "in": [1, 0] });
  131. assert(witness[0].equals(bigInt(1)));
  132. assert(witness[1].equals(bigInt(1)));
  133. witness = await circuit.calculateWitness({ "in": [555, 0] });
  134. assert(witness[0].equals(bigInt(1)));
  135. assert(witness[1].equals(bigInt(1)));
  136. witness = await circuit.calculateWitness({ "in": [0, 0] });
  137. assert(witness[0].equals(bigInt(1)));
  138. assert(witness[1].equals(bigInt(1)));
  139. });
  140. });