@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,60 @@
1
+ // SPDX-License-Identifier: MIT OR Apache-2.0
2
+ pragma solidity ^0.8.13;
3
+
4
+ import {console} from "./console.sol";
5
+ import {StdConfig} from "./StdConfig.sol";
6
+ import {CommonBase} from "./Base.sol";
7
+
8
+ /// @notice Boilerplate to streamline the setup of multi-chain environments.
9
+ abstract contract Config is CommonBase {
10
+ // -- STORAGE (CONFIG + CHAINS + FORKS) ------------------------------------
11
+
12
+ /// @dev Contract instance holding the data from the TOML config file.
13
+ StdConfig internal config;
14
+
15
+ /// @dev Array of chain IDs for which forks have been created.
16
+ uint256[] internal chainIds;
17
+
18
+ /// @dev A mapping from a chain ID to its initialized fork ID.
19
+ mapping(uint256 => uint256) internal forkOf;
20
+
21
+ // -- HELPER FUNCTIONS -----------------------------------------------------
22
+
23
+ /// @notice Loads configuration from a file.
24
+ ///
25
+ /// @dev This function instantiates a `Config` contract, caching all its config variables.
26
+ ///
27
+ /// @param filePath: the path to the TOML configuration file.
28
+ /// @param writeToFile: whether updates are written back to the TOML file.
29
+ function _loadConfig(string memory filePath, bool writeToFile) internal {
30
+ console.log("----------");
31
+ console.log(string.concat("Loading config from '", filePath, "'"));
32
+ config = new StdConfig(filePath, writeToFile);
33
+ vm.makePersistent(address(config));
34
+ console.log("Config successfully loaded");
35
+ console.log("----------");
36
+ }
37
+
38
+ /// @notice Loads configuration from a file and creates forks for each specified chain.
39
+ ///
40
+ /// @dev This function instantiates a `Config` contract, caching all its config variables,
41
+ /// reads the configured chain ids, and iterates through them to create a fork for each one.
42
+ /// It also creates a map `forkOf[chainId] -> forkId` to easily switch between forks.
43
+ ///
44
+ /// @param filePath: the path to the TOML configuration file.
45
+ /// @param writeToFile: whether updates are written back to the TOML file.
46
+ function _loadConfigAndForks(string memory filePath, bool writeToFile) internal {
47
+ _loadConfig(filePath, writeToFile);
48
+
49
+ console.log("Setting up forks for the configured chains...");
50
+ uint256[] memory chains = config.getChainIds();
51
+ for (uint256 i = 0; i < chains.length; i++) {
52
+ uint256 chainId = chains[i];
53
+ uint256 forkId = vm.createFork(config.getRpcUrl(chainId));
54
+ forkOf[chainId] = forkId;
55
+ chainIds.push(chainId);
56
+ }
57
+ console.log("Forks successfully created");
58
+ console.log("----------");
59
+ }
60
+ }
@@ -0,0 +1,477 @@
1
+ // SPDX-License-Identifier: MIT OR Apache-2.0
2
+ pragma solidity ^0.8.13;
3
+
4
+ // Enable globally.
5
+ using LibVariable for Variable global;
6
+
7
+ struct Variable {
8
+ Type ty;
9
+ bytes data;
10
+ }
11
+
12
+ struct Type {
13
+ TypeKind kind;
14
+ bool isArray;
15
+ }
16
+
17
+ enum TypeKind {
18
+ None,
19
+ Bool,
20
+ Address,
21
+ Bytes32,
22
+ Uint256,
23
+ Int256,
24
+ String,
25
+ Bytes
26
+ }
27
+
28
+ /// @notice Library for type-safe coercion of the `Variable` struct to concrete types.
29
+ ///
30
+ /// @dev Ensures that when a `Variable` is cast to a concrete Solidity type, the operation is safe and the
31
+ /// underlying type matches what is expected.
32
+ /// Provides functions to check types, convert them to strings, and coerce `Variable` instances into
33
+ /// both single values and arrays of various types.
34
+ ///
35
+ /// Usage example:
36
+ /// ```solidity
37
+ /// import {LibVariable} from "./LibVariable.sol";
38
+ ///
39
+ /// contract MyContract {
40
+ /// using LibVariable for Variable;
41
+ /// StdConfig config; // Assume 'config' is an instance of `StdConfig` and has already been loaded.
42
+ ///
43
+ /// function readValues() public {
44
+ /// // Retrieve a 'uint256' value from the config.
45
+ /// uint256 myNumber = config.get("important_number").toUint256();
46
+ ///
47
+ /// // Would revert with `TypeMismatch` as 'important_number' isn't a `uint256` in the config file.
48
+ /// // string memory notANumber = config.get("important_number").toString();
49
+ ///
50
+ /// // Retrieve a address array from the config.
51
+ /// address[] memory admins = config.get("whitelisted_admins").toAddressArray();
52
+ /// }
53
+ /// }
54
+ /// ```
55
+ library LibVariable {
56
+ error NotInitialized();
57
+ error TypeMismatch(string expected, string actual);
58
+ error UnsafeCast(string message);
59
+
60
+ // -- TYPE HELPERS ----------------------------------------------------
61
+
62
+ /// @notice Compares two Type instances for equality.
63
+ function isEqual(Type memory self, Type memory other) internal pure returns (bool) {
64
+ return self.kind == other.kind && self.isArray == other.isArray;
65
+ }
66
+
67
+ /// @notice Compares two Type instances for equality. Reverts if they are not equal.
68
+ function assertEq(Type memory self, Type memory other) internal pure {
69
+ if (!isEqual(self, other)) {
70
+ revert TypeMismatch(toString(other), toString(self));
71
+ }
72
+ }
73
+
74
+ /// @notice Converts a Type struct to its full string representation (i.e. "uint256[]").
75
+ function toString(Type memory self) internal pure returns (string memory) {
76
+ string memory tyStr = toString(self.kind);
77
+ if (!self.isArray || self.kind == TypeKind.None) {
78
+ return tyStr;
79
+ } else {
80
+ return string.concat(tyStr, "[]");
81
+ }
82
+ }
83
+
84
+ /// @dev Converts a `TypeKind` enum to its base string representation.
85
+ function toString(TypeKind self) internal pure returns (string memory) {
86
+ if (self == TypeKind.Bool) return "bool";
87
+ if (self == TypeKind.Address) return "address";
88
+ if (self == TypeKind.Bytes32) return "bytes32";
89
+ if (self == TypeKind.Uint256) return "uint256";
90
+ if (self == TypeKind.Int256) return "int256";
91
+ if (self == TypeKind.String) return "string";
92
+ if (self == TypeKind.Bytes) return "bytes";
93
+ return "none";
94
+ }
95
+
96
+ /// @dev Converts a `TypeKind` enum to its base string representation.
97
+ function toTomlKey(TypeKind self) internal pure returns (string memory) {
98
+ if (self == TypeKind.Bool) return "bool";
99
+ if (self == TypeKind.Address) return "address";
100
+ if (self == TypeKind.Bytes32) return "bytes32";
101
+ if (self == TypeKind.Uint256) return "uint";
102
+ if (self == TypeKind.Int256) return "int";
103
+ if (self == TypeKind.String) return "string";
104
+ if (self == TypeKind.Bytes) return "bytes";
105
+ return "none";
106
+ }
107
+
108
+ // -- VARIABLE HELPERS ----------------------------------------------------
109
+
110
+ /// @dev Checks if a `Variable` has been initialized and matches the expected type reverting if not.
111
+ modifier check(Variable memory self, Type memory expected) {
112
+ assertExists(self);
113
+ assertEq(self.ty, expected);
114
+ _;
115
+ }
116
+
117
+ /// @dev Checks if a `Variable` has been initialized, reverting if not.
118
+ function assertExists(Variable memory self) public pure {
119
+ if (self.ty.kind == TypeKind.None) {
120
+ revert NotInitialized();
121
+ }
122
+ }
123
+
124
+ // -- VARIABLE COERCION FUNCTIONS (SINGLE VALUES) --------------------------
125
+
126
+ /// @notice Coerces a `Variable` to a `bool` value.
127
+ function toBool(Variable memory self) internal pure check(self, Type(TypeKind.Bool, false)) returns (bool) {
128
+ return abi.decode(self.data, (bool));
129
+ }
130
+
131
+ /// @notice Coerces a `Variable` to an `address` value.
132
+ function toAddress(Variable memory self)
133
+ internal
134
+ pure
135
+ check(self, Type(TypeKind.Address, false))
136
+ returns (address)
137
+ {
138
+ return abi.decode(self.data, (address));
139
+ }
140
+
141
+ /// @notice Coerces a `Variable` to a `bytes32` value.
142
+ function toBytes32(Variable memory self)
143
+ internal
144
+ pure
145
+ check(self, Type(TypeKind.Bytes32, false))
146
+ returns (bytes32)
147
+ {
148
+ return abi.decode(self.data, (bytes32));
149
+ }
150
+
151
+ /// @notice Coerces a `Variable` to a `uint256` value.
152
+ function toUint256(Variable memory self)
153
+ internal
154
+ pure
155
+ check(self, Type(TypeKind.Uint256, false))
156
+ returns (uint256)
157
+ {
158
+ return abi.decode(self.data, (uint256));
159
+ }
160
+
161
+ /// @notice Coerces a `Variable` to a `uint128` value, checking for overflow.
162
+ function toUint128(Variable memory self) internal pure returns (uint128) {
163
+ uint256 value = self.toUint256();
164
+ if (value > type(uint128).max) {
165
+ revert UnsafeCast("value does not fit in 'uint128'");
166
+ }
167
+ return uint128(value);
168
+ }
169
+
170
+ /// @notice Coerces a `Variable` to a `uint64` value, checking for overflow.
171
+ function toUint64(Variable memory self) internal pure returns (uint64) {
172
+ uint256 value = self.toUint256();
173
+ if (value > type(uint64).max) {
174
+ revert UnsafeCast("value does not fit in 'uint64'");
175
+ }
176
+ return uint64(value);
177
+ }
178
+
179
+ /// @notice Coerces a `Variable` to a `uint32` value, checking for overflow.
180
+ function toUint32(Variable memory self) internal pure returns (uint32) {
181
+ uint256 value = self.toUint256();
182
+ if (value > type(uint32).max) {
183
+ revert UnsafeCast("value does not fit in 'uint32'");
184
+ }
185
+ return uint32(value);
186
+ }
187
+
188
+ /// @notice Coerces a `Variable` to a `uint16` value, checking for overflow.
189
+ function toUint16(Variable memory self) internal pure returns (uint16) {
190
+ uint256 value = self.toUint256();
191
+ if (value > type(uint16).max) {
192
+ revert UnsafeCast("value does not fit in 'uint16'");
193
+ }
194
+ return uint16(value);
195
+ }
196
+
197
+ /// @notice Coerces a `Variable` to a `uint8` value, checking for overflow.
198
+ function toUint8(Variable memory self) internal pure returns (uint8) {
199
+ uint256 value = self.toUint256();
200
+ if (value > type(uint8).max) {
201
+ revert UnsafeCast("value does not fit in 'uint8'");
202
+ }
203
+ return uint8(value);
204
+ }
205
+
206
+ /// @notice Coerces a `Variable` to an `int256` value.
207
+ function toInt256(Variable memory self) internal pure check(self, Type(TypeKind.Int256, false)) returns (int256) {
208
+ return abi.decode(self.data, (int256));
209
+ }
210
+
211
+ /// @notice Coerces a `Variable` to an `int128` value, checking for overflow/underflow.
212
+ function toInt128(Variable memory self) internal pure returns (int128) {
213
+ int256 value = self.toInt256();
214
+ if (value > type(int128).max || value < type(int128).min) {
215
+ revert UnsafeCast("value does not fit in 'int128'");
216
+ }
217
+ return int128(value);
218
+ }
219
+
220
+ /// @notice Coerces a `Variable` to an `int64` value, checking for overflow/underflow.
221
+ function toInt64(Variable memory self) internal pure returns (int64) {
222
+ int256 value = self.toInt256();
223
+ if (value > type(int64).max || value < type(int64).min) {
224
+ revert UnsafeCast("value does not fit in 'int64'");
225
+ }
226
+ return int64(value);
227
+ }
228
+
229
+ /// @notice Coerces a `Variable` to an `int32` value, checking for overflow/underflow.
230
+ function toInt32(Variable memory self) internal pure returns (int32) {
231
+ int256 value = self.toInt256();
232
+ if (value > type(int32).max || value < type(int32).min) {
233
+ revert UnsafeCast("value does not fit in 'int32'");
234
+ }
235
+ return int32(value);
236
+ }
237
+
238
+ /// @notice Coerces a `Variable` to an `int16` value, checking for overflow/underflow.
239
+ function toInt16(Variable memory self) internal pure returns (int16) {
240
+ int256 value = self.toInt256();
241
+ if (value > type(int16).max || value < type(int16).min) {
242
+ revert UnsafeCast("value does not fit in 'int16'");
243
+ }
244
+ return int16(value);
245
+ }
246
+
247
+ /// @notice Coerces a `Variable` to an `int8` value, checking for overflow/underflow.
248
+ function toInt8(Variable memory self) internal pure returns (int8) {
249
+ int256 value = self.toInt256();
250
+ if (value > type(int8).max || value < type(int8).min) {
251
+ revert UnsafeCast("value does not fit in 'int8'");
252
+ }
253
+ return int8(value);
254
+ }
255
+
256
+ /// @notice Coerces a `Variable` to a `string` value.
257
+ function toString(Variable memory self)
258
+ internal
259
+ pure
260
+ check(self, Type(TypeKind.String, false))
261
+ returns (string memory)
262
+ {
263
+ return abi.decode(self.data, (string));
264
+ }
265
+
266
+ /// @notice Coerces a `Variable` to a `bytes` value.
267
+ function toBytes(Variable memory self)
268
+ internal
269
+ pure
270
+ check(self, Type(TypeKind.Bytes, false))
271
+ returns (bytes memory)
272
+ {
273
+ return abi.decode(self.data, (bytes));
274
+ }
275
+
276
+ // -- VARIABLE COERCION FUNCTIONS (ARRAYS) ---------------------------------
277
+
278
+ /// @notice Coerces a `Variable` to a `bool` array.
279
+ function toBoolArray(Variable memory self)
280
+ internal
281
+ pure
282
+ check(self, Type(TypeKind.Bool, true))
283
+ returns (bool[] memory)
284
+ {
285
+ return abi.decode(self.data, (bool[]));
286
+ }
287
+
288
+ /// @notice Coerces a `Variable` to an `address` array.
289
+ function toAddressArray(Variable memory self)
290
+ internal
291
+ pure
292
+ check(self, Type(TypeKind.Address, true))
293
+ returns (address[] memory)
294
+ {
295
+ return abi.decode(self.data, (address[]));
296
+ }
297
+
298
+ /// @notice Coerces a `Variable` to a `bytes32` array.
299
+ function toBytes32Array(Variable memory self)
300
+ internal
301
+ pure
302
+ check(self, Type(TypeKind.Bytes32, true))
303
+ returns (bytes32[] memory)
304
+ {
305
+ return abi.decode(self.data, (bytes32[]));
306
+ }
307
+
308
+ /// @notice Coerces a `Variable` to a `uint256` array.
309
+ function toUint256Array(Variable memory self)
310
+ internal
311
+ pure
312
+ check(self, Type(TypeKind.Uint256, true))
313
+ returns (uint256[] memory)
314
+ {
315
+ return abi.decode(self.data, (uint256[]));
316
+ }
317
+
318
+ /// @notice Coerces a `Variable` to a `uint128` array, checking for overflow.
319
+ function toUint128Array(Variable memory self) internal pure returns (uint128[] memory) {
320
+ uint256[] memory values = self.toUint256Array();
321
+ uint128[] memory result = new uint128[](values.length);
322
+ for (uint256 i = 0; i < values.length; i++) {
323
+ if (values[i] > type(uint128).max) {
324
+ revert UnsafeCast("value in array does not fit in 'uint128'");
325
+ }
326
+ result[i] = uint128(values[i]);
327
+ }
328
+ return result;
329
+ }
330
+
331
+ /// @notice Coerces a `Variable` to a `uint64` array, checking for overflow.
332
+ function toUint64Array(Variable memory self) internal pure returns (uint64[] memory) {
333
+ uint256[] memory values = self.toUint256Array();
334
+ uint64[] memory result = new uint64[](values.length);
335
+ for (uint256 i = 0; i < values.length; i++) {
336
+ if (values[i] > type(uint64).max) {
337
+ revert UnsafeCast("value in array does not fit in 'uint64'");
338
+ }
339
+ result[i] = uint64(values[i]);
340
+ }
341
+ return result;
342
+ }
343
+
344
+ /// @notice Coerces a `Variable` to a `uint32` array, checking for overflow.
345
+ function toUint32Array(Variable memory self) internal pure returns (uint32[] memory) {
346
+ uint256[] memory values = self.toUint256Array();
347
+ uint32[] memory result = new uint32[](values.length);
348
+ for (uint256 i = 0; i < values.length; i++) {
349
+ if (values[i] > type(uint32).max) {
350
+ revert UnsafeCast("value in array does not fit in 'uint32'");
351
+ }
352
+ result[i] = uint32(values[i]);
353
+ }
354
+ return result;
355
+ }
356
+
357
+ /// @notice Coerces a `Variable` to a `uint16` array, checking for overflow.
358
+ function toUint16Array(Variable memory self) internal pure returns (uint16[] memory) {
359
+ uint256[] memory values = self.toUint256Array();
360
+ uint16[] memory result = new uint16[](values.length);
361
+ for (uint256 i = 0; i < values.length; i++) {
362
+ if (values[i] > type(uint16).max) {
363
+ revert UnsafeCast("value in array does not fit in 'uint16'");
364
+ }
365
+ result[i] = uint16(values[i]);
366
+ }
367
+ return result;
368
+ }
369
+
370
+ /// @notice Coerces a `Variable` to a `uint8` array, checking for overflow.
371
+ function toUint8Array(Variable memory self) internal pure returns (uint8[] memory) {
372
+ uint256[] memory values = self.toUint256Array();
373
+ uint8[] memory result = new uint8[](values.length);
374
+ for (uint256 i = 0; i < values.length; i++) {
375
+ if (values[i] > type(uint8).max) {
376
+ revert UnsafeCast("value in array does not fit in 'uint8'");
377
+ }
378
+ result[i] = uint8(values[i]);
379
+ }
380
+ return result;
381
+ }
382
+
383
+ /// @notice Coerces a `Variable` to an `int256` array.
384
+ function toInt256Array(Variable memory self)
385
+ internal
386
+ pure
387
+ check(self, Type(TypeKind.Int256, true))
388
+ returns (int256[] memory)
389
+ {
390
+ return abi.decode(self.data, (int256[]));
391
+ }
392
+
393
+ /// @notice Coerces a `Variable` to a `int128` array, checking for overflow/underflow.
394
+ function toInt128Array(Variable memory self) internal pure returns (int128[] memory) {
395
+ int256[] memory values = self.toInt256Array();
396
+ int128[] memory result = new int128[](values.length);
397
+ for (uint256 i = 0; i < values.length; i++) {
398
+ if (values[i] > type(int128).max || values[i] < type(int128).min) {
399
+ revert UnsafeCast("value in array does not fit in 'int128'");
400
+ }
401
+ result[i] = int128(values[i]);
402
+ }
403
+ return result;
404
+ }
405
+
406
+ /// @notice Coerces a `Variable` to a `int64` array, checking for overflow/underflow.
407
+ function toInt64Array(Variable memory self) internal pure returns (int64[] memory) {
408
+ int256[] memory values = self.toInt256Array();
409
+ int64[] memory result = new int64[](values.length);
410
+ for (uint256 i = 0; i < values.length; i++) {
411
+ if (values[i] > type(int64).max || values[i] < type(int64).min) {
412
+ revert UnsafeCast("value in array does not fit in 'int64'");
413
+ }
414
+ result[i] = int64(values[i]);
415
+ }
416
+ return result;
417
+ }
418
+
419
+ /// @notice Coerces a `Variable` to a `int32` array, checking for overflow/underflow.
420
+ function toInt32Array(Variable memory self) internal pure returns (int32[] memory) {
421
+ int256[] memory values = self.toInt256Array();
422
+ int32[] memory result = new int32[](values.length);
423
+ for (uint256 i = 0; i < values.length; i++) {
424
+ if (values[i] > type(int32).max || values[i] < type(int32).min) {
425
+ revert UnsafeCast("value in array does not fit in 'int32'");
426
+ }
427
+ result[i] = int32(values[i]);
428
+ }
429
+ return result;
430
+ }
431
+
432
+ /// @notice Coerces a `Variable` to a `int16` array, checking for overflow/underflow.
433
+ function toInt16Array(Variable memory self) internal pure returns (int16[] memory) {
434
+ int256[] memory values = self.toInt256Array();
435
+ int16[] memory result = new int16[](values.length);
436
+ for (uint256 i = 0; i < values.length; i++) {
437
+ if (values[i] > type(int16).max || values[i] < type(int16).min) {
438
+ revert UnsafeCast("value in array does not fit in 'int16'");
439
+ }
440
+ result[i] = int16(values[i]);
441
+ }
442
+ return result;
443
+ }
444
+
445
+ /// @notice Coerces a `Variable` to a `int8` array, checking for overflow/underflow.
446
+ function toInt8Array(Variable memory self) internal pure returns (int8[] memory) {
447
+ int256[] memory values = self.toInt256Array();
448
+ int8[] memory result = new int8[](values.length);
449
+ for (uint256 i = 0; i < values.length; i++) {
450
+ if (values[i] > type(int8).max || values[i] < type(int8).min) {
451
+ revert UnsafeCast("value in array does not fit in 'int8'");
452
+ }
453
+ result[i] = int8(values[i]);
454
+ }
455
+ return result;
456
+ }
457
+
458
+ /// @notice Coerces a `Variable` to a `string` array.
459
+ function toStringArray(Variable memory self)
460
+ internal
461
+ pure
462
+ check(self, Type(TypeKind.String, true))
463
+ returns (string[] memory)
464
+ {
465
+ return abi.decode(self.data, (string[]));
466
+ }
467
+
468
+ /// @notice Coerces a `Variable` to a `bytes` array.
469
+ function toBytesArray(Variable memory self)
470
+ internal
471
+ pure
472
+ check(self, Type(TypeKind.Bytes, true))
473
+ returns (bytes[] memory)
474
+ {
475
+ return abi.decode(self.data, (bytes[]));
476
+ }
477
+ }
@@ -0,0 +1,28 @@
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 Script.
6
+
7
+ // 🧩 MODULES
8
+ import {console} from "./console.sol";
9
+ import {console2} from "./console2.sol";
10
+ import {safeconsole} from "./safeconsole.sol";
11
+ import {StdChains} from "./StdChains.sol";
12
+ import {StdCheatsSafe} from "./StdCheats.sol";
13
+ import {StdConstants} from "./StdConstants.sol";
14
+ import {stdJson} from "./StdJson.sol";
15
+ import {stdMath} from "./StdMath.sol";
16
+ import {StdStorage, stdStorageSafe} from "./StdStorage.sol";
17
+ import {StdStyle} from "./StdStyle.sol";
18
+ import {StdUtils} from "./StdUtils.sol";
19
+ import {VmSafe} from "./Vm.sol";
20
+
21
+ // 📦 BOILERPLATE
22
+ import {ScriptBase} from "./Base.sol";
23
+
24
+ // ⭐️ SCRIPT
25
+ abstract contract Script is ScriptBase, StdChains, StdCheatsSafe, StdUtils {
26
+ // Note: IS_SCRIPT() must return true.
27
+ bool public IS_SCRIPT = true;
28
+ }