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(6)
28        }).send({
29            gas: 2500000,
30            from: accounts[0]
31        });
32        poseidon3 = await C.deploy({
33            data: poseidonGenContract.createCode(3)
34        }).send({
35            gas: 2500000,
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]).call();
43
44        // console.log("Cir: " + bigInt(res.toString(16)).toString(16));
45
46        const hash = Poseidon.createHash(6, 8, 57);
47
48        const res2 = hash([1,2]);
49        // console.log("Ref: " + bigInt(res2).toString(16));
50
51        assert.equal(res.toString(), res2.toString());
52    });
53    it("Shold calculate the poseidon correctly t=3", async () => {
54
55        const res = await poseidon3.methods.poseidon([1,2]).call();
56
57        // console.log("Cir: " + bigInt(res.toString(16)).toString(16));
58
59        const hash = Poseidon.createHash(3, 8, 57);
60
61        const res2 = hash([1,2]);
62        // console.log("Ref: " + bigInt(res2).toString(16));
63
64        assert.equal(res.toString(), res2.toString());
65    });
66
67});
68