arnaucube
arnaucube/circomlibPublic Self-hosted repository
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");
 6
 7const assert = chai.assert;
 8const log = (msg) => { if (process.env.MOCHA_VERBOSE) console.log(msg); };
 9
10describe("Poseidon Smart contract test", function () {
11    let testrpc;
12    let web3;
13    let poseidon6;
14    let poseidon3;
15    let accounts;
16    this.timeout(100000);
17
18    before(async () => {
19        web3 = new Web3(ganache.provider(), null, { transactionConfirmationBlocks: 1 });
20        accounts = await web3.eth.getAccounts();
21    });
22
23    it("Should deploy the contract", async () => {
24        const C = new web3.eth.Contract(poseidonGenContract.abi);
25
26        poseidon6 = await C.deploy({
27            data: poseidonGenContract.createCode(5)
28        }).send({
29            gas: 5000000,
30            from: accounts[0]
31        });
32        poseidon3 = await C.deploy({
33            data: poseidonGenContract.createCode(2)
34        }).send({
35            gas: 5000000,
36            from: accounts[0]
37        });
38    });
39
40    it("Shold calculate the poseidon correctly t=6", async () => {
41
42        const res = await poseidon6.methods.poseidon([1,2, 0, 0, 0]).call();
43
44        // console.log("Cir: " + bigInt(res.toString(16)).toString(16));
45
46        const res2 = poseidon([1,2, 0, 0, 0]);
47        // console.log("Ref: " + bigInt(res2).toString(16));
48
49        assert.equal(res.toString(), res2.toString());
50    });
51    it("Shold calculate the poseidon correctly t=3", async () => {
52
53        const res = await poseidon3.methods.poseidon([1,2]).call();
54
55        // console.log("Cir: " + bigInt(res.toString(16)).toString(16));
56
57        const res2 = poseidon([1,2]);
58        // console.log("Ref: " + bigInt(res2).toString(16));
59
60        assert.equal(res.toString(), res2.toString());
61    });
62
63});
64