-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(docs): cheatcode docs #1585
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nits and grits
|
||
## Introduction | ||
|
||
Most of the time, simply testing your smart contract isn't enough. To manipulate the state of the Aztec blockchain, as well as test for specific reverts and events, the sandbox is shipped with a set of cheatcodes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The start is a little weird. It is mainly to help you in the testing that we want to provide a bit of cheat-codes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When mentioning specific reverts and such, we should probably have examples with that 👀 .
const value = await cc.l2.loadPublic(contract, 1n) // current_value is stored in slot 1 | ||
``` | ||
|
||
### computeSlotInMap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think it would be neat to flip the ordering of computeSlotInMap
and loadPublic
, mainly as we could then very easily show using the computed slot for reading balances or similar. Just to carve it in neon what people can use it for etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separately, the example is made with private storage, which you cannot access from cheatcodes etc. Think using public storage would be better, and then it can be bundled with the loadPublic
as mentioned.
cfd6998
to
5078689
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
temp review before pushing changes
|
||
Most of the time, simply testing your smart contract isn't enough. To manipulate the state of the Aztec blockchain, as well as test for specific reverts and events, the sandbox is shipped with a set of cheatcodes. | ||
|
||
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has just made me think, should we make the cheat codes agnostic of hardhat / anvil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm aztec uses anvil within the sandbox though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think anvil
will also accept the hardhat naming and is just used as aliases, so if we use the hardhat ones, it might cover both more easily.
4cb3ebf
to
32cdeb8
Compare
In case we like the `.eth` and `.aztec` variation over `.l1` and `.l2` in cheatcodes! This would get merged into my docs pr #1585
In case we like the `.eth` and `.aztec` variation over `.l1` and `.l2` in cheatcodes! This would get merged into my docs pr #1585
97b49ea
to
d75435a
Compare
|
||
#### Description | ||
Sets the timestamp (unix format in seconds) for the next mined block on Ethereum. | ||
Remember that timestamp can only be set in the future and not in the past. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit its probably worth being explicit about the erroring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably related to: #1585 (comment)
- @aztec/aztec.js | ||
|
||
### Initialisation | ||
```js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should get better highlighting using `ts rather than js
These are cheatcodes exposed from anvil/hardhat conveniently wrapped for ease of use in the Sandbox. | ||
|
||
### Interface | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
annotate `ts
These are cheatcodes specific to manipulating the state of Aztec rollup. | ||
|
||
### Interface | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
annotate ts
|
||
#### Example | ||
``` | ||
/// struct Storage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noir snippets can be annotated rust for better results
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall great content, however noir snippets can be annotated with rust, the ones currently js should be ts to get better highlighting and solidity ones can be separated rather than inline commented and annotated with
solidity
``` | ||
/// contract LeetContract { | ||
/// uint256 private leet = 1337; // slot 0 | ||
/// } | ||
|
||
const leetContractAddress = EthAddress.fromString('0x1234...'); | ||
await cc.eth.store(leetContractAddress, BigInt(0), BigInt(1000)); | ||
const value = await cc.eth.load(leetContractAddress, BigInt(0)); | ||
console.log(value); // 1000 | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contract LeetContract {
uint256 private leet = 1337; // slot 0
}
const leetContractAddress = EthAddress.fromString('0x1234...');
await cc.eth.store(leetContractAddress, BigInt(0), BigInt(1000));
const value = await cc.eth.load(leetContractAddress, BigInt(0));
console.log(value); // 1000
Solidity blocks can be annotated with solidity, they arent perfect in docusaurus but it does offer some highlighting.
In case we like the `.eth` and `.aztec` variation over `.l1` and `.l2` in cheatcodes! This would get merged into my docs pr #1585
d75435a
to
d429f42
Compare
#### Example | ||
```rust | ||
struct Storage { | ||
// highlight-next-line:PublicState |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this still required
#### Description | ||
Loads the value stored at the given slot in the public storage of the given contract. | ||
|
||
Note: One Field element occupies a storage slot. So structs with multiple field elements won't fit in a single slot. So using loadPublic would only load a part of the struct (depending on the size of the attributes within it). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: One Field element occupies a storage slot. So structs with multiple field elements won't fit in a single slot. So using loadPublic would only load a part of the struct (depending on the size of the attributes within it). | |
Note: One Field element occupies a storage slot. Hence, structs with multiple field elements will be spread over multiple slots, rather they will be spread over multiple sequential slots. Using loadPublic will only load a single field of the struct (depending on the size of the attributes within it). |
Id reword this slightly
|
||
Keep up with the latest discussion and join the conversation in the [Aztec forum](https://discourse.aztec.network). | ||
|
||
You can also use the above link to request for more cheatcodes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also use the above link to request for more cheatcodes. | |
You can also use the above link to request more cheatcodes. |
#### Description | ||
Dumps the current Ethereum chain state to a file. | ||
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. | ||
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The uniswap example here is really specific to our testing case and probably confusing without context. Lets drop it, people looking for this feature likely have in mind a specific use case
Co-authored-by: Lasse Herskind <16536249+LHerskind@users.noreply.github.com>
In case we like the `.eth` and `.aztec` variation over `.l1` and `.l2` in cheatcodes! This would get merged into my docs pr #1585
3be10c8
to
89c3d8e
Compare
#### Description | ||
Dumps the current Ethereum chain state to a file. | ||
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. | ||
When combined with `loadChainState()` cheatcode, it can be let you easily import the current state of mainnet into the Anvil instance of the sandbox. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wording is a little weird here, it can be let you
and it might not be the current
state. Maybe fine to point to the other cheatcode and say use in combination.
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 be used in combination with `loadChainState()` |
fIX #1458