@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,200 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
pragma solidity >=0.8.13 <0.9.0;
|
|
3
|
+
|
|
4
|
+
import {IMulticall3} from "./interfaces/IMulticall3.sol";
|
|
5
|
+
import {StdConstants} from "./StdConstants.sol";
|
|
6
|
+
import {VmSafe} from "./Vm.sol";
|
|
7
|
+
|
|
8
|
+
abstract contract StdUtils {
|
|
9
|
+
/*//////////////////////////////////////////////////////////////////////////
|
|
10
|
+
CONSTANTS
|
|
11
|
+
//////////////////////////////////////////////////////////////////////////*/
|
|
12
|
+
|
|
13
|
+
VmSafe private constant vm = VmSafe(address(uint160(uint256(keccak256("hevm cheat code")))));
|
|
14
|
+
address private constant CONSOLE2_ADDRESS = 0x000000000000000000636F6e736F6c652e6c6f67;
|
|
15
|
+
uint256 private constant INT256_MIN_ABS =
|
|
16
|
+
57896044618658097711785492504343953926634992332820282019728792003956564819968;
|
|
17
|
+
uint256 private constant SECP256K1_ORDER =
|
|
18
|
+
115792089237316195423570985008687907852837564279074904382605163141518161494337;
|
|
19
|
+
uint256 private constant UINT256_MAX =
|
|
20
|
+
115792089237316195423570985008687907853269984665640564039457584007913129639935;
|
|
21
|
+
|
|
22
|
+
/*//////////////////////////////////////////////////////////////////////////
|
|
23
|
+
INTERNAL FUNCTIONS
|
|
24
|
+
//////////////////////////////////////////////////////////////////////////*/
|
|
25
|
+
|
|
26
|
+
function _bound(uint256 x, uint256 min, uint256 max) internal pure virtual returns (uint256 result) {
|
|
27
|
+
require(min <= max, "StdUtils bound(uint256,uint256,uint256): Max is less than min.");
|
|
28
|
+
// If x is between min and max, return x directly. This is to ensure that dictionary values
|
|
29
|
+
// do not get shifted if the min is nonzero. More info: https://github.com/foundry-rs/forge-std/issues/188
|
|
30
|
+
if (x >= min && x <= max) return x;
|
|
31
|
+
|
|
32
|
+
uint256 size = max - min + 1;
|
|
33
|
+
|
|
34
|
+
// If the value is 0, 1, 2, 3, wrap that to min, min+1, min+2, min+3. Similarly for the UINT256_MAX side.
|
|
35
|
+
// This helps ensure coverage of the min/max values.
|
|
36
|
+
if (x <= 3 && size > x) return min + x;
|
|
37
|
+
if (x >= UINT256_MAX - 3 && size > UINT256_MAX - x) return max - (UINT256_MAX - x);
|
|
38
|
+
|
|
39
|
+
// Otherwise, wrap x into the range [min, max], i.e. the range is inclusive.
|
|
40
|
+
if (x > max) {
|
|
41
|
+
uint256 diff = x - max;
|
|
42
|
+
uint256 rem = diff % size;
|
|
43
|
+
if (rem == 0) return max;
|
|
44
|
+
result = min + rem - 1;
|
|
45
|
+
} else if (x < min) {
|
|
46
|
+
uint256 diff = min - x;
|
|
47
|
+
uint256 rem = diff % size;
|
|
48
|
+
if (rem == 0) return min;
|
|
49
|
+
result = max - rem + 1;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function bound(uint256 x, uint256 min, uint256 max) internal pure virtual returns (uint256 result) {
|
|
54
|
+
result = _bound(x, min, max);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function _bound(int256 x, int256 min, int256 max) internal pure virtual returns (int256 result) {
|
|
58
|
+
require(min <= max, "StdUtils bound(int256,int256,int256): Max is less than min.");
|
|
59
|
+
|
|
60
|
+
// Shifting all int256 values to uint256 to use _bound function. The range of two types are:
|
|
61
|
+
// int256 : -(2**255) ~ (2**255 - 1)
|
|
62
|
+
// uint256: 0 ~ (2**256 - 1)
|
|
63
|
+
// So, add 2**255, INT256_MIN_ABS to the integer values.
|
|
64
|
+
//
|
|
65
|
+
// If the given integer value is -2**255, we cannot use `-uint256(-x)` because of the overflow.
|
|
66
|
+
// So, use `~uint256(x) + 1` instead.
|
|
67
|
+
uint256 _x = x < 0 ? (INT256_MIN_ABS - ~uint256(x) - 1) : (uint256(x) + INT256_MIN_ABS);
|
|
68
|
+
uint256 _min = min < 0 ? (INT256_MIN_ABS - ~uint256(min) - 1) : (uint256(min) + INT256_MIN_ABS);
|
|
69
|
+
uint256 _max = max < 0 ? (INT256_MIN_ABS - ~uint256(max) - 1) : (uint256(max) + INT256_MIN_ABS);
|
|
70
|
+
|
|
71
|
+
uint256 y = _bound(_x, _min, _max);
|
|
72
|
+
|
|
73
|
+
// To move it back to int256 value, subtract INT256_MIN_ABS at here.
|
|
74
|
+
result = y < INT256_MIN_ABS ? int256(~(INT256_MIN_ABS - y) + 1) : int256(y - INT256_MIN_ABS);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function bound(int256 x, int256 min, int256 max) internal pure virtual returns (int256 result) {
|
|
78
|
+
result = _bound(x, min, max);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function boundPrivateKey(uint256 privateKey) internal pure virtual returns (uint256 result) {
|
|
82
|
+
result = _bound(privateKey, 1, SECP256K1_ORDER - 1);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function bytesToUint(bytes memory b) internal pure virtual returns (uint256) {
|
|
86
|
+
require(b.length <= 32, "StdUtils bytesToUint(bytes): Bytes length exceeds 32.");
|
|
87
|
+
return abi.decode(abi.encodePacked(new bytes(32 - b.length), b), (uint256));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/// @dev Compute the address a contract will be deployed at for a given deployer address and nonce
|
|
91
|
+
function computeCreateAddress(address deployer, uint256 nonce) internal pure virtual returns (address) {
|
|
92
|
+
console2_log_StdUtils("computeCreateAddress is deprecated. Please use vm.computeCreateAddress instead.");
|
|
93
|
+
return vm.computeCreateAddress(deployer, nonce);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function computeCreate2Address(bytes32 salt, bytes32 initcodeHash, address deployer)
|
|
97
|
+
internal
|
|
98
|
+
pure
|
|
99
|
+
virtual
|
|
100
|
+
returns (address)
|
|
101
|
+
{
|
|
102
|
+
console2_log_StdUtils("computeCreate2Address is deprecated. Please use vm.computeCreate2Address instead.");
|
|
103
|
+
return vm.computeCreate2Address(salt, initcodeHash, deployer);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/// @dev returns the address of a contract created with CREATE2 using the default CREATE2 deployer
|
|
107
|
+
function computeCreate2Address(bytes32 salt, bytes32 initCodeHash) internal pure returns (address) {
|
|
108
|
+
console2_log_StdUtils("computeCreate2Address is deprecated. Please use vm.computeCreate2Address instead.");
|
|
109
|
+
return vm.computeCreate2Address(salt, initCodeHash);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/// @dev returns the hash of the init code (creation code + no args) used in CREATE2 with no constructor arguments
|
|
113
|
+
/// @param creationCode the creation code of a contract C, as returned by type(C).creationCode
|
|
114
|
+
function hashInitCode(bytes memory creationCode) internal pure returns (bytes32) {
|
|
115
|
+
return hashInitCode(creationCode, "");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/// @dev returns the hash of the init code (creation code + ABI-encoded args) used in CREATE2
|
|
119
|
+
/// @param creationCode the creation code of a contract C, as returned by type(C).creationCode
|
|
120
|
+
/// @param args the ABI-encoded arguments to the constructor of C
|
|
121
|
+
function hashInitCode(bytes memory creationCode, bytes memory args) internal pure returns (bytes32) {
|
|
122
|
+
return keccak256(abi.encodePacked(creationCode, args));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Performs a single call with Multicall3 to query the ERC-20 token balances of the given addresses.
|
|
126
|
+
function getTokenBalances(address token, address[] memory addresses)
|
|
127
|
+
internal
|
|
128
|
+
virtual
|
|
129
|
+
returns (uint256[] memory balances)
|
|
130
|
+
{
|
|
131
|
+
uint256 tokenCodeSize;
|
|
132
|
+
assembly {
|
|
133
|
+
tokenCodeSize := extcodesize(token)
|
|
134
|
+
}
|
|
135
|
+
require(tokenCodeSize > 0, "StdUtils getTokenBalances(address,address[]): Token address is not a contract.");
|
|
136
|
+
|
|
137
|
+
// ABI encode the aggregate call to Multicall3.
|
|
138
|
+
uint256 length = addresses.length;
|
|
139
|
+
IMulticall3.Call[] memory calls = new IMulticall3.Call[](length);
|
|
140
|
+
for (uint256 i = 0; i < length; ++i) {
|
|
141
|
+
// 0x70a08231 = bytes4(keccak256("balanceOf(address)"))
|
|
142
|
+
calls[i] = IMulticall3.Call({target: token, callData: abi.encodeWithSelector(0x70a08231, (addresses[i]))});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Make the aggregate call.
|
|
146
|
+
(, bytes[] memory returnData) = StdConstants.MULTICALL3_ADDRESS.aggregate(calls);
|
|
147
|
+
|
|
148
|
+
// ABI decode the return data and return the balances.
|
|
149
|
+
balances = new uint256[](length);
|
|
150
|
+
for (uint256 i = 0; i < length; ++i) {
|
|
151
|
+
balances[i] = abi.decode(returnData[i], (uint256));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/*//////////////////////////////////////////////////////////////////////////
|
|
156
|
+
PRIVATE FUNCTIONS
|
|
157
|
+
//////////////////////////////////////////////////////////////////////////*/
|
|
158
|
+
|
|
159
|
+
function addressFromLast20Bytes(bytes32 bytesValue) private pure returns (address) {
|
|
160
|
+
return address(uint160(uint256(bytesValue)));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// This section is used to prevent the compilation of console, which shortens the compilation time when console is
|
|
164
|
+
// not used elsewhere. We also trick the compiler into letting us make the console log methods as `pure` to avoid
|
|
165
|
+
// any breaking changes to function signatures.
|
|
166
|
+
function _castLogPayloadViewToPure(function(bytes memory) internal view fnIn)
|
|
167
|
+
internal
|
|
168
|
+
pure
|
|
169
|
+
returns (function(bytes memory) internal pure fnOut)
|
|
170
|
+
{
|
|
171
|
+
assembly {
|
|
172
|
+
fnOut := fnIn
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function _sendLogPayload(bytes memory payload) internal pure {
|
|
177
|
+
_castLogPayloadViewToPure(_sendLogPayloadView)(payload);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function _sendLogPayloadView(bytes memory payload) private view {
|
|
181
|
+
uint256 payloadLength = payload.length;
|
|
182
|
+
address consoleAddress = CONSOLE2_ADDRESS;
|
|
183
|
+
assembly ("memory-safe") {
|
|
184
|
+
let payloadStart := add(payload, 32)
|
|
185
|
+
let r := staticcall(gas(), consoleAddress, payloadStart, payloadLength, 0, 0)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function console2_log_StdUtils(string memory p0) private pure {
|
|
190
|
+
_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function console2_log_StdUtils(string memory p0, uint256 p1) private pure {
|
|
194
|
+
_sendLogPayload(abi.encodeWithSignature("log(string,uint256)", p0, p1));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function console2_log_StdUtils(string memory p0, string memory p1) private pure {
|
|
198
|
+
_sendLogPayload(abi.encodeWithSignature("log(string,string)", p0, p1));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
pragma solidity >=0.8.13 <0.9.0;
|
|
3
|
+
|
|
4
|
+
// 💬 ABOUT
|
|
5
|
+
// Forge Std's default Test.
|
|
6
|
+
|
|
7
|
+
// 🧩 MODULES
|
|
8
|
+
import {console} from "./console.sol";
|
|
9
|
+
import {console2} from "./console2.sol";
|
|
10
|
+
import {safeconsole} from "./safeconsole.sol";
|
|
11
|
+
import {StdAssertions} from "./StdAssertions.sol";
|
|
12
|
+
import {StdChains} from "./StdChains.sol";
|
|
13
|
+
import {StdCheats} from "./StdCheats.sol";
|
|
14
|
+
import {StdConstants} from "./StdConstants.sol";
|
|
15
|
+
import {stdError} from "./StdError.sol";
|
|
16
|
+
import {StdInvariant} from "./StdInvariant.sol";
|
|
17
|
+
import {stdJson} from "./StdJson.sol";
|
|
18
|
+
import {stdMath} from "./StdMath.sol";
|
|
19
|
+
import {StdStorage, stdStorage} from "./StdStorage.sol";
|
|
20
|
+
import {StdStyle} from "./StdStyle.sol";
|
|
21
|
+
import {stdToml} from "./StdToml.sol";
|
|
22
|
+
import {StdUtils} from "./StdUtils.sol";
|
|
23
|
+
import {Vm} from "./Vm.sol";
|
|
24
|
+
|
|
25
|
+
// 📦 BOILERPLATE
|
|
26
|
+
import {TestBase} from "./Base.sol";
|
|
27
|
+
|
|
28
|
+
// ⭐️ TEST
|
|
29
|
+
abstract contract Test is TestBase, StdAssertions, StdChains, StdCheats, StdInvariant, StdUtils {
|
|
30
|
+
// Note: IS_TEST() must return true.
|
|
31
|
+
bool public IS_TEST = true;
|
|
32
|
+
}
|