arnaucube
arnaucube/circomlibPublic Self-hosted repository
circomlib/test/mimcspongecontract.js
test/mimcspongecontract.jsRaw
 1const TestRPC = 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        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, 220)
39        }).send({
40            gas: 3500000,
41            from: accounts[0]
42        });
43    });
44
45    it("Shold calculate the mimc correctly", async () => {
46        const res = await mimc.methods.MiMCSponge(1,2,3).call();
47        const res2 = await mimcjs.hash(1,2,3);
48
49        assert.equal(res.xL.toString(), res2.xL.toString());
50        assert.equal(res.xR.toString(), res2.xR.toString());
51    });
52});
53