Skip to content

Commit 7453873

Browse files
committed
use .eth and .aztec instead of .l1 and .l2 (#1611)
In case we like the `.eth` and `.aztec` variation over `.l1` and `.l2` in cheatcodes! This would get merged into my docs pr #1585
1 parent 46b5e37 commit 7453873

File tree

4 files changed

+119
-119
lines changed

4 files changed

+119
-119
lines changed

docs/docs/dev_docs/testing/cheat_codes.md

+64-64
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ title: Cheat Codes
66

77
To help with testing, the sandbox is shipped with a set of cheatcodes.
88

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.
1010

1111
:::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.
1313
:::
1414

1515
### Aims
1616

1717
The guide will cover how to manipulate the state of the:
18-
- L1 blockchain;
18+
- Ethereum blockchain;
1919
- Aztec network.
2020

2121
### Dependencies
@@ -31,53 +31,53 @@ const aztecRpcClient = createAztecRpcClient(aztecRpcUrl);
3131
const cc = await CheatCodes.create(aztecRpcUrl, aztecRpcClient);
3232
```
3333

34-
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.
3535

36-
## L1 related cheatcodes
36+
## Ethereum related cheatcodes
3737
These are cheatcodes exposed from anvil conveniently wrapped for ease of use in the Sandbox.
3838

3939
### Interface
4040
```
41-
// Fetch current block number of L1
41+
// Fetch current block number of Ethereum
4242
public async blockNumber(): Promise<number>
4343
44-
// Fetch chain ID of L1
44+
// Fetch chain ID of the local Ethereum instance
4545
public async chainId(): Promise<number>
4646
47-
// Fetch current timestamp on L1
47+
// Fetch current timestamp on Ethereum
4848
public async timestamp(): Promise<number>
4949
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
5151
public async mine(numberOfBlocks = 1): Promise<void>
5252
53-
// Set the timestamp for the next block on L1.
53+
// Set the timestamp for the next block on Ethereum.
5454
public async setNextBlockTimestamp(timestamp: number): Promise<void>
5555
56-
// Dumps the current L1 chain state to a given file.
56+
// Dumps the current Ethereum chain state to a given file.
5757
public async dumpChainState(fileName: string): Promise<void>
5858
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.
6060
public async loadChainState(fileName: string): Promise<void>
6161
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
6363
public async load(contract: EthAddress, slot: bigint): Promise<bigint>
6464
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).
6666
public async store(contract: EthAddress, slot: bigint, value: bigint): Promise<void>
6767
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.
6969
public keccak256(baseSlot: bigint, key: bigint): bigint
7070
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.
7272
public async startImpersonating(who: EthAddress): Promise<void>
7373
74-
// Stop impersonating an account on L1 that you are currently impersonating.
74+
// Stop impersonating an account on Ethereum that you are currently impersonating.
7575
public async stopImpersonating(who: EthAddress): Promise<void>
7676
77-
// Set the bytecode for a L1 contract
77+
// Set the bytecode for a Ethereum contract
7878
public async etch(contract: EthAddress, bytecode: `0x${string}`): Promise<void>
7979
80-
// Get the bytecode for a L1 contract
80+
// Get the bytecode for a Ethereum contract
8181
public async getBytecode(contract: EthAddress): Promise<`0x${string}`>
8282
```
8383

@@ -89,11 +89,11 @@ public async blockNumber(): Promise<number>
8989
```
9090

9191
#### Description
92-
Fetches the current L1 block number.
92+
Fetches the current Ethereum block number.
9393

9494
#### Example
9595
```js
96-
const blockNumber = await cc.l1.blockNumber()
96+
const blockNumber = await cc.eth.blockNumber()
9797
```
9898

9999
### chainId
@@ -104,11 +104,11 @@ public async chainId(): Promise<number>
104104
```
105105

106106
#### Description
107-
Fetches the L1 chain ID
107+
Fetches the Ethereum chain ID
108108

109109
#### Example
110110
```js
111-
const chainId = await cc.l1.chainId()
111+
const chainId = await cc.eth.chainId()
112112
```
113113

114114
### timestamp
@@ -119,11 +119,11 @@ public async timestamp(): Promise<number>
119119
```
120120

121121
#### Description
122-
Fetches the current L1 timestamp.
122+
Fetches the current Ethereum timestamp.
123123

124124
#### Example
125125
```js
126-
const timestamp = await cc.l1.timestamp()
126+
const timestamp = await cc.eth.timestamp()
127127
```
128128

