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.

49 lines
1.4 KiB

4 years ago
5 years ago
4 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. const SEED = "mimc";
  10. describe("Poseidon Smart contract test", () => {
  11. let testrpc;
  12. let web3;
  13. let mimc;
  14. let accounts;
  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. mimc = await C.deploy({
  22. data: poseidonGenContract.createCode()
  23. }).send({
  24. gas: 2500000,
  25. from: accounts[0]
  26. });
  27. });
  28. it("Shold calculate the mimic correctly", async () => {
  29. const res = await mimc.methods.poseidon([1,2]).call();
  30. // console.log("Cir: " + bigInt(res.toString(16)).toString(16));
  31. const hash = Poseidon.createHash(6, 8, 57);
  32. const res2 = hash([1,2]);
  33. // console.log("Ref: " + bigInt(res2).toString(16));
  34. assert.equal(res.toString(), res2.toString());
  35. });
  36. });