Skip to content

Commit fde0bc5

Browse files
committed
simplify tests
1 parent fd53460 commit fde0bc5

File tree

1 file changed

+14
-41
lines changed

1 file changed

+14
-41
lines changed

src/standard.test.ts

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,19 @@ describe('standard merkle tree', () => {
2929

3030
assert(t.verify(id, proof1));
3131
assert(t.verify(leaf, proof1));
32+
assert(StandardMerkleTree.verify(t.root, ['string'], leaf, proof1));
3233
}
3334
});
3435

35-
it('generates valid single proofs for all leaves from root and encoding', () => {
36+
it('rejects invalid proofs', () => {
3637
const { t } = characters('abcdef');
38+
const { t: otherTree } = characters('abc');
3739

38-
for (const [, leaf] of t.entries()) {
39-
const proof = t.getProof(leaf);
40+
const leaf = ['a'];
41+
const invalidProof = otherTree.getProof(leaf);
4042

41-
assert(StandardMerkleTree.verify(t.root, ['string'], leaf, proof));
42-
}
43-
});
44-
45-
it('rejects invalid proof using static verify method', () => {
46-
const { t } = characters('abcdef');
47-
const { t: fakeTree } = characters('xyz');
48-
49-
const testLeaf = ['x'];
50-
const proof = fakeTree.getProof(testLeaf);
51-
52-
assert(!StandardMerkleTree.verify(t.root, ['string'], testLeaf, proof));
43+
assert(!t.verify(leaf, invalidProof));
44+
assert(!StandardMerkleTree.verify(t.root, ['string'], leaf, invalidProof));
5345
});
5446

5547
it('generates valid multiproofs', () => {
@@ -62,38 +54,19 @@ describe('standard merkle tree', () => {
6254
assert.deepEqual(proof1, proof2);
6355

6456
assert(t.verifyMultiProof(proof1));
57+
assert(StandardMerkleTree.verifyMultiProof(t.root, ['string'], proof1));
6558
}
6659
});
6760

68-
it('generates valid multi-proofs for all leaves from root and encoding', () => {
61+
it('rejects invalid multiproofs', () => {
6962
const { t } = characters('abcdef');
70-
const leaves = Array.from(t.entries()).map(([_, leaf]) => leaf);
71-
72-
const multiproof = t.getMultiProof(leaves);
73-
74-
assert(StandardMerkleTree.verifyMultiProof(t.root, ['string'], multiproof));
75-
});
76-
77-
it('rejects invalid multi-proof using static verifyMultiProof method', () => {
78-
const { t } = characters('abcdef');
79-
const { t: fakeTree } = characters('xyz');
80-
81-
const fakeLeaves = Array.from(fakeTree.entries()).map(([_, leaf]) => leaf);
82-
const fakeMultiProof = fakeTree.getMultiProof(fakeLeaves);
83-
84-
assert(!StandardMerkleTree.verifyMultiProof(t.root, ['string'], fakeMultiProof));
85-
});
86-
87-
it('verifies partial multi-proof using static verifyMultiProof method', () => {
88-
const { t } = characters('abcdef');
89-
90-
const leaves = Array.from(t.entries())
91-
.filter(([index]) => index % 2 === 0)
92-
.map(([_, leaf]) => leaf);
63+
const { t: otherTree } = characters('abc');
9364

94-
const multiproof = t.getMultiProof(leaves);
65+
const leaves = [['a'], ['b'], ['c']];
66+
const multiProof = otherTree.getMultiProof(leaves);
9567

96-
assert(StandardMerkleTree.verifyMultiProof(t.root, ['string'], multiproof));
68+
assert(!t.verifyMultiProof(multiProof));
69+
assert(!StandardMerkleTree.verifyMultiProof(t.root, ['string'], multiProof));
9770
});
9871

9972
it('renders tree representation', () => {

0 commit comments

Comments
 (0)