129129
### mine
@@ -134,13 +134,13 @@ public async mine(numberOfBlocks = 1): Promise<void>
134134
```
135135

136136
#### Description
137-
Mines the specified number of blocks on L1 (default 1).
137+
Mines the specified number of blocks on Ethereum (default 1).
138138

139139
#### Example
140140
```js
141-
const blockNum = await cc.l1.blockNumber();
142-
await cc.l1.mine(10) // mines 10 blocks
143-
const newBlockNum = await cc.l1.blockNumber(); // = blockNum + 10.
141+
const blockNum = await cc.eth.blockNumber();
142+
await cc.eth.mine(10) // mines 10 blocks
143+
const newBlockNum = await cc.eth.blockNumber(); // = blockNum + 10.
144144
```
145145

146146
### setNextBlockTimestamp
@@ -151,13 +151,13 @@ public async setNextBlockTimestamp(timestamp: number): Promise<void>
151151
```
152152

153153
#### 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.
155155
Remember that timestamp can only be set in the future and not in the past.
156156

157157
#### Example
158158
```js
159159
// // Set next block timestamp to 16 Aug 2023 10:54:30 GMT
160-
await cc.l1.setNextBlockTimestamp(1692183270)
160+
await cc.eth.setNextBlockTimestamp(1692183270)
161161
// next transaction you will do will have the timestamp as 1692183270
162162
```
163163

@@ -169,13 +169,13 @@ public async dumpChainState(fileName: string): Promise<void>
169169
```
170170

171171
#### Description
172-
Dumps the current L1 chain state to a file.
172+
Dumps the current Ethereum chain state to a file.
173173
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.
174174
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.
175175

176176
#### Example
177177
```js
178-
await cc.l1.dumpChainState('chain-state.json')
178+
await cc.eth.dumpChainState('chain-state.json')
179179
```
180180

181181
### loadChainState
@@ -186,12 +186,12 @@ public async loadChainState(fileName: string): Promise<void>
186186
```
187187

188188
#### 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.
191191

192192
#### Example
193193
```js
194-
await cc.l1.loadChainState('chain-state.json')
194+
await cc.eth.loadChainState('chain-state.json')
195195
```
196196

197197
### load
@@ -202,7 +202,7 @@ public async load(contract: EthAddress, slot: bigint): Promise<bigint>
202202
```
203203

204204
#### Description
205-
Loads the value at a storage slot of a L1 contract.
205+
Loads the value at a storage slot of a Ethereum contract.
206206

207207
#### Example
208208
```
@@ -211,7 +211,7 @@ Loads the value at a storage slot of a L1 contract.
211211
/// }
212212
213213
const leetContractAddress = EthAddress.fromString('0x1234...');
214-
const value = await cc.l1.load(leetContractAddress, BigInt(0));
214+
const value = await cc.eth.load(leetContractAddress, BigInt(0));
215215
console.log(value); // 1337
216216
```
217217

@@ -223,7 +223,7 @@ public async store(contract: EthAddress, slot: bigint, value: bigint): Promise<v
223223
```
224224

225225
#### Description
226-
Stores the value in storage slot on a L1 contract.
226+
Stores the value in storage slot on a Ethereum contract.
227227

228228
#### Example
229229
```
@@ -232,8 +232,8 @@ Stores the value in storage slot on a L1 contract.
232232
/// }
233233
234234
const leetContractAddress = EthAddress.fromString('0x1234...');
235-
await cc.l1.store(leetContractAddress, BigInt(0), BigInt(1000));
236-
const value = await cc.l1.load(leetContractAddress, BigInt(0));
235+
await cc.eth.store(leetContractAddress, BigInt(0), BigInt(1000));
236+
const value = await cc.eth.load(leetContractAddress, BigInt(0));
237237
console.log(value); // 1000
238238
```
239239

@@ -256,9 +256,9 @@ Computes the storage slot for a map key.
256256
257257
// find the storage slot for key `0xdead` in the balance map.
258258
const address = BigInt('0x000000000000000000000000000000000000dead');
259-
const slot = cc.l1.keccak256(1n, address);
259+
const slot = cc.eth.keccak256(1n, address);
260260
// store balance of 0xdead as 100
261-
await cc.l1.store(contractAddress, slot, 100n);
261+
await cc.eth.store(contractAddress, slot, 100n);
262262
```
263263

264264
### startImpersonating
@@ -269,12 +269,12 @@ public async startImpersonating(who: EthAddress): Promise<void>
269269
```
270270

