You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/docs/dev_docs/testing/cheat_codes.md
+64-64
Original file line number
Diff line number
Diff line change
@@ -6,16 +6,16 @@ title: Cheat Codes
6
6
7
7
To help with testing, the sandbox is shipped with a set of cheatcodes.
8
8
9
-
Cheatcodes allow you to change the time of the L2 block, load certain state or more easily manipulate L1 instead of having to write dedicated RPC calls to anvil.
9
+
Cheatcodes allow you to change the time of the Aztec block, load certain state or more easily manipulate Ethereum instead of having to write dedicated RPC calls to anvil.
10
10
11
11
:::info Prerequisites
12
-
If you aren't familiar with [Anvil](https://book.getfoundry.sh/anvil/), we recommend reading up on that since Aztec Sandbox uses Anvil as the local L1 instance.
12
+
If you aren't familiar with [Anvil](https://book.getfoundry.sh/anvil/), we recommend reading up on that since Aztec Sandbox uses Anvil as the local Ethereum instance.
13
13
:::
14
14
15
15
### Aims
16
16
17
17
The guide will cover how to manipulate the state of the:
There are two properties of the CheatCodes class - `l1` and `l2` for cheatcodes relating to the L1 and L2 (Aztec) respectively.
34
+
There are two properties of the CheatCodes class - `eth` and `aztec` for cheatcodes relating to the Ethereum blockchain (L1) and the Aztec network (L2) respectively.
35
35
36
-
## L1 related cheatcodes
36
+
## Ethereum related cheatcodes
37
37
These are cheatcodes exposed from anvil conveniently wrapped for ease of use in the Sandbox.
38
38
39
39
### Interface
40
40
```
41
-
// Fetch current block number of L1
41
+
// Fetch current block number of Ethereum
42
42
public async blockNumber(): Promise<number>
43
43
44
-
// Fetch chain ID of L1
44
+
// Fetch chain ID of the local Ethereum instance
45
45
public async chainId(): Promise<number>
46
46
47
-
// Fetch current timestamp on L1
47
+
// Fetch current timestamp on Ethereum
48
48
public async timestamp(): Promise<number>
49
49
50
-
// Mine a given number of blocks on L1. Mines 1 block by default
50
+
// Mine a given number of blocks on Ethereum. Mines 1 block by default
51
51
public async mine(numberOfBlocks = 1): Promise<void>
52
52
53
-
// Set the timestamp for the next block on L1.
53
+
// Set the timestamp for the next block on Ethereum.
54
54
public async setNextBlockTimestamp(timestamp: number): Promise<void>
55
55
56
-
// Dumps the current L1 chain state to a given file.
56
+
// Dumps the current Ethereum chain state to a given file.
57
57
public async dumpChainState(fileName: string): Promise<void>
58
58
59
-
// Loads the L1 chain state from a file. You may use `dumpChainState()` to save the state of the L1 chain to a file and later load it.
59
+
// Loads the Ethereum chain state from a file. You may use `dumpChainState()` to save the state of the Ethereum chain to a file and later load it.
60
60
public async loadChainState(fileName: string): Promise<void>
61
61
62
-
// Load the value at a storage slot of a contract address on L1
62
+
// Load the value at a storage slot of a contract address on Ethereum
63
63
public async load(contract: EthAddress, slot: bigint): Promise<bigint>
64
64
65
-
// Set the value at a storage slot of a contract address on L1 (e.g. modify a storage variable on your portal contract or even the rollup contract).
65
+
// Set the value at a storage slot of a contract address on Ethereum (e.g. modify a storage variable on your portal contract or even the rollup contract).
66
66
public async store(contract: EthAddress, slot: bigint, value: bigint): Promise<void>
67
67
68
-
// Computes the slot value for a given map and key on L1. A convenient wrapper to find the appropriate storage slot to load or overwrite the state.
68
+
// Computes the slot value for a given map and key on Ethereum. A convenient wrapper to find the appropriate storage slot to load or overwrite the state.
69
69
public keccak256(baseSlot: bigint, key: bigint): bigint
70
70
71
-
// Let you send transactions on L1 impersonating an externally owned or contract, without knowing the private key.
71
+
// Let you send transactions on Ethereum impersonating an externally owned or contract, without knowing the private key.
72
72
public async startImpersonating(who: EthAddress): Promise<void>
73
73
74
-
// Stop impersonating an account on L1 that you are currently impersonating.
74
+
// Stop impersonating an account on Ethereum that you are currently impersonating.
75
75
public async stopImpersonating(who: EthAddress): Promise<void>
76
76
77
-
// Set the bytecode for a L1 contract
77
+
// Set the bytecode for a Ethereum contract
78
78
public async etch(contract: EthAddress, bytecode: `0x${string}`): Promise<void>
79
79
80
-
// Get the bytecode for a L1 contract
80
+
// Get the bytecode for a Ethereum contract
81
81
public async getBytecode(contract: EthAddress): Promise<`0x${string}`>
82
82
```
83
83
@@ -89,11 +89,11 @@ public async blockNumber(): Promise<number>
89
89
```
90
90
91
91
#### Description
92
-
Fetches the current L1 block number.
92
+
Fetches the current Ethereum block number.
93
93
94
94
#### Example
95
95
```js
96
-
constblockNumber=awaitcc.l1.blockNumber()
96
+
constblockNumber=awaitcc.eth.blockNumber()
97
97
```
98
98
99
99
### chainId
@@ -104,11 +104,11 @@ public async chainId(): Promise<number>
104
104
```
105
105
106
106
#### Description
107
-
Fetches the L1 chain ID
107
+
Fetches the Ethereum chain ID
108
108
109
109
#### Example
110
110
```js
111
-
constchainId=awaitcc.l1.chainId()
111
+
constchainId=awaitcc.eth.chainId()
112
112
```
113
113
114
114
### timestamp
@@ -119,11 +119,11 @@ public async timestamp(): Promise<number>
119
119
```
120
120
121
121
#### Description
122
-
Fetches the current L1 timestamp.
122
+
Fetches the current Ethereum timestamp.
123
123
124
124
#### Example
125
125
```js
126
-
consttimestamp=awaitcc.l1.timestamp()
126
+
consttimestamp=awaitcc.eth.timestamp()
127
127
```
128
128
129
129
### mine
@@ -134,13 +134,13 @@ public async mine(numberOfBlocks = 1): Promise<void>
134
134
```
135
135
136
136
#### Description
137
-
Mines the specified number of blocks on L1 (default 1).
137
+
Mines the specified number of blocks on Ethereum (default 1).
@@ -151,13 +151,13 @@ public async setNextBlockTimestamp(timestamp: number): Promise<void>
151
151
```
152
152
153
153
#### Description
154
-
Sets the timestamp (unix format in seconds) for the next mined block on L1.
154
+
Sets the timestamp (unix format in seconds) for the next mined block on Ethereum.
155
155
Remember that timestamp can only be set in the future and not in the past.
156
156
157
157
#### Example
158
158
```js
159
159
// // Set next block timestamp to 16 Aug 2023 10:54:30 GMT
160
-
awaitcc.l1.setNextBlockTimestamp(1692183270)
160
+
awaitcc.eth.setNextBlockTimestamp(1692183270)
161
161
// next transaction you will do will have the timestamp as 1692183270
162
162
```
163
163
@@ -169,13 +169,13 @@ public async dumpChainState(fileName: string): Promise<void>
169
169
```
170
170
171
171
#### Description
172
-
Dumps the current L1 chain state to a file.
172
+
Dumps the current Ethereum chain state to a file.
173
173
Stores a hex string representing the complete state of the chain in a file with the provided path. Can be re-imported into a fresh/restarted instance of Anvil to reattain the same state.
174
174
When combined with `loadChainState()` cheatcode, it can be let you easily import the current state of mainnet into the Anvil instance of the sandbox, to use Uniswap for example.
175
175
176
176
#### Example
177
177
```js
178
-
awaitcc.l1.dumpChainState('chain-state.json')
178
+
awaitcc.eth.dumpChainState('chain-state.json')
179
179
```
180
180
181
181
### loadChainState
@@ -186,12 +186,12 @@ public async loadChainState(fileName: string): Promise<void>
186
186
```
187
187
188
188
#### Description
189
-
Loads the L1 chain state from a file which contains a hex string representing an L1 state.
190
-
When given a file previously written to by `cc.l1.dumpChainState()`, it merges the contents into the current chain state. Will overwrite any colliding accounts/storage slots.
189
+
Loads the Ethereum chain state from a file which contains a hex string representing an Ethereum state.
190
+
When given a file previously written to by `cc.eth.dumpChainState()`, it merges the contents into the current chain state. Will overwrite any colliding accounts/storage slots.
These are cheatcodes specific to manipulating the state of Aztec rollup.
330
330
331
331
### Interface
332
332
```
333
-
// Get the current L2 block number
333
+
// Get the current aztec block number
334
334
public async blockNumber(): Promise<number>
335
335
336
-
// Set time of the next execution on L2. It also modifies time on L1 for next execution and stores this time as the last rollup block on the rollup contract.
336
+
// Set time of the next execution on aztec. It also modifies time on Ethereum for next execution and stores this time as the last rollup block on the rollup contract.
337
337
public async warp(to: number): Promise<void>
338
338
339
339
// Loads the value stored at the given slot in the public storage of the given contract.
@@ -351,11 +351,11 @@ public async blockNumber(): Promise<number>
351
351
```
352
352
353
353
#### Description
354
-
Get the current L2 block number.
354
+
Get the current aztec block number.
355
355
356
356
#### Example
357
357
```js
358
-
constblockNumber=awaitcc.l2.blockNumber()
358
+
constblockNumber=awaitcc.aztec.blockNumber()
359
359
```
360
360
361
361
### warp
@@ -366,14 +366,14 @@ public async warp(to: number): Promise<void>
366
366
```
367
367
368
368
#### Description
369
-
Sets the time of L1 and the time of the next L2 block.
370
-
Like with the corresponding L1 cheatcode, time can only be set in the future, not the past.
369
+
Sets the time on Ethereum and the time of the next block on Aztec.
370
+
Like with the corresponding Ethereum cheatcode, time can only be set in the future, not the past.
371
371
372
372
#### Example
373
373
```js
374
-
consttimestamp=awaitcc.l1.timestamp();
374
+
consttimestamp=awaitcc.eth.timestamp();
375
375
constnewTimestamp= timestamp +100_000_000;
376
-
awaitcc.l2.warp(newTimestamp);
376
+
awaitcc.aztec.warp(newTimestamp);
377
377
378
378
// any noir contract calls that make use of current timestamp and is executed in the next rollup block will now read `newTimestamp`
379
379
```
@@ -409,7 +409,7 @@ The baseSlot is specified in the noir contract.
409
409
/// ...
410
410
/// }
411
411
412
-
const slot = cc.l2.computeSlotInMap(1n, key)
412
+
const slot = cc.aztec.computeSlotInMap(1n, key)
413
413
```
414
414
415
415
### loadPublic
@@ -445,8 +445,8 @@ Note: One Field element occupies a storage slot. So structs with multiple field
0 commit comments