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.

64 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
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(5)
  23. }).send({
  24. gas: 5000000,
  25. from: accounts[0]
  26. });
  27. poseidon3 = await C.deploy({
  28. data: poseidonGenContract.createCode(2)
  29. }).send({
  30. gas: 5000000,
  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, 0, 0, 0]).call();
  36. // console.log("Cir: " + bigInt(res.toString(16)).toString(16));
  37. const res2 = poseidon([1,2, 0, 0, 0]);
  38. // console.log("Ref: " + bigInt(res2).toString(16));
  39. assert.equal(res.toString(), res2.toString());
  40. });
  41. it("Shold calculate the poseidon correctly t=3", async () => {
  42. const res = await poseidon3.methods.poseidon([1,2]).call();
  43. // console.log("Cir: " + bigInt(res.toString(16)).toString(16));
  44. const res2 = poseidon([1,2]);
  45. // console.log("Ref: " + bigInt(res2).toString(16));
  46. assert.equal(res.toString(), res2.toString());
  47. });
  48. });