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.

65 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
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 C6 = new web3.eth.Contract(poseidonGenContract.generateABI(5));
  21. const C3 = new web3.eth.Contract(poseidonGenContract.generateABI(2));
  22. poseidon6 = await C6.deploy({
  23. data: poseidonGenContract.createCode(5)
  24. }).send({
  25. gas: 5000000,
  26. from: accounts[0]
  27. });
  28. poseidon3 = await C3.deploy({
  29. data: poseidonGenContract.createCode(2)
  30. }).send({
  31. gas: 5000000,
  32. from: accounts[0]
  33. });
  34. });
  35. it("Should calculate the poseidon correctly t=6", async () => {
  36. const res = await poseidon6.methods.poseidon([1,2, 0, 0, 0]).call();
  37. // console.log("Cir: " + bigInt(res.toString(16)).toString(16));
  38. const res2 = poseidon([1,2, 0, 0, 0]);
  39. // console.log("Ref: " + bigInt(res2).toString(16));
  40. assert.equal(res.toString(), res2.toString());
  41. });
  42. it("Should 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 res2 = poseidon([1,2]);
  46. // console.log("Ref: " + bigInt(res2).toString(16));
  47. assert.equal(res.toString(), res2.toString());
  48. });
  49. });