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