circomlib/test/poseidoncontract.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-07-08 15:08:04 +03:00
const ganache = require("ganache-cli");
2019-06-04 14:40:15 +03:00
const Web3 = require("web3");
const chai = require("chai");
const poseidonGenContract = require("../src/poseidon_gencontract.js");
const Poseidon = require("../src/poseidon.js");
const bigInt = require("snarkjs").bigInt;
const assert = chai.assert;
const log = (msg) => { if (process.env.MOCHA_VERBOSE) console.log(msg); };
const SEED = "mimc";
describe("Poseidon Smart contract test", () => {
let testrpc;
let web3;
let mimc;
let accounts;
before(async () => {
2019-07-08 15:08:04 +03:00
web3 = new Web3(ganache.provider(), null, { transactionConfirmationBlocks: 1 });
2019-06-04 14:40:15 +03:00
accounts = await web3.eth.getAccounts();
});
it("Should deploy the contract", async () => {
const C = new web3.eth.Contract(poseidonGenContract.abi);
mimc = await C.deploy({
data: poseidonGenContract.createCode()
}).send({
gas: 2500000,
from: accounts[0]
});
});
it("Shold calculate the mimic correctly", async () => {
const res = await mimc.methods.poseidon([1,2]).call();
2019-06-04 18:32:28 +03:00
// console.log("Cir: " + bigInt(res.toString(16)).toString(16));
2019-06-04 14:40:15 +03:00
const hash = Poseidon.createHash(6, 8, 57);
const res2 = hash([1,2]);
2019-06-04 18:32:28 +03:00
// console.log("Ref: " + bigInt(res2).toString(16));
2019-06-04 14:40:15 +03:00
assert.equal(res.toString(), res2.toString());
});
});