Skip to content

Commit d1305ef

Browse files
committed
add test with old format
1 parent e7e4668 commit d1305ef

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

tests/full.test.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ for (let index = 0; index < storages.length; index++) {
12131213
expect(cvp.value.string()).to.be.equal('22');
12141214
expect(cvp.fnc).to.be.equal(0);
12151215
});
1216-
it('calcualte depth for mtp', async () => {
1216+
it('calculate depth for mtp', async () => {
12171217
const storage = getTreeStorage('calculatedepth');
12181218
const mt = new Merkletree(storage, true, 40);
12191219

@@ -1231,6 +1231,29 @@ for (let index = 0; index < storages.length; index++) {
12311231
expect(proof.nodeAux).to.deep.equal(p.nodeAux);
12321232
expect(proof.existence).to.equal(p.existence);
12331233

1234+
let isValid = await verifyProof(await mt.root(), proof, BigInt('11'), BigInt('0'));
1235+
expect(isValid).to.be.true;
1236+
isValid = await verifyProof(await mt.root(), p, BigInt('11'), BigInt('0'));
1237+
expect(isValid).to.be.true;
1238+
});
1239+
it('calculate depth for mtp (old format)', async () => {
1240+
const storage = getTreeStorage('calculatedepth');
1241+
const mt = new Merkletree(storage, true, 40);
1242+
1243+
await mt.add(BigInt('1'), BigInt('2'));
1244+
await mt.add(BigInt('3'), BigInt('8'));
1245+
await mt.add(BigInt('7'), BigInt('8'));
1246+
await mt.add(BigInt('9'), BigInt('8'));
1247+
1248+
const { proof }: { proof: Proof } = await mt.generateProof(BigInt('11'), await mt.root());
1249+
1250+
const given = `{ "existence": false, "siblings": [ "0", "12166698708103333637493481507263348370172773813051235807348785759284762677336", "7750564177398573185975752951631372712868228752107043582052272719841058100111", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" ], "nodeAux": { "key": "3", "value": "8" }}`;
1251+
const p = Proof.fromJSON(JSON.parse(given));
1252+
1253+
expect(proof.allSiblings()).to.deep.equal(p.allSiblings());
1254+
expect(proof.nodeAux).to.deep.equal(p.nodeAux);
1255+
expect(proof.existence).to.equal(p.existence);
1256+
12341257
let isValid = await verifyProof(await mt.root(), proof, BigInt('11'), BigInt('0'));
12351258
expect(isValid).to.be.true;
12361259
isValid = await verifyProof(await mt.root(), p, BigInt('11'), BigInt('0'));

0 commit comments

Comments
 (0)