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
2 changes: 1 addition & 1 deletion .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Bytes32AddressLibTest:testFromLast20Bytes() (gas: 191)
CREATE3Test:testDeployERC20() (gas: 852410)
CREATE3Test:testFailDoubleDeployDifferentBytecode() (gas: 9079256848778914164)
CREATE3Test:testFailDoubleDeploySameBytecode() (gas: 9079256848778906218)
DSTestPlusTest:testBound() (gas: 16777)
DSTestPlusTest:testBound() (gas: 14208)
DSTestPlusTest:testBrutalizeMemory() (gas: 446)
DSTestPlusTest:testFailBoundMinBiggerThanMax() (gas: 309)
DSTestPlusTest:testRelApproxEqBothZeroesPasses() (gas: 413)
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"prettier-plugin-solidity": "^1.0.0-beta.13"
},
"scripts": {
"lint": "prettier --write src/**/*.sol"
"lint": "prettier --write **.sol"
}
}
8 changes: 4 additions & 4 deletions src/test/DSTestPlus.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {DSTestPlus} from "./utils/DSTestPlus.sol";

contract DSTestPlusTest is DSTestPlus {
function testBound() public {
assertEq(bound(5, 0, 4), 0);
assertEq(bound(0, 69, 69), 69);
assertEq(bound(0, 68, 69), 68);
assertEq(bound(10, 150, 190), 174);
assertEq(bound(300, 2800, 3200), 3107);
assertEq(bound(9999, 1337, 6666), 4669);
assertEq(bound(5, 0, 4), 0);
assertEq(bound(9999, 1337, 6666), 6006);
assertEq(bound(0, type(uint256).max - 6, type(uint256).max), type(uint256).max - 6);
assertEq(bound(6, type(uint256).max - 6, type(uint256).max), type(uint256).max);
}

function testFailBoundMinBiggerThanMax() public {
Expand Down
17 changes: 7 additions & 10 deletions src/test/utils/DSTestPlus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,13 @@ contract DSTestPlus is DSTest {

uint256 size = max - min;

if (max != type(uint256).max) size++; // Make the max inclusive.
if (size == 0) return min; // Using max would be equivalent as well.
// Ensure max is inclusive in cases where x != 0 and max is at uint max.
if (max == type(uint256).max && x != 0) x--; // Accounted for later.

if (x < min) x += size * (((min - x) / size) + 1);
result = min + ((x - min) % size);

// Account for decrementing x to make max inclusive.
if (max == type(uint256).max && x != 0) result++;
if (size == 0) result = min;
else if (size == type(uint256).max) result = x;
else {
++size; // Make max inclusive.
uint256 mod = x % size;
result = min + mod;
}

emit log_named_uint("Bound Result", result);
}
Expand Down