@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.
Files changed (81) hide show
  1. package/.devcontainer/Dockerfile +117 -0
  2. package/.devcontainer/devcontainer.json +62 -0
  3. package/.devcontainer/init-firewall.sh +118 -0
  4. package/.github/workflows/test.yml +38 -0
  5. package/.gitmodules +3 -0
  6. package/CLAUDE.md +39 -0
  7. package/README.md +33 -0
  8. package/foundry.lock +8 -0
  9. package/foundry.toml +6 -0
  10. package/index.ts +97 -0
  11. package/lib/forge-std/.gitattributes +1 -0
  12. package/lib/forge-std/.github/CODEOWNERS +1 -0
  13. package/lib/forge-std/.github/dependabot.yml +6 -0
  14. package/lib/forge-std/.github/workflows/ci.yml +125 -0
  15. package/lib/forge-std/.github/workflows/sync.yml +36 -0
  16. package/lib/forge-std/CONTRIBUTING.md +193 -0
  17. package/lib/forge-std/LICENSE-APACHE +203 -0
  18. package/lib/forge-std/LICENSE-MIT +25 -0
  19. package/lib/forge-std/README.md +314 -0
  20. package/lib/forge-std/RELEASE_CHECKLIST.md +12 -0
  21. package/lib/forge-std/foundry.toml +18 -0
  22. package/lib/forge-std/package.json +16 -0
  23. package/lib/forge-std/scripts/vm.py +636 -0
  24. package/lib/forge-std/src/Base.sol +48 -0
  25. package/lib/forge-std/src/Config.sol +60 -0
  26. package/lib/forge-std/src/LibVariable.sol +477 -0
  27. package/lib/forge-std/src/Script.sol +28 -0
  28. package/lib/forge-std/src/StdAssertions.sol +779 -0
  29. package/lib/forge-std/src/StdChains.sol +303 -0
  30. package/lib/forge-std/src/StdCheats.sol +825 -0
  31. package/lib/forge-std/src/StdConfig.sol +632 -0
  32. package/lib/forge-std/src/StdConstants.sol +30 -0
  33. package/lib/forge-std/src/StdError.sol +15 -0
  34. package/lib/forge-std/src/StdInvariant.sol +140 -0
  35. package/lib/forge-std/src/StdJson.sol +275 -0
  36. package/lib/forge-std/src/StdMath.sol +47 -0
  37. package/lib/forge-std/src/StdStorage.sol +475 -0
  38. package/lib/forge-std/src/StdStyle.sol +333 -0
  39. package/lib/forge-std/src/StdToml.sol +275 -0
  40. package/lib/forge-std/src/StdUtils.sol +200 -0
  41. package/lib/forge-std/src/Test.sol +32 -0
  42. package/lib/forge-std/src/Vm.sol +2533 -0
  43. package/lib/forge-std/src/console.sol +1551 -0
  44. package/lib/forge-std/src/console2.sol +4 -0
  45. package/lib/forge-std/src/interfaces/IERC1155.sol +105 -0
  46. package/lib/forge-std/src/interfaces/IERC165.sol +12 -0
  47. package/lib/forge-std/src/interfaces/IERC20.sol +43 -0
  48. package/lib/forge-std/src/interfaces/IERC4626.sol +190 -0
  49. package/lib/forge-std/src/interfaces/IERC6909.sol +72 -0
  50. package/lib/forge-std/src/interfaces/IERC721.sol +164 -0
  51. package/lib/forge-std/src/interfaces/IERC7540.sol +144 -0
  52. package/lib/forge-std/src/interfaces/IERC7575.sol +241 -0
  53. package/lib/forge-std/src/interfaces/IMulticall3.sol +68 -0
  54. package/lib/forge-std/src/safeconsole.sol +13248 -0
  55. package/lib/forge-std/test/CommonBase.t.sol +44 -0
  56. package/lib/forge-std/test/Config.t.sol +381 -0
  57. package/lib/forge-std/test/LibVariable.t.sol +452 -0
  58. package/lib/forge-std/test/StdAssertions.t.sol +141 -0
  59. package/lib/forge-std/test/StdChains.t.sol +227 -0
  60. package/lib/forge-std/test/StdCheats.t.sol +638 -0
  61. package/lib/forge-std/test/StdConstants.t.sol +38 -0
  62. package/lib/forge-std/test/StdError.t.sol +119 -0
  63. package/lib/forge-std/test/StdJson.t.sol +49 -0
  64. package/lib/forge-std/test/StdMath.t.sol +202 -0
  65. package/lib/forge-std/test/StdStorage.t.sol +485 -0
  66. package/lib/forge-std/test/StdStyle.t.sol +110 -0
  67. package/lib/forge-std/test/StdToml.t.sol +49 -0
  68. package/lib/forge-std/test/StdUtils.t.sol +342 -0
  69. package/lib/forge-std/test/Vm.t.sol +18 -0
  70. package/lib/forge-std/test/compilation/CompilationScript.sol +8 -0
  71. package/lib/forge-std/test/compilation/CompilationScriptBase.sol +8 -0
  72. package/lib/forge-std/test/compilation/CompilationTest.sol +8 -0
  73. package/lib/forge-std/test/compilation/CompilationTestBase.sol +8 -0
  74. package/lib/forge-std/test/fixtures/broadcast.log.json +187 -0
  75. package/lib/forge-std/test/fixtures/config.toml +81 -0
  76. package/lib/forge-std/test/fixtures/test.json +8 -0
  77. package/lib/forge-std/test/fixtures/test.toml +6 -0
  78. package/package.json +10 -0
  79. package/script/Counter.s.sol +19 -0
  80. package/src/Counter.sol +14 -0
  81. package/test/Counter.t.sol +24 -0
