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.

69 lines
2.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
  1. const ganache = require("ganache-cli");
  2. const Web3 = require("web3");
  3. const chai = require("chai");
  4. const poseidonGenContract = require("../src/poseidon_gencontract.js");
  5. const Poseidon = require("../src/poseidon.js");
  6. const bigInt = require("snarkjs").bigInt;
  7. const assert = chai.assert;
  8. const log = (msg) => { if (process.env.MOCHA_VERBOSE) console.log(msg); };
  9. describe("Poseidon Smart contract test", function () {
  10. let testrpc;
  11. let web3;
  12. let poseidon6;
  13. let poseidon3;
  14. let accounts;
  15. this.timeout(100000);
  16. before(async () => {
  17. web3 = new Web3(ganache.provider(), null, { transactionConfirmationBlocks: 1 });
  18. accounts = await web3.eth.getAccounts();
  19. });
  20. it("Should deploy the contract", async () => {
  21. const C = new web3.eth.Contract(poseidonGenContract.abi);
  22. poseidon6 = await C.deploy({
  23. data: poseidonGenContract.createCode(6)
  24. }).send({
  25. gas: 2500000,
  26. from: accounts[0]
  27. });
  28. poseidon3 = await C.deploy({
  29. data: poseidonGenContract.createCode(3)
  30. }).send({
  31. gas: 2500000,
  32. from: accounts[0]
  33. });
  34. });
  35. it("Shold calculate the poseidon correctly t=6", async () => {
  36. const res = await poseidon6.methods.poseidon([1,2]).call();
  37. // console.log("Cir: " + bigInt(res.toString(16)).toString(16));
  38. const hash = Poseidon.createHash(6, 8, 57);
  39. const res2 = hash([1,2]);
  40. // console.log("Ref: " + bigInt(res2).toString(16));
  41. assert.equal(res.toString(), res2.toString());
  42. });
  43. it("Shold calculate the poseidon correctly t=3", async () => {
  44. const res = await poseidon3.methods.poseidon([1,2]).call();
  45. // console.log("Cir: " + bigInt(res.toString(16)).toString(16));
  46. const hash = Poseidon.createHash(3, 8, 57);
  47. const res2 = hash([1,2]);
  48. // console.log("Ref: " + bigInt(res2).toString(16));
  49. assert.equal(res.toString(), res2.toString());
  50. });
  51. });