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.

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