circomlib/test/poseidoncontract.js
test/poseidoncontract.jsRaw
1const ganache = require("ganache-cli");
2const Web3 = require("web3");
3const chai = require("chai");
4const poseidonGenContract = require("../src/poseidon_gencontract.js");
5const Poseidon = require("../src/poseidon.js");
6const bigInt = require("snarkjs").bigInt;
7
8const assert = chai.assert;
9const log = (msg) => { if (process.env.MOCHA_VERBOSE) console.log(msg); };
10
11const SEED = "mimc";
12
13describe("Poseidon 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(poseidonGenContract.abi);
26
27 mimc = await C.deploy({
28 data: poseidonGenContract.createCode()
29 }).send({
30 gas: 2500000,
31 from: accounts[0]
32 });
33 });
34
35 it("Shold calculate the mimic correctly", async () => {
36
37 const res = await mimc.methods.poseidon([1,2]).call();
38
39 // console.log("Cir: " + bigInt(res.toString(16)).toString(16));
40
41 const hash = Poseidon.createHash(6, 8, 57);
42
43 const res2 = hash([1,2]);
44 // console.log("Ref: " + bigInt(res2).toString(16));
45
46 assert.equal(res.toString(), res2.toString());
47 });
48});
49