controlling the unit testing environment
Cheat codes
Since Hevm is an EVM implementation mainly dedicated to testing and exploration, it features a set of cheat codes
which can manipulate the environment in which the execution is run.
These can be accessed by calling into a contract (typically called Vm
) at address 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D
, which implements the following methods:
-
function warp(uint x) public
Sets the block timestamp tox
. -
function roll(uint x) public
Sets the block number tox
. -
function assume(bool b) public
Add the conditionb
to the assumption base for the current branch. This functions almost identically torequire
. -
function deal(uint usr, uint amt) public
Sets the eth balance ofusr
toamt
. Note that ifusr
is a symbolic address, then it must be the address of a contract that has already been deployed. This restriction is in place to ensure soundness of our symbolic address encoding with respect to potential aliasing of symbolic addresses. -
function store(address c, bytes32 loc, bytes32 val) public
Sets the slotloc
of contractc
toval
. -
function load(address c, bytes32 loc) public returns (bytes32 val)
Reads the slotloc
of contractc
. -
function sign(uint sk, bytes32 digest) public returns (uint8 v, bytes32 r, bytes32 s)
Signs thedigest
using the private keysk
. Note that signatures produced viahevm.sign
will leak the private key. -
function addr(uint sk) public returns (address addr)
Derives an ethereum address from the private keysk
. Note thathevm.addr(0)
will fail withBadCheatCode
as0
is an invalid ECDSA private key. -
function ffi(string[] calldata) external returns (bytes memory)
Executes the arguments as a command in the system shell and returns stdout. Expects abi encoded values to be returned from the shell or an error will be thrown. Note that this cheatcode means test authors can execute arbitrary code on user machines as part of a call todapp test
, for this reason all calls toffi
will fail unless the--ffi
flag is passed. -
function prank(address sender) public
Setsmsg.sender
to the specifiedsender
for the next call.