circomlib/test/poseidoncontract.js
test/poseidoncontract.jsRaw
1const TestRPC = 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 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(poseidonGenContract.abi);
36
37 mimc = await C.deploy({
38 data: poseidonGenContract.createCode()
39 }).send({
40 gas: 2500000,
41 from: accounts[0]
42 });
43 });
44
45 it("Shold calculate the mimic correctly", async () => {
46
47 const res = await mimc.methods.poseidon([1,2]).call();
48
49 console.log("Cir: " + bigInt(res.toString(16)).toString(16));
50
51 const hash = Poseidon.createHash(6, 8, 57);
52
53 const res2 = hash([1,2]);
54 console.log("Ref: " + bigInt(res2).toString(16));
55
56 assert.equal(res.toString(), res2.toString());
57 });
58});
59