circomlib/test/mimccontract.js
test/mimccontract.jsRaw
1const ganache = require("ganache-cli");
2const Web3 = require("web3");
3const chai = require("chai");
4const mimcGenContract = require("../src/mimc_gencontract.js");
5const mimcjs = require("../src/mimc7.js");
6
7
8const assert = chai.assert;
9const log = (msg) => { if (process.env.MOCHA_VERBOSE) console.log(msg); };
10
11const SEED = "mimc";
12
13describe("MiMC Smart contract test", function () {
14 let testrpc;
15 let web3;
16 let mimc;
17 let accounts;
18
19 this.timeout(100000);
20
21 before(async () => {
22 web3 = new Web3(ganache.provider(), null, { transactionConfirmationBlocks: 1 });
23 accounts = await web3.eth.getAccounts();
24 });
25
26 it("Should deploy the contract", async () => {
27 const C = new web3.eth.Contract(mimcGenContract.abi);
28
29 mimc = await C.deploy({
30 data: mimcGenContract.createCode(SEED, 91),
31 arguments: []
32 }).send({
33 gas: 1500000,
34 gasPrice: '30000000000000',
35 from: accounts[0]
36 }).on("error", (error) => {
37 console.log("ERROR: "+error);
38 });
39 });
40
41 it("Shold calculate the mimic correctly", async () => {
42 const res = await mimc.methods.MiMCpe7(1,2).call();
43 const res2 = await mimcjs.hash(1,2,91);
44
45 assert.equal(res.toString(), res2.toString());
46 });
47});
48