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.

58 lines
1.7 KiB

  1. const path = require("path");
  2. const tester = require("circom").tester;
  3. const chai = require("chai");
  4. const assert = chai.assert;
  5. const circomlib = require("circomlib");
  6. const smt = require("circomlib").smt;
  7. export {};
  8. describe("withdraw test", function () {
  9. this.timeout(200000);
  10. it("Test Withdraw", async () => {
  11. const circuit = await tester(
  12. path.join(__dirname, "../../circuits", "withdraw.circom"),
  13. {reduceConstraints: false}
  14. );
  15. const nLevels = 17;
  16. const secret = "1234567890";
  17. const coinCode = "0";
  18. const amount = '1000000000000000000';
  19. const nullifier = "567891234";
  20. const poseidon = circomlib.poseidon.createHash(6, 8, 57);
  21. const commitment = poseidon([coinCode, amount, secret, nullifier]).toString();
  22. // add commitment into SMT
  23. let tree = await smt.newMemEmptyTrie();
  24. await tree.insert(1, 0);
  25. await tree.insert(2, commitment);
  26. await tree.insert(3, 0);
  27. console.log("root", tree.root);
  28. const res = await tree.find(2);
  29. assert(res.found);
  30. let siblings = res.siblings;
  31. while (siblings.length < nLevels) {
  32. siblings.push("0");
  33. };
  34. console.log("siblings", siblings);
  35. let root = tree.root;
  36. const witness = await circuit.calculateWitness({
  37. "coinCode": coinCode,
  38. "amount": amount,
  39. "secret": secret,
  40. "nullifier": nullifier,
  41. "siblings": siblings,
  42. "root": root,
  43. "address": "987654321",
  44. "key": 2
  45. });
  46. await circuit.checkConstraints(witness);
  47. });
  48. });