Use hardhat-exposed to reduce the need for mocks (#3666)
Co-authored-by: Francisco <fg@frang.io>
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 () {
|
||||
beforeEach(async function () {
|
||||
this.merkleProof = await MerkleProofWrapper.new();
|
||||
this.merkleProof = await MerkleProof.new();
|
||||
});
|
||||
|
||||
describe('verify', function () {
|
||||
@ -24,15 +24,15 @@ contract('MerkleProof', function () {
|
||||
|
||||
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 () {
|
||||
|
||||
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 () {
|
||||
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 () {
|
||||
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,9 +92,9 @@ contract('MerkleProof', function () {
|
||||
const badProof = badMerkleTree.getMultiProof(badProofLeaves);
|
||||
const badProofFlags = badMerkleTree.getProofFlags(badProofLeaves, badProof);
|
||||
|
||||
expect(await this.merkleProof.multiProofVerify(badProof, badProofFlags, root, badProofLeaves))
|
||||
expect(await this.merkleProof.$multiProofVerify(badProof, badProofFlags, root, badProofLeaves))
|
||||
.to.equal(false);
|
||||
expect(await this.merkleProof.multiProofVerifyCalldata(badProof, badProofFlags, root, badProofLeaves))
|
||||
expect(await this.merkleProof.$multiProofVerifyCalldata(badProof, badProofFlags, root, badProofLeaves))
|
||||
.to.equal(false);
|
||||
});
|
||||
|
||||
@ -107,7 +107,7 @@ contract('MerkleProof', function () {
|
||||
const root = merkleTree.getRoot();
|
||||
|
||||
await expectRevert(
|
||||
this.merkleProof.multiProofVerify(
|
||||
this.merkleProof.$multiProofVerify(
|
||||
[ leaves[1], fill, merkleTree.layers[1][1] ],
|
||||
[ false, false, false ],
|
||||
root,
|
||||
@ -116,7 +116,7 @@ contract('MerkleProof', function () {
|
||||
'MerkleProof: invalid multiproof',
|
||||
);
|
||||
await expectRevert(
|
||||
this.merkleProof.multiProofVerifyCalldata(
|
||||
this.merkleProof.$multiProofVerifyCalldata(
|
||||
[ leaves[1], fill, merkleTree.layers[1][1] ],
|
||||
[ false, false, false ],
|
||||
root,
|
||||
@ -135,7 +135,7 @@ contract('MerkleProof', function () {
|
||||
const root = merkleTree.getRoot();
|
||||
|
||||
await expectRevert(
|
||||
this.merkleProof.multiProofVerify(
|
||||
this.merkleProof.$multiProofVerify(
|
||||
[ leaves[1], fill, merkleTree.layers[1][1] ],
|
||||
[ false, false, false, false ],
|
||||
root,
|
||||
@ -143,8 +143,9 @@ contract('MerkleProof', function () {
|
||||
),
|
||||
'reverted with panic code 0x32',
|
||||
);
|
||||
|
||||
await expectRevert(
|
||||
this.merkleProof.multiProofVerifyCalldata(
|
||||
this.merkleProof.$multiProofVerifyCalldata(
|
||||
[ leaves[1], fill, merkleTree.layers[1][1] ],
|
||||
[ false, false, false, false ],
|
||||
root,
|
||||
@ -163,8 +164,8 @@ contract('MerkleProof', function () {
|
||||
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 () {
|
||||
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