Skip to content

Commit

Permalink
Add vm.sleep() & vm.unixTime() cheatcodes (#1021)
Browse files Browse the repository at this point in the history
* Add vm.sleep() docs

* Add vm.unixTime() docs
  • Loading branch information
Tudmotu authored Oct 2, 2023
1 parent a74c123 commit da133c2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@
- [`projectRoot`](./cheatcodes/project-root.md)
- [`getCode`](./cheatcodes/get-code.md)
- [`getDeployedCode`](./cheatcodes/get-deployed-code.md)
- [`sleep`](./cheatcodes/sleep.md)
- [`unixTime`](./cheatcodes/unix-time.md)
- [`setEnv`](./cheatcodes/set-env.md)
- [`envOr`](./cheatcodes/env-or.md)
- [`envBool`](./cheatcodes/env-bool.md)
Expand Down
2 changes: 2 additions & 0 deletions src/cheatcodes/external.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
- [`projectRoot`](./project-root.md)
- [`getCode`](./get-code.md)
- [`getDeployedCode`](./get-deployed-code.md)
- [`sleep`](./sleep.md)
- [`unixTime`](./unix-time.md)
- [`setEnv`](./set-env.md)
- [`envOr`](./env-or.md)
- [`envBool`](./env-bool.md)
Expand Down
18 changes: 18 additions & 0 deletions src/cheatcodes/sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## `sleep`

### Signature

```solidity
function sleep(uint256 milliseconds) external;
```

### Description

Sleeps for a given amount of milliseconds.

### Examples

```solidity
vm.sleep(10_000); // Halts execution for 10 seconds
```

21 changes: 21 additions & 0 deletions src/cheatcodes/unix-time.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## `unixTime`

### Signature

```solidity
function unixTime() external returns (uint milliseconds);
```

### Description

Returns the time since unix epoch in milliseconds.

### Examples

```solidity
uint start = vm.unixTime();
vm.sleep(10_000); // Halts execution for 10 seconds
uint end = vm.unixTime();
assertEq(end - start, 10_000);
```

0 comments on commit da133c2

Please sign in to comment.