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.

98 lines
2.6 KiB

6 years ago
6 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 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
6 years ago
  1. const path = require("path");
  2. const bigInt = require("big-integer");
  3. const tester = require("circom").tester;
  4. describe("Mux4 test", function() {
  5. this.timeout(100000);
  6. it("Should create a constant multiplexer 4", async () => {
  7. const circuit = await tester(path.join(__dirname, "circuits", "mux4_1.circom"));
  8. const ct16 = [
  9. bigInt("123"),
  10. bigInt("456"),
  11. bigInt("789"),
  12. bigInt("012"),
  13. bigInt("111"),
  14. bigInt("222"),
  15. bigInt("333"),
  16. bigInt("4546"),
  17. bigInt("134523"),
  18. bigInt("44356"),
  19. bigInt("15623"),
  20. bigInt("4566"),
  21. bigInt("1223"),
  22. bigInt("4546"),
  23. bigInt("4256"),
  24. bigInt("4456")
  25. ];
  26. for (let i=0; i<16; i++) {
  27. const w = await circuit.calculateWitness({ "selector": i });
  28. await circuit.checkConstraints(w);
  29. await circuit.assertOut(w, {out: ct16[i]});
  30. }
  31. });
  32. it("Should create a constant multiplexer 3", async () => {
  33. const circuit = await tester(path.join(__dirname, "circuits", "mux3_1.circom"));
  34. const ct8 = [
  35. bigInt("37"),
  36. bigInt("47"),
  37. bigInt("53"),
  38. bigInt("71"),
  39. bigInt("89"),
  40. bigInt("107"),
  41. bigInt("163"),
  42. bigInt("191")
  43. ];
  44. for (let i=0; i<8; i++) {
  45. const w = await circuit.calculateWitness({ "selector": i });
  46. await circuit.checkConstraints(w);
  47. await circuit.assertOut(w, {out: ct8[i]});
  48. }
  49. });
  50. it("Should create a constant multiplexer 2", async () => {
  51. const circuit = await tester(path.join(__dirname, "circuits", "mux2_1.circom"));
  52. const ct4 = [
  53. bigInt("37"),
  54. bigInt("47"),
  55. bigInt("53"),
  56. bigInt("71"),
  57. ];
  58. for (let i=0; i<4; i++) {
  59. const w = await circuit.calculateWitness({ "selector": i });
  60. await circuit.checkConstraints(w);
  61. await circuit.assertOut(w, {out: ct4[i]});
  62. }
  63. });
  64. it("Should create a constant multiplexer 1", async () => {
  65. const circuit = await tester(path.join(__dirname, "circuits", "mux1_1.circom"));
  66. const ct2 = [
  67. bigInt("37"),
  68. bigInt("47"),
  69. ];
  70. for (let i=0; i<2; i++) {
  71. const w = await circuit.calculateWitness({ "selector": i });
  72. await circuit.checkConstraints(w);
  73. await circuit.assertOut(w, {out: ct2[i]});
  74. }
  75. });
  76. });