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