Skip to content

Commit

Permalink
test: add checkMembership tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroEkkusu committed Jun 7, 2024
1 parent 2650314 commit ff6e6cf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/murky"]
path = lib/murky
url = https://github.com/dmfxyz/murky
1 change: 0 additions & 1 deletion lib/murky
Submodule murky deleted from 5feccd
19 changes: 19 additions & 0 deletions test/BorValidatorSet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,25 @@ contract BorValidatorSetTest is Test {
assertEq(borValidatorSet.getStakePowerBySigs(1, digest, sigs), sum);
}

function test_checkMembership_SingleLeaf() public {
bytes32 leaf = keccak256("leaf");
assertTrue(borValidatorSet.checkMembership(leaf, leaf, ""));
assertFalse(borValidatorSet.checkMembership(keccak256("not root"), leaf, ""));
}

function test_checkMembership() public {
bytes32 leaf = keccak256("leaf");
bytes32 proof1 = keccak256("proof1");
bytes32 proof2 = keccak256("proof2");
bytes32 computedHash = sha256(abi.encodePacked(hex"00", leaf));
bytes memory proof = abi.encodePacked(hex"01", proof1, hex"00", proof2, "garbage");
bytes32 root = sha256(abi.encodePacked(hex"01", computedHash, proof1));
root = sha256(abi.encodePacked(hex"01", proof2, root));
assertTrue(borValidatorSet.checkMembership(root, leaf, proof));
bytes memory wrongProof = abi.encodePacked(hex"01", proof1, hex"01", proof2, "garbage");
assertFalse(borValidatorSet.checkMembership(root, leaf, wrongProof));
}

function test_leafNode(bytes32 d) public returns (bytes32) {
assertEq(borValidatorSet.leafNode(d), sha256(abi.encodePacked(bytes1(uint8(0)), d)));
}
Expand Down

0 comments on commit ff6e6cf

Please sign in to comment.