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