-
Notifications
You must be signed in to change notification settings - Fork 0
/
cheatcodes.txt
25 lines (23 loc) · 3.05 KB
/
cheatcodes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Foundry Cheatcodes:
function warp(uint x) public //Sets the block timestap to x.
function difficulty(uint x) public //sets the block difficulty x
function roll(uint x) public //sets the block number to x
function coinbase(address c) //sets the block coinbase to c
function store(address c, bytes32 loc, bytes32 val) public //Sets the slot loc of contract c to val
function load(address c, bytes32 loc) public returs (bytes32 val) //Read the slot loc of contract
function sign(uint sk, bytes32 digest) public returns (uint8 v, byres32 r, bytes32 s) //Signs the digest using the private key sk. note that signatures produced via hevm.sign will leak the private key
function addr(uint sk) public returns (address addr) //Derives an ethereum address from the private key sk. Note that hevm.addr(0) will fail with BadCheatCode as 0 is invalid ECDSA private key. sk values above the secp256k1 curve order, near the max uint will also fail.
function ffi(string[] calldata) external returns (bytes memory) //Executes the arguements as a command in the system shell and returs stdout. Note that this cheatcode means test authors can execute arbitrary code on user machines as part of a call to forge test, for this reason all calls to ffi will fail unless the --ffi flag is passed.
function deal(address who, uint256 amount) //sets an accounts balance
function etch(address where, bytes memory what) //sets the contract code at some address contract code
function prank(address sender) //Performs the next smart contract call as another address (prank just changes msg.sender Tx still occurs as normal)
function startPrank(address sender) //Performs smart contract calls as another address. The accont impersonatation lasts until the end of the transaction, or until stopPrank is called.
function startParnk(address sender, address origin) //Performs smart contract calls as another address, while also setting tx.origin. The account impersonation lasts until the end of the transaction, or until stopPrank is called.
function expectRevert(<overloaded> expectedError) //Tells the evm to expect that the next call reverts with specified error bytes. Valid input types: bytes, and bytes4. Implicitly, strings get converted to bytes except when shorter than 4, in which case you will need to case explicitly to bytes.
function expectEmit(bool,bool,bool,bool) external: //Expects the next emitted event. Params check topic 1, topic 2, topic 3 and data are the same.
function expectEmit(bool,bool,bool,bool,address) external: Expects the next emitted event. Params check topic 1, topic 2, topic 3 and data are the same. Also checks supplied address against address of originating contract.
function label(address addr, string calldata label) external //label an address in test traces.
function assume(bool) external //when fuzzing, generate new inputs if conditional not met
function setnonce(address account, uint64 nonce) external //set nonce for an account, increment only.
function getNonce(address account) //Get nonce for an account
function chainId(uint x) public //sets the block chainid to x