Skip to content

Commit 027d387

Browse files
authored
add documentation for startPrank and stopPrank (#606)
1 parent 967c7ab commit 027d387

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

Diff for: docs/src/SUMMARY.md

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
- [setNonce](./cheatcodes/set_nonce.md)
5656
- [coinbase](./cheatcodes/coinbase.md)
5757
- [prank](./cheatcodes/prank.md)
58+
- [startPrank](./cheatcodes/start_prank.md)
59+
- [stopPrank](./cheatcodes/stop_prank.md)
5860
- [prankHere](./cheatcodes/prank_here.md)
5961
- [ffi](./cheatcodes/ffi.md)
6062
- [addr](./cheatcodes/addr.md)

Diff for: docs/src/cheatcodes/cheatcodes_overview.md

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ interface StdCheats {
4242
// Sets the *next* call's msg.sender to be the input address
4343
function prank(address) external;
4444
45+
// Sets all subsequent call's msg.sender (until stopPrank is called) to be the input address
46+
function startPrank(address) external;
47+
48+
// Stops a previously called startPrank
49+
function stopPrank() external;
50+
4551
// Set msg.sender to the input address until the current call exits
4652
function prankHere(address) external;
4753

Diff for: docs/src/cheatcodes/start_prank.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# `startPrank`
2+
3+
## Description
4+
5+
The `startPrank` cheatcode will set the `msg.sender` for all subsequent calls until `stopPrank` is called. This is in
6+
contrast to [`prank`](./prank.md) where `prank` only applies to the _next_ message call.
7+
8+
## Example
9+
10+
```solidity
11+
contract TestContract {
12+
address owner = address(123);
13+
ImportantContract ic;
14+
AnotherImportantContract aic;
15+
16+
function deployImportantContract() public {
17+
require(msg.sender == owner);
18+
19+
// Deploy important contract
20+
ic = new ImportantContract(msg.sender);
21+
}
22+
23+
function deployAnotherImportantContract() public {
24+
require(msg.sender == owner);
25+
26+
// Deploy important contract
27+
ic = new AnotherImportantContract(msg.sender);
28+
}
29+
30+
function test() public {
31+
// Obtain our cheat code contract reference.
32+
IStdCheats cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
33+
34+
// Prank and deploy important contracts
35+
cheats.startPrank(owner);
36+
deployImportantContract();
37+
deployAnotherImportantContract();
38+
cheats.stopPrank();
39+
40+
assert(ic.owner() == owner);
41+
assert(aic.owner() == owner);
42+
}
43+
}
44+
```
45+
46+
## Function Signature
47+
48+
```solidity
49+
function startPrank(address) external;
50+
```

Diff for: docs/src/cheatcodes/stop_prank.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# `stopPrank`
2+
3+
## Description
4+
5+
Stops an active prank started by [`startPrank`](./start_prank.md), resetting `msg.sender`
6+
7+
## Function Signature
8+
9+
```solidity
10+
function stopPrank() external;
11+
```

0 commit comments

Comments
 (0)