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.

43 lines
1.2 KiB

  1. const ganache = require("ganache-cli");
  2. const Web3 = require("web3");
  3. const chai = require("chai");
  4. const mimcGenContract = require("../src/mimcsponge_gencontract.js");
  5. const mimcjs = require("../src/mimcsponge.js");
  6. const assert = chai.assert;
  7. const log = (msg) => { if (process.env.MOCHA_VERBOSE) console.log(msg); };
  8. const SEED = "mimcsponge";
  9. describe("MiMC Sponge Smart contract test", () => {
  10. let testrpc;
  11. let web3;
  12. let mimc;
  13. let accounts;
  14. before(async () => {
  15. web3 = new Web3(ganache.provider(), null, { transactionConfirmationBlocks: 1 });
  16. accounts = await web3.eth.getAccounts();
  17. });
  18. it("Should deploy the contract", async () => {
  19. const C = new web3.eth.Contract(mimcGenContract.abi);
  20. mimc = await C.deploy({
  21. data: mimcGenContract.createCode(SEED, 220)
  22. }).send({
  23. gas: 3500000,
  24. from: accounts[0]
  25. });
  26. });
  27. it("Shold calculate the mimc correctly", async () => {
  28. const res = await mimc.methods.MiMCSponge(1,2,3).call();
  29. const res2 = await mimcjs.hash(1,2,3);
  30. assert.equal(res.xL.toString(), res2.xL.toString());
  31. assert.equal(res.xR.toString(), res2.xR.toString());
  32. });
  33. });