Skip to content

Commit

Permalink
Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
matejos committed Apr 11, 2024
1 parent fda626c commit 02a2da9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
6 changes: 5 additions & 1 deletion packages/contracts/evm-contracts/test-lib/StdInvariant.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ abstract contract StdInvariant {
targetedArtifacts_ = _targetedArtifacts;
}

function targetArtifactSelectors() public view returns (FuzzSelector[] memory targetedArtifactSelectors_) {
function targetArtifactSelectors()
public
view
returns (FuzzSelector[] memory targetedArtifactSelectors_)
{
targetedArtifactSelectors_ = _targetedArtifactSelectors;
}

Expand Down
38 changes: 30 additions & 8 deletions packages/contracts/evm-contracts/test-lib/ctest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -588,16 +588,24 @@ contract CTest is StdInvariant {
}

function console2_log(string memory p0, uint256 p1) private view {
(bool status,) = address(CONSOLE2_ADDRESS).staticcall(abi.encodeWithSignature("log(string,uint256)", p0, p1));
(bool status, ) = address(CONSOLE2_ADDRESS).staticcall(
abi.encodeWithSignature("log(string,uint256)", p0, p1)
);
status;
}

function console2_log(string memory p0, string memory p1) private view {
(bool status,) = address(CONSOLE2_ADDRESS).staticcall(abi.encodeWithSignature("log(string,string)", p0, p1));
(bool status, ) = address(CONSOLE2_ADDRESS).staticcall(
abi.encodeWithSignature("log(string,string)", p0, p1)
);
status;
}

function _bound(uint256 x, uint256 min, uint256 max) internal pure virtual returns (uint256 result) {
function _bound(
uint256 x,
uint256 min,
uint256 max
) internal pure virtual returns (uint256 result) {
require(min <= max, "StdUtils bound(uint256,uint256,uint256): Max is less than min.");
// If x is between min and max, return x directly. This is to ensure that dictionary values
// do not get shifted if the min is nonzero. More info: https://github.com/foundry-rs/forge-std/issues/188
Expand All @@ -624,12 +632,20 @@ contract CTest is StdInvariant {
}
}

function bound(uint256 x, uint256 min, uint256 max) internal view virtual returns (uint256 result) {
function bound(
uint256 x,
uint256 min,
uint256 max
) internal view virtual returns (uint256 result) {
result = _bound(x, min, max);
console2_log("Bound Result", result);
}

function _bound(int256 x, int256 min, int256 max) internal pure virtual returns (int256 result) {
function _bound(
int256 x,
int256 min,
int256 max
) internal pure virtual returns (int256 result) {
require(min <= max, "StdUtils bound(int256,int256,int256): Max is less than min.");

// Shifting all int256 values to uint256 to use _bound function. The range of two types are:
Expand All @@ -640,13 +656,19 @@ contract CTest is StdInvariant {
// If the given integer value is -2**255, we cannot use `-uint256(-x)` because of the overflow.
// So, use `~uint256(x) + 1` instead.
uint256 _x = x < 0 ? (INT256_MIN_ABS - ~uint256(x) - 1) : (uint256(x) + INT256_MIN_ABS);
uint256 _min = min < 0 ? (INT256_MIN_ABS - ~uint256(min) - 1) : (uint256(min) + INT256_MIN_ABS);
uint256 _max = max < 0 ? (INT256_MIN_ABS - ~uint256(max) - 1) : (uint256(max) + INT256_MIN_ABS);
uint256 _min = min < 0
? (INT256_MIN_ABS - ~uint256(min) - 1)
: (uint256(min) + INT256_MIN_ABS);
uint256 _max = max < 0
? (INT256_MIN_ABS - ~uint256(max) - 1)
: (uint256(max) + INT256_MIN_ABS);

uint256 y = _bound(_x, _min, _max);

// To move it back to int256 value, subtract INT256_MIN_ABS at here.
result = y < INT256_MIN_ABS ? int256(~(INT256_MIN_ABS - y) + 1) : int256(y - INT256_MIN_ABS);
result = y < INT256_MIN_ABS
? int256(~(INT256_MIN_ABS - y) + 1)
: int256(y - INT256_MIN_ABS);
}

function bound(int256 x, int256 min, int256 max) internal view virtual returns (int256 result) {
Expand Down

0 comments on commit 02a2da9

Please sign in to comment.