Update docs
This commit is contained in:
@ -6,11 +6,11 @@ const keccak256 = require('keccak256');
|
||||
|
||||
const { expect } = require('chai');
|
||||
|
||||
const MerkleProofWrapper = artifacts.require('MerkleProofWrapper');
|
||||
const MerkleProof = artifacts.require('$MerkleProof');
|
||||
|
||||
contract('MerkleProof', function (accounts) {
|
||||
contract('MerkleProof', function () {
|
||||
beforeEach(async function () {
|
||||
this.merkleProof = await MerkleProofWrapper.new();
|
||||
this.merkleProof = await MerkleProof.new();
|
||||
});
|
||||
|
||||
describe('verify', function () {
|
||||
@ -24,15 +24,15 @@ contract('MerkleProof', function (accounts) {
|
||||
|
||||
const proof = merkleTree.getHexProof(leaf);
|
||||
|
||||
expect(await this.merkleProof.verify(proof, root, leaf)).to.equal(true);
|
||||
expect(await this.merkleProof.verifyCalldata(proof, root, leaf)).to.equal(true);
|
||||
expect(await this.merkleProof.$verify(proof, root, leaf)).to.equal(true);
|
||||
expect(await this.merkleProof.$verifyCalldata(proof, root, leaf)).to.equal(true);
|
||||
|
||||
// For demonstration, it is also possible to create valid proofs for certain 64-byte values *not* in elements:
|
||||
const noSuchLeaf = keccak256(
|
||||
Buffer.concat([keccak256(elements[0]), keccak256(elements[1])].sort(Buffer.compare)),
|
||||
);
|
||||
expect(await this.merkleProof.verify(proof.slice(1), root, noSuchLeaf)).to.equal(true);
|
||||
expect(await this.merkleProof.verifyCalldata(proof.slice(1), root, noSuchLeaf)).to.equal(true);
|
||||
expect(await this.merkleProof.$verify(proof.slice(1), root, noSuchLeaf)).to.equal(true);
|
||||
expect(await this.merkleProof.$verifyCalldata(proof.slice(1), root, noSuchLeaf)).to.equal(true);
|
||||
});
|
||||
|
||||
it('returns false for an invalid Merkle proof', async function () {
|
||||
@ -48,8 +48,8 @@ contract('MerkleProof', function (accounts) {
|
||||
|
||||
const badProof = badMerkleTree.getHexProof(badElements[0]);
|
||||
|
||||
expect(await this.merkleProof.verify(badProof, correctRoot, correctLeaf)).to.equal(false);
|
||||
expect(await this.merkleProof.verifyCalldata(badProof, correctRoot, correctLeaf)).to.equal(false);
|
||||
expect(await this.merkleProof.$verify(badProof, correctRoot, correctLeaf)).to.equal(false);
|
||||
expect(await this.merkleProof.$verifyCalldata(badProof, correctRoot, correctLeaf)).to.equal(false);
|
||||
});
|
||||
|
||||
it('returns false for a Merkle proof of invalid length', async function () {
|
||||
@ -63,8 +63,8 @@ contract('MerkleProof', function (accounts) {
|
||||
const proof = merkleTree.getHexProof(leaf);
|
||||
const badProof = proof.slice(0, proof.length - 5);
|
||||
|
||||
expect(await this.merkleProof.verify(badProof, root, leaf)).to.equal(false);
|
||||
expect(await this.merkleProof.verifyCalldata(badProof, root, leaf)).to.equal(false);
|
||||
expect(await this.merkleProof.$verify(badProof, root, leaf)).to.equal(false);
|
||||
expect(await this.merkleProof.$verifyCalldata(badProof, root, leaf)).to.equal(false);
|
||||
});
|
||||
});
|
||||
|
||||
@ -78,8 +78,8 @@ contract('MerkleProof', function (accounts) {
|
||||
const proof = merkleTree.getMultiProof(proofLeaves);
|
||||
const proofFlags = merkleTree.getProofFlags(proofLeaves, proof);
|
||||
|
||||
expect(await this.merkleProof.multiProofVerify(proof, proofFlags, root, proofLeaves)).to.equal(true);
|
||||
expect(await this.merkleProof.multiProofVerifyCalldata(proof, proofFlags, root, proofLeaves)).to.equal(true);
|
||||
expect(await this.merkleProof.$multiProofVerify(proof, proofFlags, root, proofLeaves)).to.equal(true);
|
||||
expect(await this.merkleProof.$multiProofVerifyCalldata(proof, proofFlags, root, proofLeaves)).to.equal(true);
|
||||
});
|
||||
|
||||
it('returns false for an invalid Merkle multi proof', async function () {
|
||||
@ -92,10 +92,10 @@ contract('MerkleProof', function (accounts) {
|
||||
const badProof = badMerkleTree.getMultiProof(badProofLeaves);
|
||||
const badProofFlags = badMerkleTree.getProofFlags(badProofLeaves, badProof);
|
||||
|
||||
expect(await this.merkleProof.multiProofVerify(badProof, badProofFlags, root, badProofLeaves))
|
||||
.to.equal(false);
|
||||
expect(await this.merkleProof.multiProofVerifyCalldata(badProof, badProofFlags, root, badProofLeaves))
|
||||
.to.equal(false);
|
||||
expect(await this.merkleProof.$multiProofVerify(badProof, badProofFlags, root, badProofLeaves)).to.equal(false);
|
||||
expect(await this.merkleProof.$multiProofVerifyCalldata(badProof, badProofFlags, root, badProofLeaves)).to.equal(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it('revert with invalid multi proof #1', async function () {
|
||||
@ -107,20 +107,20 @@ contract('MerkleProof', function (accounts) {
|
||||
const root = merkleTree.getRoot();
|
||||
|
||||
await expectRevert(
|
||||
this.merkleProof.multiProofVerify(
|
||||
[ leaves[1], fill, merkleTree.layers[1][1] ],
|
||||
[ false, false, false ],
|
||||
this.merkleProof.$multiProofVerify(
|
||||
[leaves[1], fill, merkleTree.layers[1][1]],
|
||||
[false, false, false],
|
||||
root,
|
||||
[ leaves[0], badLeaf ], // A, E
|
||||
[leaves[0], badLeaf], // A, E
|
||||
),
|
||||
'MerkleProof: invalid multiproof',
|
||||
);
|
||||
await expectRevert(
|
||||
this.merkleProof.multiProofVerifyCalldata(
|
||||
[ leaves[1], fill, merkleTree.layers[1][1] ],
|
||||
[ false, false, false ],
|
||||
this.merkleProof.$multiProofVerifyCalldata(
|
||||
[leaves[1], fill, merkleTree.layers[1][1]],
|
||||
[false, false, false],
|
||||
root,
|
||||
[ leaves[0], badLeaf ], // A, E
|
||||
[leaves[0], badLeaf], // A, E
|
||||
),
|
||||
'MerkleProof: invalid multiproof',
|
||||
);
|
||||
@ -135,20 +135,21 @@ contract('MerkleProof', function (accounts) {
|
||||
const root = merkleTree.getRoot();
|
||||
|
||||
await expectRevert(
|
||||
this.merkleProof.multiProofVerify(
|
||||
[ leaves[1], fill, merkleTree.layers[1][1] ],
|
||||
[ false, false, false, false ],
|
||||
this.merkleProof.$multiProofVerify(
|
||||
[leaves[1], fill, merkleTree.layers[1][1]],
|
||||
[false, false, false, false],
|
||||
root,
|
||||
[ badLeaf, leaves[0] ], // A, E
|
||||
[badLeaf, leaves[0]], // A, E
|
||||
),
|
||||
'reverted with panic code 0x32',
|
||||
);
|
||||
|
||||
await expectRevert(
|
||||
this.merkleProof.multiProofVerifyCalldata(
|
||||
[ leaves[1], fill, merkleTree.layers[1][1] ],
|
||||
[ false, false, false, false ],
|
||||
this.merkleProof.$multiProofVerifyCalldata(
|
||||
[leaves[1], fill, merkleTree.layers[1][1]],
|
||||
[false, false, false, false],
|
||||
root,
|
||||
[ badLeaf, leaves[0] ], // A, E
|
||||
[badLeaf, leaves[0]], // A, E
|
||||
),
|
||||
'reverted with panic code 0x32',
|
||||
);
|
||||
@ -163,8 +164,8 @@ contract('MerkleProof', function (accounts) {
|
||||
const proof = merkleTree.getMultiProof(proofLeaves);
|
||||
const proofFlags = merkleTree.getProofFlags(proofLeaves, proof);
|
||||
|
||||
expect(await this.merkleProof.multiProofVerify(proof, proofFlags, root, proofLeaves)).to.equal(true);
|
||||
expect(await this.merkleProof.multiProofVerifyCalldata(proof, proofFlags, root, proofLeaves)).to.equal(true);
|
||||
expect(await this.merkleProof.$multiProofVerify(proof, proofFlags, root, proofLeaves)).to.equal(true);
|
||||
expect(await this.merkleProof.$multiProofVerifyCalldata(proof, proofFlags, root, proofLeaves)).to.equal(true);
|
||||
});
|
||||
|
||||
it('limit case: can prove empty leaves', async function () {
|
||||
@ -172,8 +173,8 @@ contract('MerkleProof', function (accounts) {
|
||||
const merkleTree = new MerkleTree(leaves, keccak256, { sort: true });
|
||||
|
||||
const root = merkleTree.getRoot();
|
||||
expect(await this.merkleProof.multiProofVerify([ root ], [], root, [])).to.equal(true);
|
||||
expect(await this.merkleProof.multiProofVerifyCalldata([ root ], [], root, [])).to.equal(true);
|
||||
expect(await this.merkleProof.$multiProofVerify([root], [], root, [])).to.equal(true);
|
||||
expect(await this.merkleProof.$multiProofVerifyCalldata([root], [], root, [])).to.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user