circomlib/test/poseidoncontract.js

69 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2019-07-08 14:08:04 +02:00
const ganache = require("ganache-cli");
2019-06-04 13:40:15 +02:00
const Web3 = require("web3");
const chai = require("chai");
const poseidonGenContract = require("../src/poseidon_gencontract.js");
const Poseidon = require("../src/poseidon.js");
const assert = chai.assert;
const log = (msg) => { if (process.env.MOCHA_VERBOSE) console.log(msg); };
2020-02-25 05:41:51 -08:00
describe("Poseidon Smart contract test", function () {
2019-06-04 13:40:15 +02:00
let testrpc;
let web3;
2020-02-25 05:41:51 -08:00
let poseidon6;
let poseidon3;
2019-06-04 13:40:15 +02:00
let accounts;
2020-02-25 05:41:51 -08:00
this.timeout(100000);
2019-06-04 13:40:15 +02:00
before(async () => {
2019-07-08 14:08:04 +02:00
web3 = new Web3(ganache.provider(), null, { transactionConfirmationBlocks: 1 });
2019-06-04 13:40:15 +02:00
accounts = await web3.eth.getAccounts();
});
it("Should deploy the contract", async () => {
const C = new web3.eth.Contract(poseidonGenContract.abi);
2020-02-25 05:41:51 -08:00
poseidon6 = await C.deploy({
data: poseidonGenContract.createCode(6)
}).send({
gas: 2500000,
from: accounts[0]
});
poseidon3 = await C.deploy({
data: poseidonGenContract.createCode(3)
2019-06-04 13:40:15 +02:00
}).send({
gas: 2500000,
from: accounts[0]
});
});
2020-02-25 05:41:51 -08:00
it("Shold calculate the poseidon correctly t=6", async () => {
2019-06-04 13:40:15 +02:00
2020-02-25 05:41:51 -08:00
const res = await poseidon6.methods.poseidon([1,2]).call();
2019-06-04 13:40:15 +02:00
2019-06-04 17:32:28 +02:00
// console.log("Cir: " + bigInt(res.toString(16)).toString(16));
2019-06-04 13:40:15 +02:00
const hash = Poseidon.createHash(6, 8, 57);
const res2 = hash([1,2]);
2019-06-04 17:32:28 +02:00
// console.log("Ref: " + bigInt(res2).toString(16));
2019-06-04 13:40:15 +02:00
assert.equal(res.toString(), res2.toString());
});
2020-02-25 05:41:51 -08:00
it("Shold calculate the poseidon correctly t=3", async () => {
const res = await poseidon3.methods.poseidon([1,2]).call();
// console.log("Cir: " + bigInt(res.toString(16)).toString(16));
const hash = Poseidon.createHash(3, 8, 57);
const res2 = hash([1,2]);
// console.log("Ref: " + bigInt(res2).toString(16));
assert.equal(res.toString(), res2.toString());
});
2019-06-04 13:40:15 +02:00
});