diff --git a/src/AssertWrapper.sol b/src/AssertWrapper.sol index ed247bd..45f00a2 100644 --- a/src/AssertWrapper.sol +++ b/src/AssertWrapper.sol @@ -8,26 +8,54 @@ abstract contract AssertWrapper is AssertHelper { assertGt(a, b, message); } + function gt(int256 a, int256 b, string memory message) internal { + assertGt(a, b, message); + } + function lt(uint256 a, uint256 b, string memory message) internal { assertLt(a, b, message); } + function lt(int256 a, int256 b, string memory message) internal { + assertLt(a, b, message); + } + function gte(uint256 a, uint256 b, string memory message) internal { assertGte(a, b, message); } + function gte(int256 a, int256 b, string memory message) internal { + assertGte(a, b, message); + } + function lte(uint256 a, uint256 b, string memory message) internal { assertLte(a, b, message); } + function lte(int256 a, int256 b, string memory message) internal { + assertLte(a, b, message); + } + function eq(uint256 a, uint256 b, string memory message) internal { assertEq(a, b, message); } + function eq(int256 a, int256 b, string memory message) internal { + assertEq(a, b, message); + } + + function eq(bytes4 a, bytes4 b, string memory message) internal { + assertEq(a, b, message); + } + function neq(uint256 a, uint256 b, string memory message) internal { assertNeq(a, b, message); } + function neq(int256 a, int256 b, string memory message) internal { + assertNeq(a, b, message); + } + function t(bool a, string memory message) internal { assertWithMsg(a, message); } diff --git a/src/FuzzBase.sol b/src/FuzzBase.sol index 5ccb6dd..c05df26 100644 --- a/src/FuzzBase.sol +++ b/src/FuzzBase.sol @@ -1,12 +1,21 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "./Logging.sol"; -import "./Constants.sol"; import "./AssertWrapper.sol"; import "./ClampWrapper.sol"; +import "./MathHelper.sol"; +import "./RandomHelper.sol"; +import "./Logging.sol"; +import "./Constants.sol"; import "./IHevm.sol"; -abstract contract FuzzBase is AssertWrapper, ClampWrapper, Logging, Constants { +abstract contract FuzzBase is + AssertWrapper, + ClampWrapper, + MathHelper, + RandomHelper, + Logging, + Constants +{ IHevm internal vm = IHevm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D); } diff --git a/src/MathHelper.sol b/src/MathHelper.sol new file mode 100644 index 0000000..f8d3ec2 --- /dev/null +++ b/src/MathHelper.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +abstract contract MathHelper { + function min(uint256 a, uint256 b) internal pure returns (uint256) { + return a < b ? a : b; + } + + // Forked from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.0/contracts/utils/math/SignedMath.sol + function max(int256 a, int256 b) internal pure returns (int256) { + return a > b ? a : b; + } + + // Forked with modifications from https://ethereum.stackexchange.com/a/84391 + function abs(int128 n) internal pure returns (int128) { + return n >= 0 ? n : -n; + } +} diff --git a/src/RandomHelper.sol b/src/RandomHelper.sol new file mode 100644 index 0000000..fed6854 --- /dev/null +++ b/src/RandomHelper.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +abstract contract RandomHelper { + /// @notice Shuffle an array using Fisher-Yates algorithm + /// @dev Based on https://gist.github.com/scammi/602387a22e04c77beb73c0ebc0f0bc18 + function shuffleArray(uint256[] memory shuffle, uint256 entropy) internal { + for (uint256 i = shuffle.length - 1; i > 0; i--) { + uint256 swapIndex = entropy % (shuffle.length - i); + + uint256 currentIndex = shuffle[i]; + uint256 indexToSwap = shuffle[swapIndex]; + + shuffle[i] = indexToSwap; + shuffle[swapIndex] = currentIndex; + } + } +}