@godzillaba/mutest 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.devcontainer/Dockerfile +117 -0
- package/.devcontainer/devcontainer.json +62 -0
- package/.devcontainer/init-firewall.sh +118 -0
- package/.github/workflows/test.yml +38 -0
- package/.gitmodules +3 -0
- package/CLAUDE.md +39 -0
- package/README.md +33 -0
- package/foundry.lock +8 -0
- package/foundry.toml +6 -0
- package/index.ts +97 -0
- package/lib/forge-std/.gitattributes +1 -0
- package/lib/forge-std/.github/CODEOWNERS +1 -0
- package/lib/forge-std/.github/dependabot.yml +6 -0
- package/lib/forge-std/.github/workflows/ci.yml +125 -0
- package/lib/forge-std/.github/workflows/sync.yml +36 -0
- package/lib/forge-std/CONTRIBUTING.md +193 -0
- package/lib/forge-std/LICENSE-APACHE +203 -0
- package/lib/forge-std/LICENSE-MIT +25 -0
- package/lib/forge-std/README.md +314 -0
- package/lib/forge-std/RELEASE_CHECKLIST.md +12 -0
- package/lib/forge-std/foundry.toml +18 -0
- package/lib/forge-std/package.json +16 -0
- package/lib/forge-std/scripts/vm.py +636 -0
- package/lib/forge-std/src/Base.sol +48 -0
- package/lib/forge-std/src/Config.sol +60 -0
- package/lib/forge-std/src/LibVariable.sol +477 -0
- package/lib/forge-std/src/Script.sol +28 -0
- package/lib/forge-std/src/StdAssertions.sol +779 -0
- package/lib/forge-std/src/StdChains.sol +303 -0
- package/lib/forge-std/src/StdCheats.sol +825 -0
- package/lib/forge-std/src/StdConfig.sol +632 -0
- package/lib/forge-std/src/StdConstants.sol +30 -0
- package/lib/forge-std/src/StdError.sol +15 -0
- package/lib/forge-std/src/StdInvariant.sol +140 -0
- package/lib/forge-std/src/StdJson.sol +275 -0
- package/lib/forge-std/src/StdMath.sol +47 -0
- package/lib/forge-std/src/StdStorage.sol +475 -0
- package/lib/forge-std/src/StdStyle.sol +333 -0
- package/lib/forge-std/src/StdToml.sol +275 -0
- package/lib/forge-std/src/StdUtils.sol +200 -0
- package/lib/forge-std/src/Test.sol +32 -0
- package/lib/forge-std/src/Vm.sol +2533 -0
- package/lib/forge-std/src/console.sol +1551 -0
- package/lib/forge-std/src/console2.sol +4 -0
- package/lib/forge-std/src/interfaces/IERC1155.sol +105 -0
- package/lib/forge-std/src/interfaces/IERC165.sol +12 -0
- package/lib/forge-std/src/interfaces/IERC20.sol +43 -0
- package/lib/forge-std/src/interfaces/IERC4626.sol +190 -0
- package/lib/forge-std/src/interfaces/IERC6909.sol +72 -0
- package/lib/forge-std/src/interfaces/IERC721.sol +164 -0
- package/lib/forge-std/src/interfaces/IERC7540.sol +144 -0
- package/lib/forge-std/src/interfaces/IERC7575.sol +241 -0
- package/lib/forge-std/src/interfaces/IMulticall3.sol +68 -0
- package/lib/forge-std/src/safeconsole.sol +13248 -0
- package/lib/forge-std/test/CommonBase.t.sol +44 -0
- package/lib/forge-std/test/Config.t.sol +381 -0
- package/lib/forge-std/test/LibVariable.t.sol +452 -0
- package/lib/forge-std/test/StdAssertions.t.sol +141 -0
- package/lib/forge-std/test/StdChains.t.sol +227 -0
- package/lib/forge-std/test/StdCheats.t.sol +638 -0
- package/lib/forge-std/test/StdConstants.t.sol +38 -0
- package/lib/forge-std/test/StdError.t.sol +119 -0
- package/lib/forge-std/test/StdJson.t.sol +49 -0
- package/lib/forge-std/test/StdMath.t.sol +202 -0
- package/lib/forge-std/test/StdStorage.t.sol +485 -0
- package/lib/forge-std/test/StdStyle.t.sol +110 -0
- package/lib/forge-std/test/StdToml.t.sol +49 -0
- package/lib/forge-std/test/StdUtils.t.sol +342 -0
- package/lib/forge-std/test/Vm.t.sol +18 -0
- package/lib/forge-std/test/compilation/CompilationScript.sol +8 -0
- package/lib/forge-std/test/compilation/CompilationScriptBase.sol +8 -0
- package/lib/forge-std/test/compilation/CompilationTest.sol +8 -0
- package/lib/forge-std/test/compilation/CompilationTestBase.sol +8 -0
- package/lib/forge-std/test/fixtures/broadcast.log.json +187 -0
- package/lib/forge-std/test/fixtures/config.toml +81 -0
- package/lib/forge-std/test/fixtures/test.json +8 -0
- package/lib/forge-std/test/fixtures/test.toml +6 -0
- package/package.json +10 -0
- package/script/Counter.s.sol +19 -0
- package/src/Counter.sol +14 -0
- package/test/Counter.t.sol +24 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
pragma solidity >=0.8.13 <0.9.0;
|
|
3
|
+
|
|
4
|
+
import {stdError} from "../src/StdError.sol";
|
|
5
|
+
import {Test} from "../src/Test.sol";
|
|
6
|
+
|
|
7
|
+
contract StdErrorsTest is Test {
|
|
8
|
+
ErrorsTest test;
|
|
9
|
+
|
|
10
|
+
function setUp() public {
|
|
11
|
+
test = new ErrorsTest();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function test_RevertIf_AssertionError() public {
|
|
15
|
+
vm.expectRevert(stdError.assertionError);
|
|
16
|
+
test.assertionError();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function test_RevertIf_ArithmeticError() public {
|
|
20
|
+
vm.expectRevert(stdError.arithmeticError);
|
|
21
|
+
test.arithmeticError(10);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function test_RevertIf_DivisionError() public {
|
|
25
|
+
vm.expectRevert(stdError.divisionError);
|
|
26
|
+
test.divError(0);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function test_RevertIf_ModError() public {
|
|
30
|
+
vm.expectRevert(stdError.divisionError);
|
|
31
|
+
test.modError(0);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function test_RevertIf_EnumConversionError() public {
|
|
35
|
+
vm.expectRevert(stdError.enumConversionError);
|
|
36
|
+
test.enumConversion(1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function test_RevertIf_EncodeStgError() public {
|
|
40
|
+
vm.expectRevert(stdError.encodeStorageError);
|
|
41
|
+
test.encodeStgError();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function test_RevertIf_PopError() public {
|
|
45
|
+
vm.expectRevert(stdError.popError);
|
|
46
|
+
test.pop();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function test_RevertIf_IndexOOBError() public {
|
|
50
|
+
vm.expectRevert(stdError.indexOOBError);
|
|
51
|
+
test.indexOOBError(1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function test_RevertIf_MemOverflowError() public {
|
|
55
|
+
vm.expectRevert(stdError.memOverflowError);
|
|
56
|
+
test.mem();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function test_RevertIf_InternError() public {
|
|
60
|
+
vm.expectRevert(stdError.zeroVarError);
|
|
61
|
+
test.intern();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
contract ErrorsTest {
|
|
66
|
+
enum T {
|
|
67
|
+
T1
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
uint256[] public someArr;
|
|
71
|
+
bytes someBytes;
|
|
72
|
+
|
|
73
|
+
function assertionError() public pure {
|
|
74
|
+
assert(false);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function arithmeticError(uint256 a) public pure {
|
|
78
|
+
a -= 100;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function divError(uint256 a) public pure {
|
|
82
|
+
100 / a;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function modError(uint256 a) public pure {
|
|
86
|
+
100 % a;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function enumConversion(uint256 a) public pure {
|
|
90
|
+
T(a);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function encodeStgError() public {
|
|
94
|
+
assembly ("memory-safe") {
|
|
95
|
+
sstore(someBytes.slot, 1)
|
|
96
|
+
}
|
|
97
|
+
keccak256(someBytes);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function pop() public {
|
|
101
|
+
someArr.pop();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function indexOOBError(uint256 a) public pure {
|
|
105
|
+
uint256[] memory t = new uint256[](0);
|
|
106
|
+
t[a];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function mem() public pure {
|
|
110
|
+
uint256 l = 2 ** 256 / 32;
|
|
111
|
+
new uint256[](l);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function intern() public returns (uint256) {
|
|
115
|
+
function(uint256) internal returns (uint256) x;
|
|
116
|
+
x(2);
|
|
117
|
+
return 7;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
pragma solidity >=0.8.13 <0.9.0;
|
|
3
|
+
|
|
4
|
+
import {Test, stdJson} from "../src/Test.sol";
|
|
5
|
+
|
|
6
|
+
contract StdJsonTest is Test {
|
|
7
|
+
using stdJson for string;
|
|
8
|
+
|
|
9
|
+
string root;
|
|
10
|
+
string path;
|
|
11
|
+
|
|
12
|
+
function setUp() public {
|
|
13
|
+
root = vm.projectRoot();
|
|
14
|
+
path = string.concat(root, "/test/fixtures/test.json");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
struct SimpleJson {
|
|
18
|
+
uint256 a;
|
|
19
|
+
string b;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
struct NestedJson {
|
|
23
|
+
uint256 a;
|
|
24
|
+
string b;
|
|
25
|
+
SimpleJson c;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function test_readJson() public view {
|
|
29
|
+
string memory json = vm.readFile(path);
|
|
30
|
+
assertEq(json.readUint(".a"), 123);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function test_writeJson() public {
|
|
34
|
+
string memory json = "json";
|
|
35
|
+
json.serialize("a", uint256(123));
|
|
36
|
+
string memory semiFinal = json.serialize("b", string("test"));
|
|
37
|
+
string memory finalJson = json.serialize("c", semiFinal);
|
|
38
|
+
finalJson.write(path);
|
|
39
|
+
|
|
40
|
+
string memory json_ = vm.readFile(path);
|
|
41
|
+
bytes memory data = json_.parseRaw("$");
|
|
42
|
+
NestedJson memory decodedData = abi.decode(data, (NestedJson));
|
|
43
|
+
|
|
44
|
+
assertEq(decodedData.a, 123);
|
|
45
|
+
assertEq(decodedData.b, "test");
|
|
46
|
+
assertEq(decodedData.c.a, 123);
|
|
47
|
+
assertEq(decodedData.c.b, "test");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
pragma solidity >=0.8.13 <0.9.0;
|
|
3
|
+
|
|
4
|
+
import {stdMath} from "../src/StdMath.sol";
|
|
5
|
+
import {Test, stdError} from "../src/Test.sol";
|
|
6
|
+
|
|
7
|
+
contract StdMathMock is Test {
|
|
8
|
+
function exposedPercentDelta(uint256 a, uint256 b) public pure returns (uint256) {
|
|
9
|
+
return stdMath.percentDelta(a, b);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function exposedPercentDelta(int256 a, int256 b) public pure returns (uint256) {
|
|
13
|
+
return stdMath.percentDelta(a, b);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
contract StdMathTest is Test {
|
|
18
|
+
function test_GetAbs() external pure {
|
|
19
|
+
assertEq(stdMath.abs(-50), 50);
|
|
20
|
+
assertEq(stdMath.abs(50), 50);
|
|
21
|
+
assertEq(stdMath.abs(-1337), 1337);
|
|
22
|
+
assertEq(stdMath.abs(0), 0);
|
|
23
|
+
|
|
24
|
+
assertEq(stdMath.abs(type(int256).min), (type(uint256).max >> 1) + 1);
|
|
25
|
+
assertEq(stdMath.abs(type(int256).max), (type(uint256).max >> 1));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function testFuzz_GetAbs(int256 a) external pure {
|
|
29
|
+
uint256 manualAbs = getAbs(a);
|
|
30
|
+
|
|
31
|
+
uint256 abs = stdMath.abs(a);
|
|
32
|
+
|
|
33
|
+
assertEq(abs, manualAbs);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function test_GetDelta_Uint() external pure {
|
|
37
|
+
assertEq(stdMath.delta(uint256(0), uint256(0)), 0);
|
|
38
|
+
assertEq(stdMath.delta(uint256(0), uint256(1337)), 1337);
|
|
39
|
+
assertEq(stdMath.delta(uint256(0), type(uint64).max), type(uint64).max);
|
|
40
|
+
assertEq(stdMath.delta(uint256(0), type(uint128).max), type(uint128).max);
|
|
41
|
+
assertEq(stdMath.delta(uint256(0), type(uint256).max), type(uint256).max);
|
|
42
|
+
|
|
43
|
+
assertEq(stdMath.delta(0, uint256(0)), 0);
|
|
44
|
+
assertEq(stdMath.delta(1337, uint256(0)), 1337);
|
|
45
|
+
assertEq(stdMath.delta(type(uint64).max, uint256(0)), type(uint64).max);
|
|
46
|
+
assertEq(stdMath.delta(type(uint128).max, uint256(0)), type(uint128).max);
|
|
47
|
+
assertEq(stdMath.delta(type(uint256).max, uint256(0)), type(uint256).max);
|
|
48
|
+
|
|
49
|
+
assertEq(stdMath.delta(1337, uint256(1337)), 0);
|
|
50
|
+
assertEq(stdMath.delta(type(uint256).max, type(uint256).max), 0);
|
|
51
|
+
assertEq(stdMath.delta(5000, uint256(1250)), 3750);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function testFuzz_GetDelta_Uint(uint256 a, uint256 b) external pure {
|
|
55
|
+
uint256 manualDelta = a > b ? a - b : b - a;
|
|
56
|
+
|
|
57
|
+
uint256 delta = stdMath.delta(a, b);
|
|
58
|
+
|
|
59
|
+
assertEq(delta, manualDelta);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function test_GetDelta_Int() external pure {
|
|
63
|
+
assertEq(stdMath.delta(int256(0), int256(0)), 0);
|
|
64
|
+
assertEq(stdMath.delta(int256(0), int256(1337)), 1337);
|
|
65
|
+
assertEq(stdMath.delta(int256(0), type(int64).max), type(uint64).max >> 1);
|
|
66
|
+
assertEq(stdMath.delta(int256(0), type(int128).max), type(uint128).max >> 1);
|
|
67
|
+
assertEq(stdMath.delta(int256(0), type(int256).max), type(uint256).max >> 1);
|
|
68
|
+
|
|
69
|
+
assertEq(stdMath.delta(0, int256(0)), 0);
|
|
70
|
+
assertEq(stdMath.delta(1337, int256(0)), 1337);
|
|
71
|
+
assertEq(stdMath.delta(type(int64).max, int256(0)), type(uint64).max >> 1);
|
|
72
|
+
assertEq(stdMath.delta(type(int128).max, int256(0)), type(uint128).max >> 1);
|
|
73
|
+
assertEq(stdMath.delta(type(int256).max, int256(0)), type(uint256).max >> 1);
|
|
74
|
+
|
|
75
|
+
assertEq(stdMath.delta(-0, int256(0)), 0);
|
|
76
|
+
assertEq(stdMath.delta(-1337, int256(0)), 1337);
|
|
77
|
+
assertEq(stdMath.delta(type(int64).min, int256(0)), (type(uint64).max >> 1) + 1);
|
|
78
|
+
assertEq(stdMath.delta(type(int128).min, int256(0)), (type(uint128).max >> 1) + 1);
|
|
79
|
+
assertEq(stdMath.delta(type(int256).min, int256(0)), (type(uint256).max >> 1) + 1);
|
|
80
|
+
|
|
81
|
+
assertEq(stdMath.delta(int256(0), -0), 0);
|
|
82
|
+
assertEq(stdMath.delta(int256(0), -1337), 1337);
|
|
83
|
+
assertEq(stdMath.delta(int256(0), type(int64).min), (type(uint64).max >> 1) + 1);
|
|
84
|
+
assertEq(stdMath.delta(int256(0), type(int128).min), (type(uint128).max >> 1) + 1);
|
|
85
|
+
assertEq(stdMath.delta(int256(0), type(int256).min), (type(uint256).max >> 1) + 1);
|
|
86
|
+
|
|
87
|
+
assertEq(stdMath.delta(1337, int256(1337)), 0);
|
|
88
|
+
assertEq(stdMath.delta(type(int256).max, type(int256).max), 0);
|
|
89
|
+
assertEq(stdMath.delta(type(int256).min, type(int256).min), 0);
|
|
90
|
+
assertEq(stdMath.delta(type(int256).min, type(int256).max), type(uint256).max);
|
|
91
|
+
assertEq(stdMath.delta(5000, int256(1250)), 3750);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function testFuzz_GetDelta_Int(int256 a, int256 b) external pure {
|
|
95
|
+
uint256 absA = getAbs(a);
|
|
96
|
+
uint256 absB = getAbs(b);
|
|
97
|
+
uint256 absDelta = absA > absB ? absA - absB : absB - absA;
|
|
98
|
+
|
|
99
|
+
uint256 manualDelta;
|
|
100
|
+
if ((a >= 0 && b >= 0) || (a < 0 && b < 0)) {
|
|
101
|
+
manualDelta = absDelta;
|
|
102
|
+
}
|
|
103
|
+
// (a < 0 && b >= 0) || (a >= 0 && b < 0)
|
|
104
|
+
else {
|
|
105
|
+
manualDelta = absA + absB;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
uint256 delta = stdMath.delta(a, b);
|
|
109
|
+
|
|
110
|
+
assertEq(delta, manualDelta);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function test_GetPercentDelta_Uint() external {
|
|
114
|
+
StdMathMock stdMathMock = new StdMathMock();
|
|
115
|
+
|
|
116
|
+
assertEq(stdMath.percentDelta(uint256(0), uint256(1337)), 1e18);
|
|
117
|
+
assertEq(stdMath.percentDelta(uint256(0), type(uint64).max), 1e18);
|
|
118
|
+
assertEq(stdMath.percentDelta(uint256(0), type(uint128).max), 1e18);
|
|
119
|
+
assertEq(stdMath.percentDelta(uint256(0), type(uint192).max), 1e18);
|
|
120
|
+
|
|
121
|
+
assertEq(stdMath.percentDelta(1337, uint256(1337)), 0);
|
|
122
|
+
assertEq(stdMath.percentDelta(type(uint192).max, type(uint192).max), 0);
|
|
123
|
+
assertEq(stdMath.percentDelta(0, uint256(2500)), 1e18);
|
|
124
|
+
assertEq(stdMath.percentDelta(2500, uint256(2500)), 0);
|
|
125
|
+
assertEq(stdMath.percentDelta(5000, uint256(2500)), 1e18);
|
|
126
|
+
assertEq(stdMath.percentDelta(7500, uint256(2500)), 2e18);
|
|
127
|
+
|
|
128
|
+
vm.expectRevert("stdMath percentDelta(uint256,uint256): Divisor is zero");
|
|
129
|
+
stdMathMock.exposedPercentDelta(uint256(1), 0);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function testFuzz_GetPercentDelta_Uint(uint192 a, uint192 b) external pure {
|
|
133
|
+
vm.assume(b != 0);
|
|
134
|
+
uint256 manualDelta = a > b ? a - b : b - a;
|
|
135
|
+
|
|
136
|
+
uint256 manualPercentDelta = manualDelta * 1e18 / b;
|
|
137
|
+
uint256 percentDelta = stdMath.percentDelta(a, b);
|
|
138
|
+
|
|
139
|
+
assertEq(percentDelta, manualPercentDelta);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function test_GetPercentDelta_Int() external {
|
|
143
|
+
// We deploy a mock version so we can properly test the revert.
|
|
144
|
+
StdMathMock stdMathMock = new StdMathMock();
|
|
145
|
+
|
|
146
|
+
assertEq(stdMath.percentDelta(int256(0), int256(1337)), 1e18);
|
|
147
|
+
assertEq(stdMath.percentDelta(int256(0), -1337), 1e18);
|
|
148
|
+
assertEq(stdMath.percentDelta(int256(0), type(int64).min), 1e18);
|
|
149
|
+
assertEq(stdMath.percentDelta(int256(0), type(int128).min), 1e18);
|
|
150
|
+
assertEq(stdMath.percentDelta(int256(0), type(int192).min), 1e18);
|
|
151
|
+
assertEq(stdMath.percentDelta(int256(0), type(int64).max), 1e18);
|
|
152
|
+
assertEq(stdMath.percentDelta(int256(0), type(int128).max), 1e18);
|
|
153
|
+
assertEq(stdMath.percentDelta(int256(0), type(int192).max), 1e18);
|
|
154
|
+
|
|
155
|
+
assertEq(stdMath.percentDelta(1337, int256(1337)), 0);
|
|
156
|
+
assertEq(stdMath.percentDelta(type(int192).max, type(int192).max), 0);
|
|
157
|
+
assertEq(stdMath.percentDelta(type(int192).min, type(int192).min), 0);
|
|
158
|
+
|
|
159
|
+
assertEq(stdMath.percentDelta(type(int192).min, type(int192).max), 2e18); // rounds the 1 wei diff down
|
|
160
|
+
assertEq(stdMath.percentDelta(type(int192).max, type(int192).min), 2e18 - 1); // rounds the 1 wei diff down
|
|
161
|
+
assertEq(stdMath.percentDelta(0, int256(2500)), 1e18);
|
|
162
|
+
assertEq(stdMath.percentDelta(2500, int256(2500)), 0);
|
|
163
|
+
assertEq(stdMath.percentDelta(5000, int256(2500)), 1e18);
|
|
164
|
+
assertEq(stdMath.percentDelta(7500, int256(2500)), 2e18);
|
|
165
|
+
|
|
166
|
+
vm.expectRevert("stdMath percentDelta(int256,int256): Divisor is zero");
|
|
167
|
+
stdMathMock.exposedPercentDelta(int256(1), 0);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function testFuzz_GetPercentDelta_Int(int192 a, int192 b) external pure {
|
|
171
|
+
vm.assume(b != 0);
|
|
172
|
+
uint256 absA = getAbs(a);
|
|
173
|
+
uint256 absB = getAbs(b);
|
|
174
|
+
uint256 absDelta = absA > absB ? absA - absB : absB - absA;
|
|
175
|
+
|
|
176
|
+
uint256 manualDelta;
|
|
177
|
+
if ((a >= 0 && b >= 0) || (a < 0 && b < 0)) {
|
|
178
|
+
manualDelta = absDelta;
|
|
179
|
+
}
|
|
180
|
+
// (a < 0 && b >= 0) || (a >= 0 && b < 0)
|
|
181
|
+
else {
|
|
182
|
+
manualDelta = absA + absB;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
uint256 manualPercentDelta = manualDelta * 1e18 / absB;
|
|
186
|
+
uint256 percentDelta = stdMath.percentDelta(a, b);
|
|
187
|
+
|
|
188
|
+
assertEq(percentDelta, manualPercentDelta);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/*//////////////////////////////////////////////////////////////////////////
|
|
192
|
+
HELPERS
|
|
193
|
+
//////////////////////////////////////////////////////////////////////////*/
|
|
194
|
+
|
|
195
|
+
function getAbs(int256 a) private pure returns (uint256) {
|
|
196
|
+
if (a < 0) {
|
|
197
|
+
return a == type(int256).min ? uint256(type(int256).max) + 1 : uint256(-a);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return uint256(a);
|
|
201
|
+
}
|
|
202
|
+
}
|