Browse Source

Add Poseidon test vectors

master
arnaucube 4 years ago
parent
commit
e4217687a6
2 changed files with 45 additions and 7 deletions
  1. +9
    -7
      test/mt.test.js
  2. +36
    -0
      test/poseidon.test.js

+ 9
- 7
test/mt.test.js

@ -3,6 +3,7 @@ const chai = require("chai");
const Fr = require("ffjavascript").bn128.Fr; const Fr = require("ffjavascript").bn128.Fr;
const smt = require("circomlib").smt; const smt = require("circomlib").smt;
// const smt = require("../../iden3/circomlib/src/smt.js");
const assert = chai.assert; const assert = chai.assert;
@ -18,24 +19,24 @@ describe("SMT javascript testvectors", function () {
let k = Fr.e(1); let k = Fr.e(1);
let v = Fr.e(2); let v = Fr.e(2);
await tree.insert(k,v); await tree.insert(k,v);
console.log(tree.root);
console.log("insert(1,2)", tree.root);
k = Fr.e(33); k = Fr.e(33);
v = Fr.e(44); v = Fr.e(44);
await tree.insert(k,v); await tree.insert(k,v);
console.log(tree.root);
console.log("insert(33, 44)", tree.root);
k = Fr.e(1234); k = Fr.e(1234);
v = Fr.e(9876); v = Fr.e(9876);
await tree.insert(k,v); await tree.insert(k,v);
console.log(tree.root);
console.log("insert(1234, 9876)", tree.root);
await tree.delete(Fr.e(33)); await tree.delete(Fr.e(33));
console.log(tree.root);
console.log("delete(33)", tree.root);
await tree.delete(Fr.e(1234)); await tree.delete(Fr.e(1234));
await tree.delete(Fr.e(1)); await tree.delete(Fr.e(1));
console.log(tree.root);
console.log("delete(1234 & 1)", tree.root);
assert(Fr.isZero(tree.root)); assert(Fr.isZero(tree.root));
}); });
@ -50,7 +51,7 @@ describe("SMT javascript testvectors", function () {
k = Fr.e(2); k = Fr.e(2);
v = Fr.e(2); v = Fr.e(2);
await tree.insert(k,v); await tree.insert(k,v);
console.log(tree.root);
console.log("insert(2,2)", tree.root);
console.log("TestDelete3", tree.root); console.log("TestDelete3", tree.root);
await tree.delete(Fr.e(1)); await tree.delete(Fr.e(1));
@ -75,7 +76,8 @@ describe("SMT javascript testvectors", function () {
console.log(tree.root); console.log(tree.root);
console.log("TestDelete4", tree.root); console.log("TestDelete4", tree.root);
await tree.delete(Fr.e(1));
let res = await tree.delete(Fr.e(1));
console.log("TestDelete4 res", res);
console.log("TestDelete4", tree.root); console.log("TestDelete4", tree.root);
}); });
it("TestDelete5", async () => { it("TestDelete5", async () => {

+ 36
- 0
test/poseidon.test.js

@ -0,0 +1,36 @@
const chai = require("chai");
const Fr = require("ffjavascript").bn128.Fr;
const poseidon = require("../../iden3/circomlib/src/poseidon.js");
const assert = chai.assert;
describe("Poseidon javascript testvectors", function () {
this.timeout(100000);
before( async () => {
});
it("Poseidon t=6", async () => {
let res = poseidon([1]);
console.log(res);
res = poseidon([1,2]);
console.log(res);
res = poseidon([1,2, 0, 0, 0]);
console.log(res);
res = poseidon([1,2, 0, 0, 0, 0]);
console.log(res);
res = poseidon([3,4, 0, 0, 0]);
console.log(res);
res = poseidon([3,4, 0, 0, 0, 0]);
console.log(res);
res = poseidon([1,2,3,4,5,6]);
console.log(res);
});
});

Loading…
Cancel
Save