Skip to content

Commit ed3c681

Browse files
committed
test
1 parent 17b8414 commit ed3c681

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/test/unit/libraries/Merkle.t.sol

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ abstract contract MerkleBaseTest is Test, MurkyBase {
6161
_checkSingleProof(false, 0);
6262
}
6363

64+
/// @notice Verifies that an out-of-bounds index reverts.
65+
function testFuzz_verifyInclusion_IndexOutOfBounds(uint) public {
66+
uint index = vm.randomUint(leaves.length, type(uint).max);
67+
vm.expectRevert(stdError.indexOOBError);
68+
_checkSingleProof(false, index);
69+
}
70+
71+
function testFuzz_verifyInclusion_InternalNodeAsProof(uint) public {
72+
// TODO
73+
}
74+
6475
/// -----------------------------------------------------------------------
6576
/// Assertions
6677
/// -----------------------------------------------------------------------
@@ -70,25 +81,17 @@ abstract contract MerkleBaseTest is Test, MurkyBase {
7081
function (bytes memory proof, bytes32 root, bytes32 leaf, uint256 index) returns (bool) verifyInclusion =
7182
usingSha() ? Merkle.verifyInclusionSha256 : Merkle.verifyInclusionKeccak;
7283
for (uint i = 0; i < leaves.length; ++i) {
73-
if (proofs[i].length == 0) {
74-
vm.expectRevert(Merkle.InvalidProofLength.selector);
75-
verifyInclusion(proofs[i], root, leaves[i], i);
76-
} else {
77-
assertEq(verifyInclusion(proofs[i], root, leaves[i], i), status);
78-
}
84+
if (proofs[i].length == 0) vm.expectRevert(Merkle.InvalidProofLength.selector);
85+
assertEq(verifyInclusion(proofs[i], root, leaves[i], i), status);
7986
}
8087
}
8188

8289
/// @dev Checks that a single proof is valid for its respective leaf.
8390
function _checkSingleProof(bool status, uint index) internal virtual {
8491
function (bytes memory proof, bytes32 root, bytes32 leaf, uint256 index) view returns (bool) verifyInclusion =
8592
usingSha() ? Merkle.verifyInclusionSha256 : Merkle.verifyInclusionKeccak;
86-
if (proofs[index].length == 0) {
87-
vm.expectRevert(Merkle.InvalidProofLength.selector);
88-
verifyInclusion(proofs[index], root, leaves[index], index);
89-
} else {
90-
assertEq(verifyInclusion(proofs[index], root, leaves[index], index), status);
91-
}
93+
if (proofs[index].length == 0) vm.expectRevert(Merkle.InvalidProofLength.selector);
94+
assertEq(verifyInclusion(proofs[index], root, leaves[index], index), status);
9295
}
9396

9497
/// -----------------------------------------------------------------------

0 commit comments

Comments
 (0)