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.

52 lines
1.3 KiB

  1. const TestRPC = 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", () => {
  10. let testrpc;
  11. let web3;
  12. let mimc;
  13. let accounts;
  14. before(async () => {
  15. testrpc = TestRPC.server({
  16. ws: true,
  17. gasLimit: 5800000,
  18. total_accounts: 10,
  19. });
  20. testrpc.listen(8546, "127.0.0.1");
  21. web3 = new Web3("ws://127.0.0.1:8546");
  22. accounts = await web3.eth.getAccounts();
  23. });
  24. after(async () => testrpc.close());
  25. it("Should deploy the contract", async () => {
  26. const C = new web3.eth.Contract(mimcGenContract.abi);
  27. mimc = await C.deploy({
  28. data: mimcGenContract.createCode(SEED, 91)
  29. }).send({
  30. gas: 1500000,
  31. from: accounts[0]
  32. });
  33. });
  34. it("Shold calculate the mimic correctly", async () => {
  35. const res = await mimc.methods.MiMCpe7(1,2).call();
  36. const res2 = await mimcjs.hash(1,2,91);
  37. assert.equal(res.toString(), res2.toString());
  38. });
  39. });