Skip to content
This repository was archived by the owner on Apr 18, 2026. It is now read-only.

Commit 540207b

Browse files
authored
Merge pull request #113 from morpho-org/test/fix-bounds
[Tests] Fix bounds in the revert conditions
2 parents c8cc8be + d5133d6 commit 540207b

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

test/TestPercentageMath.sol

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ contract TestPercentageMath is Test {
99
uint256 internal constant PERCENTAGE_FACTOR = 100_00;
1010
uint256 internal constant HALF_PERCENTAGE_FACTOR = 50_00;
1111

12-
uint256 internal constant MAX_UINT256_PERCENT_UP = type(uint256).max - PERCENTAGE_FACTOR - 1;
12+
uint256 internal constant MAX_UINT256_PERCENT_UP = type(uint256).max - (PERCENTAGE_FACTOR - 1);
1313
uint256 internal constant MAX_UINT256_PERCENT_HALF_UP = type(uint256).max - HALF_PERCENTAGE_FACTOR;
1414

1515
PercentageMathMock mock;
@@ -121,6 +121,11 @@ contract TestPercentageMath is Test {
121121
mock.percentMulUp(x, y);
122122
}
123123

124+
function testPercentMulUpOverflowBound() public {
125+
vm.expectRevert();
126+
mock.percentMulUp(MAX_UINT256_PERCENT_UP + 1, 1);
127+
}
128+
124129
function testPercentDiv(uint256 x, uint256 p) public {
125130
vm.assume(p > 0 && x <= (type(uint256).max - p / 2) / PERCENTAGE_FACTOR);
126131

test/TestWadRayMath.sol

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ contract TestWadRayMath is Test {
1313
uint256 internal constant RAY_WAD_RATIO = RAY / WAD;
1414
uint256 internal constant HALF_RAY_WAD_RATIO = RAY_WAD_RATIO / 2;
1515

16-
uint256 internal constant MAX_UINT256_WAD_UP = type(uint256).max - WAD - 1;
16+
uint256 internal constant MAX_UINT256_WAD_UP = type(uint256).max - (WAD - 1);
1717
uint256 internal constant MAX_UINT256_WAD_HALF_UP = type(uint256).max - HALF_WAD;
1818

19-
uint256 internal constant MAX_UINT256_RAY_UP = type(uint256).max - RAY - 1;
19+
uint256 internal constant MAX_UINT256_RAY_UP = type(uint256).max - (RAY - 1);
2020
uint256 internal constant MAX_UINT256_RAY_HALF_UP = type(uint256).max - HALF_RAY;
2121

2222
WadRayMathMock mock;
@@ -76,6 +76,11 @@ contract TestWadRayMath is Test {
7676
mock.wadMulUp(x, y);
7777
}
7878

79+
function testWadMulUpOverflowBound() public {
80+
vm.expectRevert();
81+
mock.wadMulUp(MAX_UINT256_WAD_UP + 1, 1);
82+
}
83+
7984
function testWadDivRef(uint256 x, uint256 y) public {
8085
vm.assume(y > 0 && x <= (type(uint256).max - y / 2) / WAD);
8186

@@ -185,6 +190,11 @@ contract TestWadRayMath is Test {
185190
mock.rayMulUp(x, y);
186191
}
187192

193+
function testRayMulUpOverflowBound() public {
194+
vm.expectRevert();
195+
mock.rayMulUp(MAX_UINT256_RAY_UP + 1, 1);
196+
}
197+
188198
function testRayDivRef(uint256 x, uint256 y) public {
189199
vm.assume(y > 0 && x <= (type(uint256).max - y / 2) / RAY);
190200

0 commit comments

Comments
 (0)