circomlib/test/poseidoncontract.js

68 lines
2.0 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");
2019-06-04 14:40:15 +03:00
const assert = chai.assert;
const log = (msg) => { if (process.env.MOCHA_VERBOSE) console.log(msg); };
describe("Poseidon Smart contract test", function () {
2019-06-04 14:40:15 +03:00
let testrpc;
let web3;
let poseidon2;
let poseidon4;
2019-06-04 14:40:15 +03:00
let accounts;
this.timeout(100000);
let C2;
let C4;
2019-06-04 14:40:15 +03:00
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 () => {
C2 = new web3.eth.Contract(poseidonGenContract.generateABI(2));
poseidon2 = await C2.deploy({
data: poseidonGenContract.createCode(2)
}).send({
2020-08-10 13:07:22 +03:00
gas: 5000000,
from: accounts[0]
});
C4 = new web3.eth.Contract(poseidonGenContract.generateABI(4));
poseidon4 = await C4.deploy({
data: poseidonGenContract.createCode(4)
2019-06-04 14:40:15 +03:00
}).send({
2020-08-10 13:07:22 +03:00
gas: 5000000,
2019-06-04 14:40:15 +03:00
from: accounts[0]
});
});
it("Should calculate the poseidon correctly for 2 inputs", async () => {
const res = await poseidon2.methods.poseidon([1, 2]).call();
2019-06-04 14:40:15 +03:00
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 res2 = poseidon([1, 2]);
// console.log("Ref: " + bigInt(res2).toString(16));
2019-06-04 14:40:15 +03:00
assert.equal(res.toString(), res2.toString());
});
it("Should calculate the poseidon correctly for 4 inputs", async () => {
const res = await poseidon4.methods.poseidon([1, 2, 3, 4]).call();
// console.log("Cir: " + bigInt(res.toString(16)).toString(16));
const res2 = poseidon([1, 2, 3, 4]);
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());
});
2019-06-04 14:40:15 +03:00
});