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.

61 lines
1.7 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
  1. const path = require("path");
  2. const Scalar = require("ffjavascript").Scalar;
  3. const F1Field = require("ffjavascript").F1Field;
  4. const c_tester = require("../index.js").c_tester;
  5. const wasm_tester = require("../index.js").wasm_tester;
  6. const __P__ = Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");
  7. const Fr = new F1Field(__P__);
  8. const basicCases = require("./basiccases.json");
  9. function normalize(o) {
  10. if ((typeof(o) == "bigint") || o.isZero !== undefined) {
  11. return Fr.e(o);
  12. } else if (Array.isArray(o)) {
  13. return o.map(normalize);
  14. } else if (typeof o == "object") {
  15. const res = {};
  16. for (let k in o) {
  17. res[k] = normalize(o[k]);
  18. }
  19. return res;
  20. } else {
  21. return Fr.e(o);
  22. }
  23. }
  24. async function doTest(tester, circuit, testVectors) {
  25. const cir = await tester(path.join(__dirname, "circuits", circuit));
  26. for (let i=0; i<testVectors.length; i++) {
  27. const w = await cir.calculateWitness(normalize(testVectors[i][0]));
  28. // console.log(testVectors[i][0]);
  29. // console.log(w);
  30. // console.log(testVectors[i][1]);
  31. await cir.assertOut(w, normalize(testVectors[i][1]) );
  32. }
  33. await cir.release();
  34. }
  35. describe("basic cases", function () {
  36. this.timeout(100000);
  37. for (let i=0; i< basicCases.length; i++) {
  38. it("c/c++ " + basicCases[i].name, async () => {
  39. await doTest(c_tester, basicCases[i].circuit, basicCases[i].tv);
  40. });
  41. }
  42. for (let i=0; i<basicCases.length; i++) {
  43. it("wasm " + basicCases[i].name, async () => {
  44. await doTest(wasm_tester, basicCases[i].circuit, basicCases[i].tv);
  45. });
  46. }
  47. });