Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/AssertWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
15 changes: 12 additions & 3 deletions src/FuzzBase.sol
Original file line number Diff line number Diff line change
@@ -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);
}
18 changes: 18 additions & 0 deletions src/MathHelper.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}
18 changes: 18 additions & 0 deletions src/RandomHelper.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}
}