Skip to content

Commit

Permalink
final clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
dmfxyz committed Mar 26, 2024
1 parent c199f8b commit ce355ba
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 25 deletions.
10 changes: 5 additions & 5 deletions script/test/Merkle.s.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract MerkleScriptOutputTest is Test, ScriptHelper {
uint256 value = 10000;
uint256 index = 1;

function testAbiEncode(address a, uint256 b, uint256 c) public {
function testAbiEncode(address a, uint256 b, uint256 c) public pure {
vm.assume(a != address(0));
vm.assume(b != 0);
vm.assume(c != 0);
Expand All @@ -39,24 +39,24 @@ contract MerkleScriptOutputTest is Test, ScriptHelper {
assertEq(abi.encode(a, b, c), ltrim64(abi.encode(_bytes)));
}

function testComputeLeaf() public {
function testComputeLeaf() public view {
bytes32 computedLeaf = keccak256(bytes.concat(keccak256(abi.encode(addr, value, index))));
assertEq(computedLeaf, leaf);
}

function testVerify() public {
function testVerify() public view {
bytes32 computedLeaf = keccak256(bytes.concat(keccak256(abi.encode(addr, value, index))));
assertTrue(MerkleProof.verify(proof, root, computedLeaf));
}

function testFalseAddress(address a) public {
function testFalseAddress(address a) public view {
vm.assume(a != addr);

bytes32 computedLeaf = keccak256(bytes.concat(keccak256(abi.encode(a, value, index))));
assertFalse(MerkleProof.verify(proof, root, computedLeaf));
}

function testFalseValue(uint256 b, uint256 c) public {
function testFalseValue(uint256 b, uint256 c) public view {
vm.assume(b != value);
vm.assume(c != index);

Expand Down
9 changes: 0 additions & 9 deletions src/test/CompleteMerkle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ contract GasComparisonTests is Test {
assertTrue(MerkleProof.verify(proof, root, valueToProve));
}

// function testVerifyProofOzForGasComparison(bytes32[] memory data, uint256 node) public view {
// vm.assume(data.length > 1);
// vm.assume(node < data.length);
// bytes32 root = m.getRoot(data);
// bytes32[] memory proof = m.getProof(data, node);
// bytes32 valueToProve = data[node];
// assertTrue(MerkleProof.verify(proof, root, valueToProve));
// }

function testWontGetRootSingleLeaf() public {
bytes32[] memory data = new bytes32[](1);
data[0] = bytes32(0x0);
Expand Down
10 changes: 5 additions & 5 deletions src/test/Merkle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ contract ContractTest is Test {
m = new Merkle();
}

function testHashes(bytes32 left, bytes32 right) public {
function testHashes(bytes32 left, bytes32 right) public view {
bytes32 hAssem = m.hashLeafPairs(left, right);
bytes memory packed;
if (left <= right) {
Expand All @@ -24,7 +24,7 @@ contract ContractTest is Test {
assertEq(hAssem, hNaive);
}

function testGenerateProof(bytes32[] memory data, uint256 node) public {
function testGenerateProof(bytes32[] memory data, uint256 node) public view {
vm.assume(data.length > 1);
vm.assume(node < data.length);
bytes32 root = m.getRoot(data);
Expand All @@ -38,7 +38,7 @@ contract ContractTest is Test {
assertEq(rollingHash, root);
}

function testVerifyProof(bytes32[] memory data, uint256 node) public {
function testVerifyProof(bytes32[] memory data, uint256 node) public view {
vm.assume(data.length > 1);
vm.assume(node < data.length);
bytes32 root = m.getRoot(data);
Expand All @@ -47,7 +47,7 @@ contract ContractTest is Test {
assertTrue(m.verifyProof(root, proof, valueToProve));
}

function testFailVerifyProof(bytes32[] memory data, bytes32 valueToProve, uint256 node) public {
function testFailVerifyProof(bytes32[] memory data, bytes32 valueToProve, uint256 node) public view {
vm.assume(data.length > 1);
vm.assume(node < data.length);
vm.assume(valueNotInArray(data, valueToProve));
Expand All @@ -56,7 +56,7 @@ contract ContractTest is Test {
assertTrue(m.verifyProof(root, proof, valueToProve));
}

function testVerifyProofOzForGasComparison(bytes32[] memory data, uint256 node) public {
function testVerifyProofOzForGasComparison(bytes32[] memory data, uint256 node) public view {
vm.assume(data.length > 1);
vm.assume(node < data.length);
bytes32 root = m.getRoot(data);
Expand Down
4 changes: 2 additions & 2 deletions src/test/MurkyBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ contract MurkyBaseTest is Test, MurkyBase {
this.log2ceilBitMagic(x);
}

function testLogCeil_KnownPowerOf2() public {
function testLogCeil_KnownPowerOf2() public view {
assertEq(3, this.log2ceilBitMagic(8));
}

function testLogCeil_Known() public {
function testLogCeil_Known() public view {
assertEq(8, this.log2ceilBitMagic((129)));
}
}
8 changes: 4 additions & 4 deletions src/test/Xorkle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ contract ContractTest is Test {
m = new Xorkle();
}

function testHashes(bytes32 left, bytes32 right) public {
function testHashes(bytes32 left, bytes32 right) public view {
bytes32 hAssem = m.hashLeafPairs(left, right);
bytes32 hNaive = keccak256(abi.encode(left ^ right));
assertEq(hAssem, hNaive);
}

function testGenerateProof(bytes32[] memory data, uint256 node) public {
function testGenerateProof(bytes32[] memory data, uint256 node) public view {
vm.assume(data.length > 1);
vm.assume(node < data.length);
bytes32 root = m.getRoot(data);
Expand All @@ -31,7 +31,7 @@ contract ContractTest is Test {
assertEq(rollingHash, root);
}

function testVerifyProof(bytes32[] memory data, uint256 node) public {
function testVerifyProof(bytes32[] memory data, uint256 node) public view {
vm.assume(data.length > 1);
vm.assume(node < data.length);
bytes32 root = m.getRoot(data);
Expand All @@ -40,7 +40,7 @@ contract ContractTest is Test {
assertTrue(m.verifyProof(root, proof, valueToProve));
}

function testFailVerifyProof(bytes32[] memory data, bytes32 valueToProve, uint256 node) public {
function testFailVerifyProof(bytes32[] memory data, bytes32 valueToProve, uint256 node) public view {
vm.assume(data.length > 1);
vm.assume(node < data.length);
vm.assume(valueNotInArray(data, valueToProve));
Expand Down

0 comments on commit ce355ba

Please sign in to comment.