-
Notifications
You must be signed in to change notification settings - Fork 706
Expand file tree
/
Copy pathDSTestPlus.t.sol
More file actions
72 lines (59 loc) · 1.92 KB
/
DSTestPlus.t.sol
File metadata and controls
72 lines (59 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.15;
import {DSTestPlus} from "./utils/DSTestPlus.sol";
contract DSTestPlusTest is DSTestPlus {
function testBound() public {
assertEq(bound(0, 69, 69), 69);
assertEq(bound(0, 68, 69), 68);
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 {
bound(5, 100, 10);
}
function testRelApproxEqBothZeroesPasses() public {
assertRelApproxEq(0, 0, 1e18);
assertRelApproxEq(0, 0, 0);
}
function testBound(
uint256 num,
uint256 min,
uint256 max
) public {
if (min > max) (min, max) = (max, min);
uint256 bounded = bound(num, min, max);
assertGe(bounded, min);
assertLe(bounded, max);
}
function testFailBoundMinBiggerThanMax(
uint256 num,
uint256 min,
uint256 max
) public {
if (max == min) {
unchecked {
min++; // Overflow is handled below.
}
}
if (max > min) (min, max) = (max, min);
bound(num, min, max);
}
function testBrutalizeMemory() public brutalizeMemory("FEEDFACECAFEBEEFFEEDFACECAFEBEEF") {
bytes32 scratchSpace1;
bytes32 scratchSpace2;
bytes32 freeMem1;
bytes32 freeMem2;
assembly {
scratchSpace1 := mload(0)
scratchSpace2 := mload(32)
freeMem1 := mload(mload(0x40))
freeMem2 := mload(add(mload(0x40), 32))
}
assertGt(uint256(freeMem1), 0);
assertGt(uint256(freeMem2), 0);
assertGt(uint256(scratchSpace1), 0);
assertGt(uint256(scratchSpace2), 0);
}
}