circomlib/test/mimccontract.js

49 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2019-07-08 15:08:04 +03:00
const ganache = require("ganache-cli");
2018-12-06 19:32:49 +03:00
const Web3 = require("web3");
const chai = require("chai");
const mimcGenContract = require("../src/mimc_gencontract.js");
const mimcjs = require("../src/mimc7.js");
const assert = chai.assert;
const log = (msg) => { if (process.env.MOCHA_VERBOSE) console.log(msg); };
2018-12-16 10:05:20 +03:00
const SEED = "mimc";
2018-12-06 19:32:49 +03:00
2019-07-08 15:08:04 +03:00
describe("MiMC Smart contract test", function () {
2018-12-06 19:32:49 +03:00
let testrpc;
let web3;
let mimc;
let accounts;
2019-07-08 15:08:04 +03:00
this.timeout(100000);
2018-12-06 19:32:49 +03:00
2019-07-08 15:08:04 +03:00
before(async () => {
web3 = new Web3(ganache.provider(), null, { transactionConfirmationBlocks: 1 });
2018-12-06 19:32:49 +03:00
accounts = await web3.eth.getAccounts();
});
it("Should deploy the contract", async () => {
const C = new web3.eth.Contract(mimcGenContract.abi);
mimc = await C.deploy({
2019-07-08 15:08:04 +03:00
data: mimcGenContract.createCode(SEED, 91),
arguments: []
2018-12-06 19:32:49 +03:00
}).send({
gas: 1500000,
2019-07-08 15:08:04 +03:00
gasPrice: '30000000000000',
2018-12-06 19:32:49 +03:00
from: accounts[0]
2019-07-08 15:08:04 +03:00
}).on("error", (error) => {
console.log("ERROR: "+error);
2018-12-06 19:32:49 +03:00
});
});
it("Shold calculate the mimic correctly", async () => {
const res = await mimc.methods.MiMCpe7(1,2).call();
const res2 = await mimcjs.hash(1,2,91);
assert.equal(res.toString(), res2.toString());
});
});