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.

53 lines
1.4 KiB

  1. const TestRPC = 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. 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, 220)
  29. }).send({
  30. gas: 3500000,
  31. from: accounts[0]
  32. });
  33. });
  34. it("Shold calculate the mimc correctly", async () => {
  35. const res = await mimc.methods.MiMCSponge(1,2,3).call();
  36. const res2 = await mimcjs.hash(1,2,3);
  37. assert.equal(res.xL.toString(), res2.xL.toString());
  38. assert.equal(res.xR.toString(), res2.xR.toString());
  39. });
  40. });