-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
vm.rs
2250 lines (1884 loc) · 114 KB
/
vm.rs
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// We don't document function parameters individually so we can't enable `missing_docs` for this
// module. Instead, we emit custom diagnostics in `#[derive(Cheatcode)]`.
#![allow(missing_docs)]
use super::*;
use crate::Vm::ForgeContext;
use alloy_sol_types::sol;
use foundry_macros::Cheatcode;
sol! {
// Cheatcodes are marked as view/pure/none using the following rules:
// 0. A call's observable behaviour includes its return value, logs, reverts and state writes,
// 1. If you can influence a later call's observable behaviour, you're neither `view` nor `pure`
// (you are modifying some state be it the EVM, interpreter, filesystem, etc),
// 2. Otherwise if you can be influenced by an earlier call, or if reading some state, you're `view`,
// 3. Otherwise you're `pure`.
/// Foundry cheatcodes interface.
#[derive(Debug, Cheatcode)] // Keep this list small to avoid unnecessary bloat.
#[sol(abi)]
interface Vm {
// ======== Types ========
/// Error thrown by cheatcodes.
error CheatcodeError(string message);
/// A modification applied to either `msg.sender` or `tx.origin`. Returned by `readCallers`.
enum CallerMode {
/// No caller modification is currently active.
None,
/// A one time broadcast triggered by a `vm.broadcast()` call is currently active.
Broadcast,
/// A recurrent broadcast triggered by a `vm.startBroadcast()` call is currently active.
RecurrentBroadcast,
/// A one time prank triggered by a `vm.prank()` call is currently active.
Prank,
/// A recurrent prank triggered by a `vm.startPrank()` call is currently active.
RecurrentPrank,
}
/// The kind of account access that occurred.
enum AccountAccessKind {
/// The account was called.
Call,
/// The account was called via delegatecall.
DelegateCall,
/// The account was called via callcode.
CallCode,
/// The account was called via staticcall.
StaticCall,
/// The account was created.
Create,
/// The account was selfdestructed.
SelfDestruct,
/// Synthetic access indicating the current context has resumed after a previous sub-context (AccountAccess).
Resume,
/// The account's balance was read.
Balance,
/// The account's codesize was read.
Extcodesize,
/// The account's codehash was read.
Extcodehash,
/// The account's code was copied.
Extcodecopy,
}
/// Forge execution contexts.
enum ForgeContext {
/// Test group execution context (test, coverage or snapshot).
TestGroup,
/// `forge test` execution context.
Test,
/// `forge coverage` execution context.
Coverage,
/// `forge snapshot` execution context.
Snapshot,
/// Script group execution context (dry run, broadcast or resume).
ScriptGroup,
/// `forge script` execution context.
ScriptDryRun,
/// `forge script --broadcast` execution context.
ScriptBroadcast,
/// `forge script --resume` execution context.
ScriptResume,
/// Unknown `forge` execution context.
Unknown,
}
/// An Ethereum log. Returned by `getRecordedLogs`.
struct Log {
/// The topics of the log, including the signature, if any.
bytes32[] topics;
/// The raw data of the log.
bytes data;
/// The address of the log's emitter.
address emitter;
}
/// Gas used. Returned by `lastCallGas`.
struct Gas {
/// The gas limit of the call.
uint64 gasLimit;
/// The total gas used.
uint64 gasTotalUsed;
/// DEPRECATED: The amount of gas used for memory expansion. Ref: <https://github.com/foundry-rs/foundry/pull/7934#pullrequestreview-2069236939>
uint64 gasMemoryUsed;
/// The amount of gas refunded.
int64 gasRefunded;
/// The amount of gas remaining.
uint64 gasRemaining;
}
/// An RPC URL and its alias. Returned by `rpcUrlStructs`.
struct Rpc {
/// The alias of the RPC URL.
string key;
/// The RPC URL.
string url;
}
/// An RPC log object. Returned by `eth_getLogs`.
struct EthGetLogs {
/// The address of the log's emitter.
address emitter;
/// The topics of the log, including the signature, if any.
bytes32[] topics;
/// The raw data of the log.
bytes data;
/// The block hash.
bytes32 blockHash;
/// The block number.
uint64 blockNumber;
/// The transaction hash.
bytes32 transactionHash;
/// The transaction index in the block.
uint64 transactionIndex;
/// The log index.
uint256 logIndex;
/// Whether the log was removed.
bool removed;
}
/// A single entry in a directory listing. Returned by `readDir`.
struct DirEntry {
/// The error message, if any.
string errorMessage;
/// The path of the entry.
string path;
/// The depth of the entry.
uint64 depth;
/// Whether the entry is a directory.
bool isDir;
/// Whether the entry is a symlink.
bool isSymlink;
}
/// Metadata information about a file.
///
/// This structure is returned from the `fsMetadata` function and represents known
/// metadata about a file such as its permissions, size, modification
/// times, etc.
struct FsMetadata {
/// True if this metadata is for a directory.
bool isDir;
/// True if this metadata is for a symlink.
bool isSymlink;
/// The size of the file, in bytes, this metadata is for.
uint256 length;
/// True if this metadata is for a readonly (unwritable) file.
bool readOnly;
/// The last modification time listed in this metadata.
uint256 modified;
/// The last access time of this metadata.
uint256 accessed;
/// The creation time listed in this metadata.
uint256 created;
}
/// A wallet with a public and private key.
struct Wallet {
/// The wallet's address.
address addr;
/// The wallet's public key `X`.
uint256 publicKeyX;
/// The wallet's public key `Y`.
uint256 publicKeyY;
/// The wallet's private key.
uint256 privateKey;
}
/// The result of a `tryFfi` call.
struct FfiResult {
/// The exit code of the call.
int32 exitCode;
/// The optionally hex-decoded `stdout` data.
bytes stdout;
/// The `stderr` data.
bytes stderr;
}
/// Information on the chain and fork.
struct ChainInfo {
/// The fork identifier. Set to zero if no fork is active.
uint256 forkId;
/// The chain ID of the current fork.
uint256 chainId;
}
/// The storage accessed during an `AccountAccess`.
struct StorageAccess {
/// The account whose storage was accessed.
address account;
/// The slot that was accessed.
bytes32 slot;
/// If the access was a write.
bool isWrite;
/// The previous value of the slot.
bytes32 previousValue;
/// The new value of the slot.
bytes32 newValue;
/// If the access was reverted.
bool reverted;
}
/// The result of a `stopAndReturnStateDiff` call.
struct AccountAccess {
/// The chain and fork the access occurred.
ChainInfo chainInfo;
/// The kind of account access that determines what the account is.
/// If kind is Call, DelegateCall, StaticCall or CallCode, then the account is the callee.
/// If kind is Create, then the account is the newly created account.
/// If kind is SelfDestruct, then the account is the selfdestruct recipient.
/// If kind is a Resume, then account represents a account context that has resumed.
AccountAccessKind kind;
/// The account that was accessed.
/// It's either the account created, callee or a selfdestruct recipient for CREATE, CALL or SELFDESTRUCT.
address account;
/// What accessed the account.
address accessor;
/// If the account was initialized or empty prior to the access.
/// An account is considered initialized if it has code, a
/// non-zero nonce, or a non-zero balance.
bool initialized;
/// The previous balance of the accessed account.
uint256 oldBalance;
/// The potential new balance of the accessed account.
/// That is, all balance changes are recorded here, even if reverts occurred.
uint256 newBalance;
/// Code of the account deployed by CREATE.
bytes deployedCode;
/// Value passed along with the account access
uint256 value;
/// Input data provided to the CREATE or CALL
bytes data;
/// If this access reverted in either the current or parent context.
bool reverted;
/// An ordered list of storage accesses made during an account access operation.
StorageAccess[] storageAccesses;
/// Call depth traversed during the recording of state differences
uint64 depth;
}
// ======== EVM ========
/// Gets the address for a given private key.
#[cheatcode(group = Evm, safety = Safe)]
function addr(uint256 privateKey) external pure returns (address keyAddr);
/// Dump a genesis JSON file's `allocs` to disk.
#[cheatcode(group = Evm, safety = Unsafe)]
function dumpState(string calldata pathToStateJson) external;
/// Gets the nonce of an account.
#[cheatcode(group = Evm, safety = Safe)]
function getNonce(address account) external view returns (uint64 nonce);
/// Loads a storage slot from an address.
#[cheatcode(group = Evm, safety = Safe)]
function load(address target, bytes32 slot) external view returns (bytes32 data);
/// Load a genesis JSON file's `allocs` into the in-memory revm state.
#[cheatcode(group = Evm, safety = Unsafe)]
function loadAllocs(string calldata pathToAllocsJson) external;
/// Signs `digest` with `privateKey` using the secp256k1 curve.
#[cheatcode(group = Evm, safety = Safe)]
function sign(uint256 privateKey, bytes32 digest) external pure returns (uint8 v, bytes32 r, bytes32 s);
/// Signs `digest` with signer provided to script using the secp256k1 curve.
///
/// If `--sender` is provided, the signer with provided address is used, otherwise,
/// if exactly one signer is provided to the script, that signer is used.
///
/// Raises error if signer passed through `--sender` does not match any unlocked signers or
/// if `--sender` is not provided and not exactly one signer is passed to the script.
#[cheatcode(group = Evm, safety = Safe)]
function sign(bytes32 digest) external pure returns (uint8 v, bytes32 r, bytes32 s);
/// Signs `digest` with signer provided to script using the secp256k1 curve.
///
/// Raises error if none of the signers passed into the script have provided address.
#[cheatcode(group = Evm, safety = Safe)]
function sign(address signer, bytes32 digest) external pure returns (uint8 v, bytes32 r, bytes32 s);
/// Signs `digest` with `privateKey` using the secp256r1 curve.
#[cheatcode(group = Evm, safety = Safe)]
function signP256(uint256 privateKey, bytes32 digest) external pure returns (bytes32 r, bytes32 s);
// -------- Record Storage --------
/// Records all storage reads and writes.
#[cheatcode(group = Evm, safety = Safe)]
function record() external;
/// Gets all accessed reads and write slot from a `vm.record` session, for a given address.
#[cheatcode(group = Evm, safety = Safe)]
function accesses(address target) external returns (bytes32[] memory readSlots, bytes32[] memory writeSlots);
/// Record all account accesses as part of CREATE, CALL or SELFDESTRUCT opcodes in order,
/// along with the context of the calls
#[cheatcode(group = Evm, safety = Safe)]
function startStateDiffRecording() external;
/// Returns an ordered array of all account accesses from a `vm.startStateDiffRecording` session.
#[cheatcode(group = Evm, safety = Safe)]
function stopAndReturnStateDiff() external returns (AccountAccess[] memory accountAccesses);
// -------- Recording Map Writes --------
/// Starts recording all map SSTOREs for later retrieval.
#[cheatcode(group = Evm, safety = Safe)]
function startMappingRecording() external;
/// Stops recording all map SSTOREs for later retrieval and clears the recorded data.
#[cheatcode(group = Evm, safety = Safe)]
function stopMappingRecording() external;
/// Gets the number of elements in the mapping at the given slot, for a given address.
#[cheatcode(group = Evm, safety = Safe)]
function getMappingLength(address target, bytes32 mappingSlot) external returns (uint256 length);
/// Gets the elements at index idx of the mapping at the given slot, for a given address. The
/// index must be less than the length of the mapping (i.e. the number of keys in the mapping).
#[cheatcode(group = Evm, safety = Safe)]
function getMappingSlotAt(address target, bytes32 mappingSlot, uint256 idx) external returns (bytes32 value);
/// Gets the map key and parent of a mapping at a given slot, for a given address.
#[cheatcode(group = Evm, safety = Safe)]
function getMappingKeyAndParentOf(address target, bytes32 elementSlot)
external
returns (bool found, bytes32 key, bytes32 parent);
// -------- Block and Transaction Properties --------
/// Sets `block.chainid`.
#[cheatcode(group = Evm, safety = Unsafe)]
function chainId(uint256 newChainId) external;
/// Sets `block.coinbase`.
#[cheatcode(group = Evm, safety = Unsafe)]
function coinbase(address newCoinbase) external;
/// Sets `block.difficulty`.
/// Not available on EVM versions from Paris onwards. Use `prevrandao` instead.
/// Reverts if used on unsupported EVM versions.
#[cheatcode(group = Evm, safety = Unsafe)]
function difficulty(uint256 newDifficulty) external;
/// Sets `block.basefee`.
#[cheatcode(group = Evm, safety = Unsafe)]
function fee(uint256 newBasefee) external;
/// Sets `block.prevrandao`.
/// Not available on EVM versions before Paris. Use `difficulty` instead.
/// If used on unsupported EVM versions it will revert.
#[cheatcode(group = Evm, safety = Unsafe)]
function prevrandao(bytes32 newPrevrandao) external;
/// Sets `block.prevrandao`.
/// Not available on EVM versions before Paris. Use `difficulty` instead.
/// If used on unsupported EVM versions it will revert.
#[cheatcode(group = Evm, safety = Unsafe)]
function prevrandao(uint256 newPrevrandao) external;
/// Sets the blobhashes in the transaction.
/// Not available on EVM versions before Cancun.
/// If used on unsupported EVM versions it will revert.
#[cheatcode(group = Evm, safety = Unsafe)]
function blobhashes(bytes32[] calldata hashes) external;
/// Gets the blockhashes from the current transaction.
/// Not available on EVM versions before Cancun.
/// If used on unsupported EVM versions it will revert.
#[cheatcode(group = Evm, safety = Unsafe)]
function getBlobhashes() external view returns (bytes32[] memory hashes);
/// Sets `block.height`.
#[cheatcode(group = Evm, safety = Unsafe)]
function roll(uint256 newHeight) external;
/// Gets the current `block.number`.
/// You should use this instead of `block.number` if you use `vm.roll`, as `block.number` is assumed to be constant across a transaction,
/// and as a result will get optimized out by the compiler.
/// See https://github.com/foundry-rs/foundry/issues/6180
#[cheatcode(group = Evm, safety = Safe)]
function getBlockNumber() external view returns (uint256 height);
/// Sets `tx.gasprice`.
#[cheatcode(group = Evm, safety = Unsafe)]
function txGasPrice(uint256 newGasPrice) external;
/// Sets `block.timestamp`.
#[cheatcode(group = Evm, safety = Unsafe)]
function warp(uint256 newTimestamp) external;
/// Gets the current `block.timestamp`.
/// You should use this instead of `block.timestamp` if you use `vm.warp`, as `block.timestamp` is assumed to be constant across a transaction,
/// and as a result will get optimized out by the compiler.
/// See https://github.com/foundry-rs/foundry/issues/6180
#[cheatcode(group = Evm, safety = Safe)]
function getBlockTimestamp() external view returns (uint256 timestamp);
/// Sets `block.blobbasefee`
#[cheatcode(group = Evm, safety = Unsafe)]
function blobBaseFee(uint256 newBlobBaseFee) external;
/// Gets the current `block.blobbasefee`.
/// You should use this instead of `block.blobbasefee` if you use `vm.blobBaseFee`, as `block.blobbasefee` is assumed to be constant across a transaction,
/// and as a result will get optimized out by the compiler.
/// See https://github.com/foundry-rs/foundry/issues/6180
#[cheatcode(group = Evm, safety = Safe)]
function getBlobBaseFee() external view returns (uint256 blobBaseFee);
/// Set blockhash for the current block.
/// It only sets the blockhash for blocks where `block.number - 256 <= number < block.number`.
#[cheatcode(group = Evm, safety = Unsafe)]
function setBlockhash(uint256 blockNumber, bytes32 blockHash) external;
// -------- Account State --------
/// Sets an address' balance.
#[cheatcode(group = Evm, safety = Unsafe)]
function deal(address account, uint256 newBalance) external;
/// Sets an address' code.
#[cheatcode(group = Evm, safety = Unsafe)]
function etch(address target, bytes calldata newRuntimeBytecode) external;
/// Resets the nonce of an account to 0 for EOAs and 1 for contract accounts.
#[cheatcode(group = Evm, safety = Unsafe)]
function resetNonce(address account) external;
/// Sets the nonce of an account. Must be higher than the current nonce of the account.
#[cheatcode(group = Evm, safety = Unsafe)]
function setNonce(address account, uint64 newNonce) external;
/// Sets the nonce of an account to an arbitrary value.
#[cheatcode(group = Evm, safety = Unsafe)]
function setNonceUnsafe(address account, uint64 newNonce) external;
/// Stores a value to an address' storage slot.
#[cheatcode(group = Evm, safety = Unsafe)]
function store(address target, bytes32 slot, bytes32 value) external;
/// Marks the slots of an account and the account address as cold.
#[cheatcode(group = Evm, safety = Unsafe, status = Experimental)]
function cool(address target) external;
// -------- Call Manipulation --------
// --- Mocks ---
/// Clears all mocked calls.
#[cheatcode(group = Evm, safety = Unsafe)]
function clearMockedCalls() external;
/// Mocks a call to an address, returning specified data.
/// Calldata can either be strict or a partial match, e.g. if you only
/// pass a Solidity selector to the expected calldata, then the entire Solidity
/// function will be mocked.
#[cheatcode(group = Evm, safety = Unsafe)]
function mockCall(address callee, bytes calldata data, bytes calldata returnData) external;
/// Mocks a call to an address with a specific `msg.value`, returning specified data.
/// Calldata match takes precedence over `msg.value` in case of ambiguity.
#[cheatcode(group = Evm, safety = Unsafe)]
function mockCall(address callee, uint256 msgValue, bytes calldata data, bytes calldata returnData) external;
/// Reverts a call to an address with specified revert data.
#[cheatcode(group = Evm, safety = Unsafe)]
function mockCallRevert(address callee, bytes calldata data, bytes calldata revertData) external;
/// Reverts a call to an address with a specific `msg.value`, with specified revert data.
#[cheatcode(group = Evm, safety = Unsafe)]
function mockCallRevert(address callee, uint256 msgValue, bytes calldata data, bytes calldata revertData)
external;
// --- Impersonation (pranks) ---
/// Sets the *next* call's `msg.sender` to be the input address.
#[cheatcode(group = Evm, safety = Unsafe)]
function prank(address msgSender) external;
/// Sets all subsequent calls' `msg.sender` to be the input address until `stopPrank` is called.
#[cheatcode(group = Evm, safety = Unsafe)]
function startPrank(address msgSender) external;
/// Sets the *next* call's `msg.sender` to be the input address, and the `tx.origin` to be the second input.
#[cheatcode(group = Evm, safety = Unsafe)]
function prank(address msgSender, address txOrigin) external;
/// Sets all subsequent calls' `msg.sender` to be the input address until `stopPrank` is called, and the `tx.origin` to be the second input.
#[cheatcode(group = Evm, safety = Unsafe)]
function startPrank(address msgSender, address txOrigin) external;
/// Resets subsequent calls' `msg.sender` to be `address(this)`.
#[cheatcode(group = Evm, safety = Unsafe)]
function stopPrank() external;
/// Reads the current `msg.sender` and `tx.origin` from state and reports if there is any active caller modification.
#[cheatcode(group = Evm, safety = Unsafe)]
function readCallers() external returns (CallerMode callerMode, address msgSender, address txOrigin);
// -------- State Snapshots --------
/// Snapshot the current state of the evm.
/// Returns the ID of the snapshot that was created.
/// To revert a snapshot use `revertTo`.
#[cheatcode(group = Evm, safety = Unsafe)]
function snapshot() external returns (uint256 snapshotId);
/// Revert the state of the EVM to a previous snapshot
/// Takes the snapshot ID to revert to.
///
/// Returns `true` if the snapshot was successfully reverted.
/// Returns `false` if the snapshot does not exist.
///
/// **Note:** This does not automatically delete the snapshot. To delete the snapshot use `deleteSnapshot`.
#[cheatcode(group = Evm, safety = Unsafe)]
function revertTo(uint256 snapshotId) external returns (bool success);
/// Revert the state of the EVM to a previous snapshot and automatically deletes the snapshots
/// Takes the snapshot ID to revert to.
///
/// Returns `true` if the snapshot was successfully reverted and deleted.
/// Returns `false` if the snapshot does not exist.
#[cheatcode(group = Evm, safety = Unsafe)]
function revertToAndDelete(uint256 snapshotId) external returns (bool success);
/// Removes the snapshot with the given ID created by `snapshot`.
/// Takes the snapshot ID to delete.
///
/// Returns `true` if the snapshot was successfully deleted.
/// Returns `false` if the snapshot does not exist.
#[cheatcode(group = Evm, safety = Unsafe)]
function deleteSnapshot(uint256 snapshotId) external returns (bool success);
/// Removes _all_ snapshots previously created by `snapshot`.
#[cheatcode(group = Evm, safety = Unsafe)]
function deleteSnapshots() external;
// -------- Forking --------
// --- Creation and Selection ---
/// Returns the identifier of the currently active fork. Reverts if no fork is currently active.
#[cheatcode(group = Evm, safety = Unsafe)]
function activeFork() external view returns (uint256 forkId);
/// Creates a new fork with the given endpoint and the _latest_ block and returns the identifier of the fork.
#[cheatcode(group = Evm, safety = Unsafe)]
function createFork(string calldata urlOrAlias) external returns (uint256 forkId);
/// Creates a new fork with the given endpoint and block and returns the identifier of the fork.
#[cheatcode(group = Evm, safety = Unsafe)]
function createFork(string calldata urlOrAlias, uint256 blockNumber) external returns (uint256 forkId);
/// Creates a new fork with the given endpoint and at the block the given transaction was mined in,
/// replays all transaction mined in the block before the transaction, and returns the identifier of the fork.
#[cheatcode(group = Evm, safety = Unsafe)]
function createFork(string calldata urlOrAlias, bytes32 txHash) external returns (uint256 forkId);
/// Creates and also selects a new fork with the given endpoint and the latest block and returns the identifier of the fork.
#[cheatcode(group = Evm, safety = Unsafe)]
function createSelectFork(string calldata urlOrAlias) external returns (uint256 forkId);
/// Creates and also selects a new fork with the given endpoint and block and returns the identifier of the fork.
#[cheatcode(group = Evm, safety = Unsafe)]
function createSelectFork(string calldata urlOrAlias, uint256 blockNumber) external returns (uint256 forkId);
/// Creates and also selects new fork with the given endpoint and at the block the given transaction was mined in,
/// replays all transaction mined in the block before the transaction, returns the identifier of the fork.
#[cheatcode(group = Evm, safety = Unsafe)]
function createSelectFork(string calldata urlOrAlias, bytes32 txHash) external returns (uint256 forkId);
/// Updates the currently active fork to given block number
/// This is similar to `roll` but for the currently active fork.
#[cheatcode(group = Evm, safety = Unsafe)]
function rollFork(uint256 blockNumber) external;
/// Updates the currently active fork to given transaction. This will `rollFork` with the number
/// of the block the transaction was mined in and replays all transaction mined before it in the block.
#[cheatcode(group = Evm, safety = Unsafe)]
function rollFork(bytes32 txHash) external;
/// Updates the given fork to given block number.
#[cheatcode(group = Evm, safety = Unsafe)]
function rollFork(uint256 forkId, uint256 blockNumber) external;
/// Updates the given fork to block number of the given transaction and replays all transaction mined before it in the block.
#[cheatcode(group = Evm, safety = Unsafe)]
function rollFork(uint256 forkId, bytes32 txHash) external;
/// Takes a fork identifier created by `createFork` and sets the corresponding forked state as active.
#[cheatcode(group = Evm, safety = Unsafe)]
function selectFork(uint256 forkId) external;
/// Fetches the given transaction from the active fork and executes it on the current state.
#[cheatcode(group = Evm, safety = Unsafe)]
function transact(bytes32 txHash) external;
/// Fetches the given transaction from the given fork and executes it on the current state.
#[cheatcode(group = Evm, safety = Unsafe)]
function transact(uint256 forkId, bytes32 txHash) external;
/// Performs an Ethereum JSON-RPC request to the current fork URL.
#[cheatcode(group = Evm, safety = Safe)]
function rpc(string calldata method, string calldata params) external returns (bytes memory data);
/// Performs an Ethereum JSON-RPC request to the given endpoint.
#[cheatcode(group = Evm, safety = Safe)]
function rpc(string calldata urlOrAlias, string calldata method, string calldata params)
external
returns (bytes memory data);
/// Gets all the logs according to specified filter.
#[cheatcode(group = Evm, safety = Safe)]
function eth_getLogs(uint256 fromBlock, uint256 toBlock, address target, bytes32[] memory topics)
external
returns (EthGetLogs[] memory logs);
// --- Behavior ---
/// In forking mode, explicitly grant the given address cheatcode access.
#[cheatcode(group = Evm, safety = Unsafe)]
function allowCheatcodes(address account) external;
/// Marks that the account(s) should use persistent storage across fork swaps in a multifork setup
/// Meaning, changes made to the state of this account will be kept when switching forks.
#[cheatcode(group = Evm, safety = Unsafe)]
function makePersistent(address account) external;
/// See `makePersistent(address)`.
#[cheatcode(group = Evm, safety = Unsafe)]
function makePersistent(address account0, address account1) external;
/// See `makePersistent(address)`.
#[cheatcode(group = Evm, safety = Unsafe)]
function makePersistent(address account0, address account1, address account2) external;
/// See `makePersistent(address)`.
#[cheatcode(group = Evm, safety = Unsafe)]
function makePersistent(address[] calldata accounts) external;
/// Revokes persistent status from the address, previously added via `makePersistent`.
#[cheatcode(group = Evm, safety = Unsafe)]
function revokePersistent(address account) external;
/// See `revokePersistent(address)`.
#[cheatcode(group = Evm, safety = Unsafe)]
function revokePersistent(address[] calldata accounts) external;
/// Returns true if the account is marked as persistent.
#[cheatcode(group = Evm, safety = Unsafe)]
function isPersistent(address account) external view returns (bool persistent);
// -------- Record Logs --------
/// Record all the transaction logs.
#[cheatcode(group = Evm, safety = Safe)]
function recordLogs() external;
/// Gets all the recorded logs.
#[cheatcode(group = Evm, safety = Safe)]
function getRecordedLogs() external returns (Log[] memory logs);
// -------- Gas Metering --------
// It's recommend to use the `noGasMetering` modifier included with forge-std, instead of
// using these functions directly.
/// Pauses gas metering (i.e. gas usage is not counted). Noop if already paused.
#[cheatcode(group = Evm, safety = Safe)]
function pauseGasMetering() external;
/// Resumes gas metering (i.e. gas usage is counted again). Noop if already on.
#[cheatcode(group = Evm, safety = Safe)]
function resumeGasMetering() external;
// -------- Gas Measurement --------
/// Gets the gas used in the last call.
#[cheatcode(group = Evm, safety = Safe)]
function lastCallGas() external view returns (Gas memory gas);
// ======== Test Assertions and Utilities ========
/// If the condition is false, discard this run's fuzz inputs and generate new ones.
#[cheatcode(group = Testing, safety = Safe)]
function assume(bool condition) external pure;
/// Writes a breakpoint to jump to in the debugger.
#[cheatcode(group = Testing, safety = Safe)]
function breakpoint(string calldata char) external;
/// Writes a conditional breakpoint to jump to in the debugger.
#[cheatcode(group = Testing, safety = Safe)]
function breakpoint(string calldata char, bool value) external;
/// Returns the RPC url for the given alias.
#[cheatcode(group = Testing, safety = Safe)]
function rpcUrl(string calldata rpcAlias) external view returns (string memory json);
/// Returns all rpc urls and their aliases `[alias, url][]`.
#[cheatcode(group = Testing, safety = Safe)]
function rpcUrls() external view returns (string[2][] memory urls);
/// Returns all rpc urls and their aliases as structs.
#[cheatcode(group = Testing, safety = Safe)]
function rpcUrlStructs() external view returns (Rpc[] memory urls);
/// Suspends execution of the main thread for `duration` milliseconds.
#[cheatcode(group = Testing, safety = Safe)]
function sleep(uint256 duration) external;
/// Expects a call to an address with the specified calldata.
/// Calldata can either be a strict or a partial match.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectCall(address callee, bytes calldata data) external;
/// Expects given number of calls to an address with the specified calldata.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectCall(address callee, bytes calldata data, uint64 count) external;
/// Expects a call to an address with the specified `msg.value` and calldata.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectCall(address callee, uint256 msgValue, bytes calldata data) external;
/// Expects given number of calls to an address with the specified `msg.value` and calldata.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectCall(address callee, uint256 msgValue, bytes calldata data, uint64 count) external;
/// Expect a call to an address with the specified `msg.value`, gas, and calldata.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectCall(address callee, uint256 msgValue, uint64 gas, bytes calldata data) external;
/// Expects given number of calls to an address with the specified `msg.value`, gas, and calldata.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectCall(address callee, uint256 msgValue, uint64 gas, bytes calldata data, uint64 count) external;
/// Expect a call to an address with the specified `msg.value` and calldata, and a *minimum* amount of gas.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectCallMinGas(address callee, uint256 msgValue, uint64 minGas, bytes calldata data) external;
/// Expect given number of calls to an address with the specified `msg.value` and calldata, and a *minimum* amount of gas.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectCallMinGas(address callee, uint256 msgValue, uint64 minGas, bytes calldata data, uint64 count)
external;
/// Prepare an expected log with (bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData.).
/// Call this function, then emit an event, then call a function. Internally after the call, we check if
/// logs were emitted in the expected order with the expected topics and data (as specified by the booleans).
#[cheatcode(group = Testing, safety = Unsafe)]
function expectEmit(bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData) external;
/// Same as the previous method, but also checks supplied address against emitting contract.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectEmit(bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData, address emitter)
external;
/// Prepare an expected log with all topic and data checks enabled.
/// Call this function, then emit an event, then call a function. Internally after the call, we check if
/// logs were emitted in the expected order with the expected topics and data.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectEmit() external;
/// Same as the previous method, but also checks supplied address against emitting contract.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectEmit(address emitter) external;
/// Prepare an expected anonymous log with (bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData.).
/// Call this function, then emit an anonymous event, then call a function. Internally after the call, we check if
/// logs were emitted in the expected order with the expected topics and data (as specified by the booleans).
#[cheatcode(group = Testing, safety = Unsafe)]
function expectEmitAnonymous(bool checkTopic0, bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData) external;
/// Same as the previous method, but also checks supplied address against emitting contract.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectEmitAnonymous(bool checkTopic0, bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData, address emitter)
external;
/// Prepare an expected anonymous log with all topic and data checks enabled.
/// Call this function, then emit an anonymous event, then call a function. Internally after the call, we check if
/// logs were emitted in the expected order with the expected topics and data.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectEmitAnonymous() external;
/// Same as the previous method, but also checks supplied address against emitting contract.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectEmitAnonymous(address emitter) external;
/// Expects an error on next call with any revert data.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectRevert() external;
/// Expects an error on next call that starts with the revert data.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectRevert(bytes4 revertData) external;
/// Expects an error on next call that exactly matches the revert data.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectRevert(bytes calldata revertData) external;
/// Expects an error on next cheatcode call with any revert data.
#[cheatcode(group = Testing, safety = Unsafe, status = Internal)]
function _expectCheatcodeRevert() external;
/// Expects an error on next cheatcode call that starts with the revert data.
#[cheatcode(group = Testing, safety = Unsafe, status = Internal)]
function _expectCheatcodeRevert(bytes4 revertData) external;
/// Expects an error on next cheatcode call that exactly matches the revert data.
#[cheatcode(group = Testing, safety = Unsafe, status = Internal)]
function _expectCheatcodeRevert(bytes calldata revertData) external;
/// Only allows memory writes to offsets [0x00, 0x60) ∪ [min, max) in the current subcontext. If any other
/// memory is written to, the test will fail. Can be called multiple times to add more ranges to the set.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectSafeMemory(uint64 min, uint64 max) external;
/// Stops all safe memory expectation in the current subcontext.
#[cheatcode(group = Testing, safety = Unsafe)]
function stopExpectSafeMemory() external;
/// Only allows memory writes to offsets [0x00, 0x60) ∪ [min, max) in the next created subcontext.
/// If any other memory is written to, the test will fail. Can be called multiple times to add more ranges
/// to the set.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectSafeMemoryCall(uint64 min, uint64 max) external;
/// Marks a test as skipped. Must be called at the top of the test.
#[cheatcode(group = Testing, safety = Unsafe)]
function skip(bool skipTest) external;
/// Asserts that the given condition is true.
#[cheatcode(group = Testing, safety = Safe)]
function assertTrue(bool condition) external pure;
/// Asserts that the given condition is true and includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertTrue(bool condition, string calldata error) external pure;
/// Asserts that the given condition is false.
#[cheatcode(group = Testing, safety = Safe)]
function assertFalse(bool condition) external pure;
/// Asserts that the given condition is false and includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertFalse(bool condition, string calldata error) external pure;
/// Asserts that two `bool` values are equal.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(bool left, bool right) external pure;
/// Asserts that two `bool` values are equal and includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(bool left, bool right, string calldata error) external pure;
/// Asserts that two `uint256` values are equal.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(uint256 left, uint256 right) external pure;
/// Asserts that two `uint256` values are equal and includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(uint256 left, uint256 right, string calldata error) external pure;
/// Asserts that two `int256` values are equal.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(int256 left, int256 right) external pure;
/// Asserts that two `int256` values are equal and includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(int256 left, int256 right, string calldata error) external pure;
/// Asserts that two `address` values are equal.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(address left, address right) external pure;
/// Asserts that two `address` values are equal and includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(address left, address right, string calldata error) external pure;
/// Asserts that two `bytes32` values are equal.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(bytes32 left, bytes32 right) external pure;
/// Asserts that two `bytes32` values are equal and includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(bytes32 left, bytes32 right, string calldata error) external pure;
/// Asserts that two `string` values are equal.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(string calldata left, string calldata right) external pure;
/// Asserts that two `string` values are equal and includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(string calldata left, string calldata right, string calldata error) external pure;
/// Asserts that two `bytes` values are equal.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(bytes calldata left, bytes calldata right) external pure;
/// Asserts that two `bytes` values are equal and includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(bytes calldata left, bytes calldata right, string calldata error) external pure;
/// Asserts that two arrays of `bool` values are equal.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(bool[] calldata left, bool[] calldata right) external pure;
/// Asserts that two arrays of `bool` values are equal and includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(bool[] calldata left, bool[] calldata right, string calldata error) external pure;
/// Asserts that two arrays of `uint256 values are equal.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(uint256[] calldata left, uint256[] calldata right) external pure;
/// Asserts that two arrays of `uint256` values are equal and includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(uint256[] calldata left, uint256[] calldata right, string calldata error) external pure;
/// Asserts that two arrays of `int256` values are equal.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(int256[] calldata left, int256[] calldata right) external pure;
/// Asserts that two arrays of `int256` values are equal and includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(int256[] calldata left, int256[] calldata right, string calldata error) external pure;
/// Asserts that two arrays of `address` values are equal.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(address[] calldata left, address[] calldata right) external pure;
/// Asserts that two arrays of `address` values are equal and includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(address[] calldata left, address[] calldata right, string calldata error) external pure;
/// Asserts that two arrays of `bytes32` values are equal.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(bytes32[] calldata left, bytes32[] calldata right) external pure;
/// Asserts that two arrays of `bytes32` values are equal and includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(bytes32[] calldata left, bytes32[] calldata right, string calldata error) external pure;
/// Asserts that two arrays of `string` values are equal.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(string[] calldata left, string[] calldata right) external pure;
/// Asserts that two arrays of `string` values are equal and includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(string[] calldata left, string[] calldata right, string calldata error) external pure;
/// Asserts that two arrays of `bytes` values are equal.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(bytes[] calldata left, bytes[] calldata right) external pure;
/// Asserts that two arrays of `bytes` values are equal and includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertEq(bytes[] calldata left, bytes[] calldata right, string calldata error) external pure;
/// Asserts that two `uint256` values are equal, formatting them with decimals in failure message.
#[cheatcode(group = Testing, safety = Safe)]
function assertEqDecimal(uint256 left, uint256 right, uint256 decimals) external pure;
/// Asserts that two `uint256` values are equal, formatting them with decimals in failure message.
/// Includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertEqDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure;
/// Asserts that two `int256` values are equal, formatting them with decimals in failure message.
#[cheatcode(group = Testing, safety = Safe)]
function assertEqDecimal(int256 left, int256 right, uint256 decimals) external pure;
/// Asserts that two `int256` values are equal, formatting them with decimals in failure message.
/// Includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertEqDecimal(int256 left, int256 right, uint256 decimals, string calldata error) external pure;
/// Asserts that two `bool` values are not equal.
#[cheatcode(group = Testing, safety = Safe)]
function assertNotEq(bool left, bool right) external pure;
/// Asserts that two `bool` values are not equal and includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertNotEq(bool left, bool right, string calldata error) external pure;
/// Asserts that two `uint256` values are not equal.
#[cheatcode(group = Testing, safety = Safe)]
function assertNotEq(uint256 left, uint256 right) external pure;
/// Asserts that two `uint256` values are not equal and includes error message into revert string on failure.
#[cheatcode(group = Testing, safety = Safe)]
function assertNotEq(uint256 left, uint256 right, string calldata error) external pure;