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 18:13:04 +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-02-25 16:41:51 +03:00
|
|
|
describe("Poseidon Smart contract test", function () {
|
2019-06-04 14:40:15 +03:00
|
|
|
let testrpc;
|
|
|
|
let web3;
|
2020-02-25 16:41:51 +03:00
|
|
|
let poseidon6;
|
|
|
|
let poseidon3;
|
2019-06-04 14:40:15 +03:00
|
|
|
let accounts;
|
2020-02-25 16:41:51 +03:00
|
|
|
this.timeout(100000);
|
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 () => {
|
|
|
|
const C = new web3.eth.Contract(poseidonGenContract.abi);
|
|
|
|
|
2020-02-25 16:41:51 +03:00
|
|
|
poseidon6 = await C.deploy({
|
2020-08-09 18:13:04 +03:00
|
|
|
data: poseidonGenContract.createCode(5)
|
2020-02-25 16:41:51 +03:00
|
|
|
}).send({
|
2020-08-09 18:13:04 +03:00
|
|
|
gas: 5000000,
|
2020-02-25 16:41:51 +03:00
|
|
|
from: accounts[0]
|
|
|
|
});
|
|
|
|
poseidon3 = await C.deploy({
|
2020-08-09 18:13:04 +03:00
|
|
|
data: poseidonGenContract.createCode(2)
|
2019-06-04 14:40:15 +03:00
|
|
|
}).send({
|
2020-08-09 18:13:04 +03:00
|
|
|
gas: 5000000,
|
2019-06-04 14:40:15 +03:00
|
|
|
from: accounts[0]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-02-25 16:41:51 +03:00
|
|
|
it("Shold calculate the poseidon correctly t=6", async () => {
|
2019-06-04 14:40:15 +03:00
|
|
|
|
2020-08-09 18:13:04 +03:00
|
|
|
const res = await poseidon6.methods.poseidon([1,2, 0, 0, 0]).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 18:13:04 +03:00
|
|
|
const res2 = poseidon([1,2, 0, 0, 0]);
|
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-02-25 16:41:51 +03: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));
|
|
|
|
|
2020-08-09 18:13:04 +03:00
|
|
|
const res2 = poseidon([1,2]);
|
2020-02-25 16:41:51 +03:00
|
|
|
// console.log("Ref: " + bigInt(res2).toString(16));
|
|
|
|
|
|
|
|
assert.equal(res.toString(), res2.toString());
|
|
|
|
});
|
|
|
|
|
2019-06-04 14:40:15 +03:00
|
|
|
});
|
|
|
|
|