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.

48 lines
1.3 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. const ganache = require("ganache-cli");
  2. const Web3 = require("web3");
  3. const chai = require("chai");
  4. const mimcGenContract = require("../src/mimc_gencontract.js");
  5. const mimcjs = require("../src/mimc7.js");
  6. const assert = chai.assert;
  7. const log = (msg) => { if (process.env.MOCHA_VERBOSE) console.log(msg); };
  8. const SEED = "mimc";
  9. describe("MiMC Smart contract test", function () {
  10. let testrpc;
  11. let web3;
  12. let mimc;
  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(mimcGenContract.abi);
  21. mimc = await C.deploy({
  22. data: mimcGenContract.createCode(SEED, 91),
  23. arguments: []
  24. }).send({
  25. gas: 1500000,
  26. gasPrice: '30000000000000',
  27. from: accounts[0]
  28. }).on("error", (error) => {
  29. console.log("ERROR: "+error);
  30. });
  31. });
  32. it("Shold calculate the mimic correctly", async () => {
  33. const res = await mimc.methods.MiMCpe7(1,2).call();
  34. const res2 = await mimcjs.hash(1,2,91);
  35. assert.equal(res.toString(), res2.toString());
  36. });
  37. });