@@ -0,0 +1,638 @@
1
+ // SPDX-License-Identifier: MIT OR Apache-2.0
2
+ pragma solidity >=0.8.13 <0.9.0;
3
+
4
+ import {StdCheats} from "../src/StdCheats.sol";
5
+ import {Test} from "../src/Test.sol";
6
+ import {stdJson} from "../src/StdJson.sol";
7
+ import {stdToml} from "../src/StdToml.sol";
8
+ import {IERC20} from "../src/interfaces/IERC20.sol";
9
+
10
+ contract StdCheatsTest is Test {
11
+ Bar test;
12
+
13
+ using stdJson for string;
14
+
15
+ function setUp() public {
16
+ test = new Bar();
17
+ }
18
+
19
+ function test_Skip() public {
20
+ vm.warp(100);
21
+ skip(25);
22
+ assertEq(block.timestamp, 125);
23
+ }
24
+
25
+ function test_Rewind() public {
26
+ vm.warp(100);
27
+ rewind(25);
28
+ assertEq(block.timestamp, 75);
29
+ }
30
+
31
+ function test_Hoax() public {
32
+ hoax(address(1337));
33
+ test.bar{value: 100}(address(1337));
34
+ }
35
+
36
+ function test_HoaxOrigin() public {
37
+ hoax(address(1337), address(1337));
38
+ test.origin{value: 100}(address(1337));
39
+ }
40
+
41
+ function test_HoaxDifferentAddresses() public {
42
+ hoax(address(1337), address(7331));
43
+ test.origin{value: 100}(address(1337), address(7331));
44
+ }
45
+
46
+ function test_StartHoax() public {
47
+ startHoax(address(1337));
48
+ test.bar{value: 100}(address(1337));
49
+ test.bar{value: 100}(address(1337));
50
+ vm.stopPrank();
51
+ test.bar(address(this));
52
+ }
53
+
54
+ function test_StartHoaxOrigin() public {
55
+ startHoax(address(1337), address(1337));
56
+ test.origin{value: 100}(address(1337));
57
+ test.origin{value: 100}(address(1337));
58
+ vm.stopPrank();
59
+ test.bar(address(this));
60
+ }
61
+
62
+ function test_ChangePrankMsgSender() public {
63
+ vm.startPrank(address(1337));
64
+ test.bar(address(1337));
65
+ changePrank(address(0xdead));
66
+ test.bar(address(0xdead));
67
+ changePrank(address(1337));
68
+ test.bar(address(1337));
69
+ vm.stopPrank();
70
+ }
71
+
72
+ function test_ChangePrankMsgSenderAndTxOrigin() public {
73
+ vm.startPrank(address(1337), address(1338));
74
+ test.origin(address(1337), address(1338));
75
+ changePrank(address(0xdead), address(0xbeef));
76
+ test.origin(address(0xdead), address(0xbeef));
77
+ changePrank(address(1337), address(1338));
78
+ test.origin(address(1337), address(1338));
79
+ vm.stopPrank();
80
+ }
81
+
82
+ function test_MakeAccountEquivalence() public {
83
+ Account memory account = makeAccount("1337");
84
+ (address addr, uint256 key) = makeAddrAndKey("1337");
85
+ assertEq(account.addr, addr);
86
+ assertEq(account.key, key);
87
+ }
88
+
89
+ function test_MakeAddrEquivalence() public {
90
+ (address addr,) = makeAddrAndKey("1337");
91
+ assertEq(makeAddr("1337"), addr);
92
+ }
93
+
94
+ function test_MakeAddrSigning() public {
95
+ (address addr, uint256 key) = makeAddrAndKey("1337");
96
+ bytes32 hash = keccak256("some_message");
97
+
98
+ (uint8 v, bytes32 r, bytes32 s) = vm.sign(key, hash);
99
+ assertEq(ecrecover(hash, v, r, s), addr);
100
+ }
101
+
102
+ function test_Deal() public {
103
+ deal(address(this), 1 ether);
104
+ assertEq(address(this).balance, 1 ether);
105
+ }
106
+
107
+ function test_DealToken() public {
108
+ Bar barToken = new Bar();
109
+ address bar = address(barToken);
110
+ deal(bar, address(this), 10000e18);
111
+ assertEq(barToken.balanceOf(address(this)), 10000e18);
112
+ }
113
+
114
+ function test_DealTokenAdjustTotalSupply() public {
115
+ Bar barToken = new Bar();
116
+ address bar = address(barToken);
117
+ deal(bar, address(this), 10000e18, true);
118
+ assertEq(barToken.balanceOf(address(this)), 10000e18);
119
+ assertEq(barToken.totalSupply(), 20000e18);
120
+ deal(bar, address(this), 0, true);
121
+ assertEq(barToken.balanceOf(address(this)), 0);
122
+ assertEq(barToken.totalSupply(), 10000e18);
123
+ }
124
+
125
+ function test_DealERC1155Token() public {
126
+ BarERC1155 barToken = new BarERC1155();
127
+ address bar = address(barToken);
128
+ dealERC1155(bar, address(this), 0, 10000e18, false);
129
+ assertEq(barToken.balanceOf(address(this), 0), 10000e18);
130
+ }
131
+
132
+ function test_DealERC1155TokenAdjustTotalSupply() public {
133
+ BarERC1155 barToken = new BarERC1155();
134
+ address bar = address(barToken);
135
+ dealERC1155(bar, address(this), 0, 10000e18, true);
136
+ assertEq(barToken.balanceOf(address(this), 0), 10000e18);
137
+ assertEq(barToken.totalSupply(0), 20000e18);
138
+ dealERC1155(bar, address(this), 0, 0, true);
139
+ assertEq(barToken.balanceOf(address(this), 0), 0);
140
+ assertEq(barToken.totalSupply(0), 10000e18);
141
+ }
142
+
143
+ function test_DealERC721Token() public {
144
+ BarERC721 barToken = new BarERC721();
145
+ address bar = address(barToken);
146
+ dealERC721(bar, address(2), 1);
147
+ assertEq(barToken.balanceOf(address(2)), 1);
148
+ assertEq(barToken.balanceOf(address(1)), 0);
149
+ dealERC721(bar, address(1), 2);
150
+ assertEq(barToken.balanceOf(address(1)), 1);
151
+ assertEq(barToken.balanceOf(bar), 1);
152
+ }
153
+
154
+ function test_DeployCode() public {
155
+ address deployed = deployCode("StdCheats.t.sol:Bar", bytes(""));
156
+ assertEq(string(getCode(deployed)), string(getCode(address(test))));
157
+ }
158
+
159
+ function test_DestroyAccount() public {
160
+ // deploy something to destroy it
161
+ BarERC721 barToken = new BarERC721();
162
+ address bar = address(barToken);
163
+ vm.setNonce(bar, 10);
164
+ deal(bar, 100);
165
+
166
+ uint256 prevThisBalance = address(this).balance;
167
+ uint256 size;
168
+ assembly {
169
+ size := extcodesize(bar)
170
+ }
171
+
172
+ assertGt(size, 0);
173
+ assertEq(bar.balance, 100);
174
+ assertEq(vm.getNonce(bar), 10);
175
+
176
+ destroyAccount(bar, address(this));
177
+ assembly {
178
+ size := extcodesize(bar)
179
+ }
180
+ assertEq(address(this).balance, prevThisBalance + 100);
181
+ assertEq(vm.getNonce(bar), 0);
182
+ assertEq(size, 0);
183
+ assertEq(bar.balance, 0);
184
+ }
185
+
186
+ function test_DeployCodeNoArgs() public {
187
+ address deployed = deployCode("StdCheats.t.sol:Bar");
188
+ assertEq(string(getCode(deployed)), string(getCode(address(test))));
189
+ }
190
+
191
+ function test_DeployCodeVal() public {
192
+ address deployed = deployCode("StdCheats.t.sol:Bar", bytes(""), 1 ether);
193
+ assertEq(string(getCode(deployed)), string(getCode(address(test))));
194
+ assertEq(deployed.balance, 1 ether);
195
+ }
196
+
197
+ function test_DeployCodeValNoArgs() public {
198
+ address deployed = deployCode("StdCheats.t.sol:Bar", 1 ether);
199
+ assertEq(string(getCode(deployed)), string(getCode(address(test))));
200
+ assertEq(deployed.balance, 1 ether);
201
+ }
202
+
203
+ // We need this so we can call "this.deployCode" rather than "deployCode" directly
204
+ function deployCodeHelper(string memory what) external {
205
+ deployCode(what);
206
+ }
207
+
208
+ function test_RevertIf_DeployCodeFail() public {
209
+ vm.expectRevert(bytes("StdCheats deployCode(string): Deployment failed."));
210
+ this.deployCodeHelper("StdCheats.t.sol:RevertingContract");
211
+ }
212
+
213
+ function getCode(address who) internal view returns (bytes memory o_code) {
214
+ assembly ("memory-safe") {
215
+ // retrieve the size of the code, this needs assembly
216
+ let size := extcodesize(who)
217
+ // allocate output byte array - this could also be done without assembly
218
+ // by using o_code = new bytes(size)
219
+ o_code := mload(0x40)
220
+ // new "memory end" including padding
221
+ mstore(0x40, add(o_code, and(add(add(size, 0x20), 0x1f), not(0x1f))))
222
+ // store length in memory
223
+ mstore(o_code, size)
224
+ // actually retrieve the code, this needs assembly
225
+ extcodecopy(who, add(o_code, 0x20), 0, size)
226
+ }
227
+ }
228
+
229
+ function test_DeriveRememberKey() public {
230
+ string memory mnemonic = "test test test test test test test test test test test junk";
231
+
232
+ (address deployer, uint256 privateKey) = deriveRememberKey(mnemonic, 0);
233
+ assertEq(deployer, 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266);
234
+ assertEq(privateKey, 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80);
235
+ }
236
+
237
+ function test_BytesToUint() public pure {
238
+ assertEq(3, bytesToUint_test(hex"03"));
239
+ assertEq(2, bytesToUint_test(hex"02"));
240
+ assertEq(255, bytesToUint_test(hex"ff"));
241
+ assertEq(29625, bytesToUint_test(hex"73b9"));
242
+ }
243
+
244
+ function test_ParseJsonTxDetail() public view {
245
+ string memory root = vm.projectRoot();
246
+ string memory path = string.concat(root, "/test/fixtures/broadcast.log.json");
247
+ string memory json = vm.readFile(path);
248
+ bytes memory transactionDetails = json.parseRaw(".transactions[0].tx");
249
+ RawTx1559Detail memory rawTxDetail = abi.decode(transactionDetails, (RawTx1559Detail));
250
+ Tx1559Detail memory txDetail = rawToConvertedEIP1559Detail(rawTxDetail);
251
+ assertEq(txDetail.from, 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266);
252
+ assertEq(txDetail.to, 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512);
253
+ assertEq(
254
+ txDetail.data,
255
+ hex"23e99187000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000013370000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004"
256
+ );
257
+ assertEq(txDetail.nonce, 3);
258
+ assertEq(txDetail.txType, 2);
259
+ assertEq(txDetail.gas, 29625);
260
+ assertEq(txDetail.value, 0);
261
+ }
262
+
263
+ function test_ReadEIP1559Transaction() public view {
264
+ string memory root = vm.projectRoot();
265
+ string memory path = string.concat(root, "/test/fixtures/broadcast.log.json");
266
+ uint256 index = 0;
267
+ Tx1559 memory transaction = readTx1559(path, index);
268
+ transaction;
269
+ }
270
+
271
+ function test_ReadEIP1559Transactions() public view {
272
+ string memory root = vm.projectRoot();
273
+ string memory path = string.concat(root, "/test/fixtures/broadcast.log.json");
274
+ Tx1559[] memory transactions = readTx1559s(path);
275
+ transactions;
276
+ }
277
+
278
+ function test_ReadReceipt() public view {
279
+ string memory root = vm.projectRoot();
280
+ string memory path = string.concat(root, "/test/fixtures/broadcast.log.json");
281
+ uint256 index = 5;
282
+ Receipt memory receipt = readReceipt(path, index);
283
+ assertEq(
284
+ receipt.logsBloom,
285
+ hex"00000000000800000000000000000010000000000000000000000000000180000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100"
286
+ );
287
+ }
288
+
289
+ function test_ReadReceipts() public view {
290
+ string memory root = vm.projectRoot();
291
+ string memory path = string.concat(root, "/test/fixtures/broadcast.log.json");
292
+ Receipt[] memory receipts = readReceipts(path);
293
+ receipts;
294
+ }
295
+
296
+ function test_GasMeteringModifier() public {
297
+ uint256 gas_start_normal = gasleft();
298
+ addInLoop();
299
+ uint256 gas_used_normal = gas_start_normal - gasleft();
300
+
301
+ uint256 gas_start_single = gasleft();
302
+ addInLoopNoGas();
303
+ uint256 gas_used_single = gas_start_single - gasleft();
304
+
305
+ uint256 gas_start_double = gasleft();
306
+ addInLoopNoGasNoGas();
307
+ uint256 gas_used_double = gas_start_double - gasleft();
308
+
309
+ assertTrue(gas_used_double + gas_used_single < gas_used_normal);
310
+ }
311
+
312
+ function addInLoop() internal pure returns (uint256) {
313
+ uint256 b;
314
+ for (uint256 i; i < 10000; i++) {
315
+ b += i;
316
+ }
317
+ return b;
318
+ }
319
+
320
+ function addInLoopNoGas() internal noGasMetering returns (uint256) {
321
+ return addInLoop();
322
+ }
323
+
324
+ function addInLoopNoGasNoGas() internal noGasMetering returns (uint256) {
325
+ return addInLoopNoGas();
326
+ }
327
+
328
+ function bytesToUint_test(bytes memory b) private pure returns (uint256) {
329
+ uint256 number;
330
+ for (uint256 i = 0; i < b.length; i++) {
331
+ number = number + uint256(uint8(b[i])) * (2 ** (8 * (b.length - (i + 1))));
332
+ }
333
+ return number;
334
+ }
335
+
336
+ function testFuzz_AssumeAddressIsNot(address addr) external {
337
+ // skip over Payable and NonPayable enums
338
+ for (uint8 i = 2; i < uint8(type(AddressType).max); i++) {
339
+ assumeAddressIsNot(addr, AddressType(i));
340
+ }
341
+ assertTrue(addr != address(0));
342
+ assertTrue(addr < address(1) || addr > address(9));
343
+ assertTrue(addr != address(vm) || addr != 0x000000000000000000636F6e736F6c652e6c6f67);
344
+ }
345
+
346
+ function test_AssumePayable() external {
347
+ // We deploy a mock version so we can properly test the revert.
348
+ StdCheatsMock stdCheatsMock = new StdCheatsMock();
349
+
350
+ // all should revert since these addresses are not payable
351
+
352
+ // VM address
353
+ vm.expectRevert();
354
+ stdCheatsMock.exposedAssumePayable(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
355
+
356
+ // Console address
357
+ vm.expectRevert();
358
+ stdCheatsMock.exposedAssumePayable(0x000000000000000000636F6e736F6c652e6c6f67);
359
+
360
+ // Create2Deployer
361
+ vm.expectRevert();
362
+ stdCheatsMock.exposedAssumePayable(0x4e59b44847b379578588920cA78FbF26c0B4956C);
363
+
364
+ // all should pass since these addresses are payable
365
+
366
+ // vitalik.eth
367
+ stdCheatsMock.exposedAssumePayable(0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045);
368
+
369
+ // mock payable contract
370
+ MockContractPayable cp = new MockContractPayable();
371
+ stdCheatsMock.exposedAssumePayable(address(cp));
372
+ }
373
+
374
+ function test_AssumeNotPayable() external {
375
+ // We deploy a mock version so we can properly test the revert.
376
+ StdCheatsMock stdCheatsMock = new StdCheatsMock();
377
+
378
+ // all should pass since these addresses are not payable
379
+
380
+ // VM address
381
+ stdCheatsMock.exposedAssumeNotPayable(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
382
+
383
+ // Console address
384
+ stdCheatsMock.exposedAssumeNotPayable(0x000000000000000000636F6e736F6c652e6c6f67);
385
+
386
+ // Create2Deployer
387
+ stdCheatsMock.exposedAssumeNotPayable(0x4e59b44847b379578588920cA78FbF26c0B4956C);
388
+
389
+ // all should revert since these addresses are payable
390
+
391
+ // vitalik.eth
392
+ vm.expectRevert();
393
+ stdCheatsMock.exposedAssumeNotPayable(0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045);
394
+
395
+ // mock payable contract
396
+ MockContractPayable cp = new MockContractPayable();
397
+ vm.expectRevert();
398
+ stdCheatsMock.exposedAssumeNotPayable(address(cp));
399
+ }
400
+
401
+ function testFuzz_AssumeNotPrecompile(address addr) external {
402
+ assumeNotPrecompile(addr, getChain("optimism_sepolia").chainId);
403
+ assertTrue(
404
+ addr < address(1) || (addr > address(9) && addr < address(0x4200000000000000000000000000000000000000))
405
+ || addr > address(0x4200000000000000000000000000000000000800)
406
+ );
407
+ }
408
+
409
+ function testFuzz_AssumeNotForgeAddress(address addr) external pure {
410
+ assumeNotForgeAddress(addr);
411
+ assertTrue(
412
+ addr != address(vm) && addr != 0x000000000000000000636F6e736F6c652e6c6f67
413
+ && addr != 0x4e59b44847b379578588920cA78FbF26c0B4956C
414
+ );
415
+ }
416
+
417
+ function test_RevertIf_CannotDeployCodeTo() external {
418
+ vm.expectRevert("StdCheats deployCodeTo(string,bytes,uint256,address): Failed to create runtime bytecode.");
419
+ this._revertDeployCodeTo();
420
+ }
421
+
422
+ function _revertDeployCodeTo() external {
423
+ deployCodeTo("StdCheats.t.sol:RevertingContract", address(0));
424
+ }
425
+
426
+ function test_DeployCodeTo() external {
427
+ address arbitraryAddress = makeAddr("arbitraryAddress");
428
+
429
+ deployCodeTo(
430
+ "StdCheats.t.sol:MockContractWithConstructorArgs",
431
+ abi.encode(uint256(6), true, bytes20(arbitraryAddress)),
432
+ 1 ether,
433
+ arbitraryAddress
434
+ );
435
+
436
+ MockContractWithConstructorArgs ct = MockContractWithConstructorArgs(arbitraryAddress);
437
+
438
+ assertEq(arbitraryAddress.balance, 1 ether);
439
+ assertEq(ct.x(), 6);
440
+ assertTrue(ct.y());
441
+ assertEq(ct.z(), bytes20(arbitraryAddress));
442
+ }
443
+ }
444
+
445
+ contract StdCheatsMock is StdCheats {
446
+ function exposedAssumePayable(address addr) external {
447
+ assumePayable(addr);
448
+ }
449
+
450
+ function exposedAssumeNotPayable(address addr) external {
451
+ assumeNotPayable(addr);
452
+ }
453
+
454
+ // We deploy a mock version so we can properly test expected reverts.
455
+ function exposedAssumeNotBlacklisted(address token, address addr) external view {
456
+ return assumeNotBlacklisted(token, addr);
457
+ }
458
+ }
459
+
460
+ contract StdCheatsForkTest is Test {
461
+ address internal constant USDC_BLACKLISTED_USER = 0x1E34A77868E19A6647b1f2F47B51ed72dEDE95DD;
462
+ address internal constant USDT_BLACKLISTED_USER = 0x8f8a8F4B54a2aAC7799d7bc81368aC27b852822A;
463
+
464
+ MockUSDT public USDT;
465
+ MockUSDC public USDC;
466
+
467
+ function setUp() public {
468
+ USDT = new MockUSDT();
469
+ USDC = new MockUSDC();
470
+
471
+ USDC.setBlacklisted(USDC_BLACKLISTED_USER, true);
472
+ USDT.setBlacklisted(USDT_BLACKLISTED_USER, true);
473
+ }
474
+
475
+ function test_RevertIf_CannotAssumeNoBlacklisted_EOA() external {
476
+ // We deploy a mock version so we can properly test the revert.
477
+ StdCheatsMock stdCheatsMock = new StdCheatsMock();
478
+ address eoa = vm.addr({privateKey: 1});
479
+ vm.expectRevert("StdCheats assumeNotBlacklisted(address,address): Token address is not a contract.");
480
+ stdCheatsMock.exposedAssumeNotBlacklisted(eoa, address(0));
481
+ }
482
+
483
+ function testFuzz_AssumeNotBlacklisted_TokenWithoutBlacklist(address addr) external view {
484
+ assumeNotBlacklisted(address(USDC), addr);
485
+ assumeNotBlacklisted(address(USDT), addr);
486
+ assertTrue(true);
487
+ }
488
+
489
+ function test_RevertIf_AssumeNoBlacklisted_USDC() external {
490
+ // We deploy a mock version so we can properly test the revert.
491
+ StdCheatsMock stdCheatsMock = new StdCheatsMock();
492
+ vm.expectRevert();
493
+ stdCheatsMock.exposedAssumeNotBlacklisted(address(USDC), USDC_BLACKLISTED_USER);
494
+ }
495
+
496
+ function testFuzz_AssumeNotBlacklisted_USDC(address addr) external view {
497
+ assumeNotBlacklisted(address(USDC), addr);
498
+ assertFalse(USDCLike(USDC).isBlacklisted(addr));
499
+ }
500
+
501
+ function test_RevertIf_AssumeNoBlacklisted_USDT() external {
502
+ // We deploy a mock version so we can properly test the revert.
503
+ StdCheatsMock stdCheatsMock = new StdCheatsMock();
504
+ vm.expectRevert();
505
+ stdCheatsMock.exposedAssumeNotBlacklisted(address(USDT), USDT_BLACKLISTED_USER);
506
+ }
507
+
508
+ function testFuzz_AssumeNotBlacklisted_USDT(address addr) external view {
509
+ assumeNotBlacklisted(address(USDT), addr);
510
+ assertFalse(USDTLike(USDT).isBlackListed(addr));
511
+ }
512
+ }
513
+
514
+ /// @dev https://etherscan.io/token/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48#readProxyContract
515
+ interface USDCLike {
516
+ function isBlacklisted(address) external view returns (bool);
517
+ }
518
+
519
+ /// @dev https://etherscan.io/token/0xdac17f958d2ee523a2206206994597c13d831ec7#readContract
520
+ interface USDTLike {
521
+ function isBlackListed(address) external view returns (bool);
522
+ }
523
+
524
+ contract MockUSDT is USDTLike {
525
+ mapping(address => bool) private blacklist;
526
+
527
+ function isBlackListed(address addr) external view returns (bool) {
528
+ return blacklist[addr];
529
+ }
530
+
531
+ function setBlacklisted(address addr, bool value) external {
532
+ blacklist[addr] = value;
533
+ }
534
+ }
535
+
536
+ contract MockUSDC is USDCLike {
537
+ mapping(address => bool) private blacklist;
538
+
539
+ function isBlacklisted(address addr) external view returns (bool) {
540
+ return blacklist[addr];
541
+ }
542
+
543
+ function setBlacklisted(address addr, bool value) external {
544
+ blacklist[addr] = value;
545
+ }
546
+ }
547
+
548
+ contract Bar {
549
+ constructor() payable {
550
+ /// `DEAL` STDCHEAT
551
+ totalSupply = 10000e18;
552
+ balanceOf[address(this)] = totalSupply;
553
+ }
554
+
555
+ /// `HOAX` and `CHANGEPRANK` STDCHEATS
556
+ function bar(address expectedSender) public payable {
557
+ require(msg.sender == expectedSender, "!prank");
558
+ }
559
+
560
+ function origin(address expectedSender) public payable {
561
+ require(msg.sender == expectedSender, "!prank");
562
+ require(tx.origin == expectedSender, "!prank");
563
+ }
564
+
565
+ function origin(address expectedSender, address expectedOrigin) public payable {
566
+ require(msg.sender == expectedSender, "!prank");
567
+ require(tx.origin == expectedOrigin, "!prank");
568
+ }
569
+
570
+ /// `DEAL` STDCHEAT
571
+ mapping(address => uint256) public balanceOf;
572
+ uint256 public totalSupply;
573
+ }
574
+
575
+ contract BarERC1155 {
576
+ constructor() payable {
577
+ /// `DEALERC1155` STDCHEAT
578
+ _totalSupply[0] = 10000e18;
579
+ _balances[0][address(this)] = _totalSupply[0];
580
+ }
581
+
582
+ function balanceOf(address account, uint256 id) public view virtual returns (uint256) {
583
+ return _balances[id][account];
584
+ }
585
+
586
+ function totalSupply(uint256 id) public view virtual returns (uint256) {
587
+ return _totalSupply[id];
588
+ }
589
+
590
+ /// `DEALERC1155` STDCHEAT
591
+ mapping(uint256 => mapping(address => uint256)) private _balances;
592
+ mapping(uint256 => uint256) private _totalSupply;
593
+ }
594
+
595
+ contract BarERC721 {
596
+ constructor() payable {
597
+ /// `DEALERC721` STDCHEAT
598
+ _owners[1] = address(1);
599
+ _balances[address(1)] = 1;
600
+ _owners[2] = address(this);
601
+ _owners[3] = address(this);
602
+ _balances[address(this)] = 2;
603
+ }
604
+
605
+ function balanceOf(address owner) public view virtual returns (uint256) {
606
+ return _balances[owner];
607
+ }
608
+
609
+ function ownerOf(uint256 tokenId) public view virtual returns (address) {
610
+ address owner = _owners[tokenId];
611
+ return owner;
612
+ }
613
+
614
+ mapping(uint256 => address) private _owners;
615
+ mapping(address => uint256) private _balances;
616
+ }
617
+
618
+ contract RevertingContract {
619
+ constructor() {
620
+ revert();
621
+ }
622
+ }
623
+
624
+ contract MockContractWithConstructorArgs {
625
+ uint256 public immutable x;
626
+ bool public y;
627
+ bytes20 public z;
628
+
629
+ constructor(uint256 _x, bool _y, bytes20 _z) payable {
630
+ x = _x;
631
+ y = _y;
632
+ z = _z;
633
+ }
634
+ }
635
+
636
+ contract MockContractPayable {
637
+ receive() external payable {}
638
+ }
@@ -0,0 +1,38 @@
1
+ // SPDX-License-Identifier: MIT OR Apache-2.0
2
+ pragma solidity >=0.8.13 <0.9.0;
3
+
4
+ import {StdConstants} from "../src/StdConstants.sol";
5
+ import {Test} from "../src/Test.sol";
6
+
7
+ contract StdConstantsTest is Test {
8
+ function testVm() public view {
9
+ assertEq(StdConstants.VM.getBlockNumber(), 1);
10
+ }
11
+
12
+ function testVmDerivation() public pure {
13
+ assertEq(address(StdConstants.VM), address(uint160(uint256(keccak256("hevm cheat code")))));
14
+ }
15
+
16
+ function testConsoleDerivation() public pure {
17
+ assertEq(StdConstants.CONSOLE, address(uint160(uint88(bytes11("console.log")))));
18
+ }
19
+
20
+ function testDefaultSender() public view {
21
+ assertEq(StdConstants.DEFAULT_SENDER, msg.sender);
22
+ }
23
+
24
+ function testDefaultSenderDerivation() public pure {
25
+ assertEq(StdConstants.DEFAULT_SENDER, address(uint160(uint256(keccak256("foundry default caller")))));
26
+ }
27
+
28
+ function testDefaultTestContract() public {
29
+ assertEq(StdConstants.DEFAULT_TEST_CONTRACT, address(new Dummy()));
30
+ }
31
+
32
+ function testDefaultTestContractDerivation() public view {
33
+ assertEq(address(this), StdConstants.VM.computeCreateAddress(StdConstants.DEFAULT_SENDER, 1));
34
+ assertEq(StdConstants.DEFAULT_TEST_CONTRACT, StdConstants.VM.computeCreateAddress(address(this), 1));
35
+ }
36
+ }
37
+
38
+ contract Dummy {}