271271
#### Description
272-
Start impersonating an L1 account.
272+
Start impersonating an Ethereum account.
273273
This allows you to use this address as a sender.
274274

275275
#### Example
276276
```js
277-
await cc.l1.startImpersonating(EthAddress.fromString(address));
277+
await cc.eth.startImpersonating(EthAddress.fromString(address));
278278
```
279279

280280
### stopImpersonating
@@ -285,12 +285,12 @@ public async stopImpersonating(who: EthAddress): Promise<void>
285285
```
286286

287287
#### Description
288-
Stop impersonating an L1 account.
288+
Stop impersonating an Ethereum account.
289289
Stops an active impersonation started by startImpersonating.
290290

291291
#### Example
292292
```js
293-
await cc.l1.stopImpersonating(EthAddress.fromString(address))
293+
await cc.eth.stopImpersonating(EthAddress.fromString(address))
294294
```
295295

296296
### getBytecode
@@ -301,11 +301,11 @@ public async getBytecode(contract: EthAddress): Promise<`0x${string}`>
301301
```
302302

303303
#### Description
304-
Get the bytecode for an L1 contract.
304+
Get the bytecode for an Ethereum contract.
305305

306306
#### Example
307307
```js
308-
const bytecode = await cc.l1.getBytecode(contract) // 0x6080604052348015610010...
308+
const bytecode = await cc.eth.getBytecode(contract) // 0x6080604052348015610010...
309309
```
310310

311311
### etch
@@ -316,24 +316,24 @@ public async etch(contract: EthAddress, bytecode: `0x${string}`): Promise<void>
316316
```
317317

318318
#### Description
319-
Set the bytecode for an L1 contract.
319+
Set the bytecode for an Ethereum contract.
320320

321321
#### Example
322322
```js
323323
const bytecode = `0x6080604052348015610010...`
324-
await cc.l1.etch(contract, bytecode)
325-
console.log(await cc.l1.getBytecode(contract)) // 0x6080604052348015610010...
324+
await cc.eth.etch(contract, bytecode)
325+
console.log(await cc.eth.getBytecode(contract)) // 0x6080604052348015610010...
326326
```
327327

328-
## L2 related cheatcodes
328+
## Aztec related cheatcodes
329329
These are cheatcodes specific to manipulating the state of Aztec rollup.
330330

331331
### Interface
332332
```
333-
// Get the current L2 block number
333+
// Get the current aztec block number
334334
public async blockNumber(): Promise<number>
335335
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.
337337
public async warp(to: number): Promise<void>
338338
339339
// 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>
351351
```
352352

353353
#### Description
354-
Get the current L2 block number.
354+
Get the current aztec block number.
355355

356356
#### Example
357357
```js
358-
const blockNumber = await cc.l2.blockNumber()
358+
const blockNumber = await cc.aztec.blockNumber()
359359
```
360360

361361
### warp
@@ -366,14 +366,14 @@ public async warp(to: number): Promise<void>
366366
```
367367

368368
#### 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.
371371

372372
#### Example
373373
```js
374-
const timestamp = await cc.l1.timestamp();
374+
const timestamp = await cc.eth.timestamp();
375375
const newTimestamp = timestamp + 100_000_000;
376-
await cc.l2.warp(newTimestamp);
376+
await cc.aztec.warp(newTimestamp);
377377

378378
// any noir contract calls that make use of current timestamp and is executed in the next rollup block will now read `newTimestamp`
379379
```
@@ -409,7 +409,7 @@ The baseSlot is specified in the noir contract.
409409
/// ...
410410
/// }
411411
412-
const slot = cc.l2.computeSlotInMap(1n, key)
412+
const slot = cc.aztec.computeSlotInMap(1n, key)
413413
```
414414

415415
### loadPublic
@@ -445,8 +445,8 @@ Note: One Field element occupies a storage slot. So structs with multiple field
445445
/// }
446446
447447
const address = AztecAddress.fromString("0x123...")
448-
const slot = cc.l2.computeSlotInMap(1n, key)
449-
const value = await cc.l2.loadPublic(address, slot);
448+
const slot = cc.aztec.computeSlotInMap(1n, key)
449+
const value = await cc.aztec.loadPublic(address, slot);
450450
```
451451
## Participate
452452

0 commit comments

Comments
 (0)