Skip to content

Commit

Permalink
docs: Add prevrandao cheatcode (#889)
Browse files Browse the repository at this point in the history
* Update cheatcodes README.md interface

* add `prevrandao.md` cheatcode description

* chore: add more context on docs
  • Loading branch information
Evalir authored May 11, 2023
1 parent 27e6423 commit f41642d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/cheatcodes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ interface CheatCodes {
function fee(uint256) external;
// Set block.difficulty
// Does not work from the Paris hard fork and onwards, and will revert instead.
function difficulty(uint256) external;
// Set block.prevrandao
// Does not work before the Paris hard fork, and will revert instead.
function prevrandao(bytes32) external;
// Set block.chainid
function chainId(uint256) external;
Expand Down Expand Up @@ -250,6 +255,9 @@ interface CheatCodes {
// Label an address in test traces
function label(address addr, string calldata label) external;
// Retrieve the label of an address
function getLabel(address addr) external returns (string memory);
// When fuzzing, generate new inputs if conditional not met
function assume(bool) external;
Expand Down
2 changes: 2 additions & 0 deletions src/cheatcodes/difficulty.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ function difficulty(uint256) external;

Sets `block.difficulty`.

If used with a post-merge EVM version (Paris and onwards), it will revert. In that case, use [`vm.prevrandao`](./prevrandao.md) instead.

### Examples

```solidity
Expand Down
20 changes: 20 additions & 0 deletions src/cheatcodes/prevrandao.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## `prevrandao`

### Signature

```solidity
function prevrandao(bytes32) external;
```

### Description

Sets `block.prevrandao`.

If used with an EVM version previous to the Paris hard fork, it will revert. In that case, use [`vm.difficulty`](./difficulty.md) instead.

### Examples

```solidity
vm.prevrandao(bytes32(uint256(42)));
emit log_uint(block.prevrandao); // 42
```

0 comments on commit f41642d

Please sign in to comment.