Conversation
|
|
||
| ## 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.
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.
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.
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.
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
Maddiaa0
left a comment
There was a problem hiding this comment.
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.
This has just made me think, should we make the cheat codes agnostic of hardhat / anvil
There was a problem hiding this comment.
hmm aztec uses anvil within the sandbox though
There was a problem hiding this comment.
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.
nit its probably worth being explicit about the erroring
| - @aztec/aztec.js | ||
|
|
||
| ### Initialisation | ||
| ```js |
There was a problem hiding this comment.
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 | ||
| ``` |
| These are cheatcodes specific to manipulating the state of Aztec rollup. | ||
|
|
||
| ### Interface | ||
| ``` |
|
|
||
| #### Example | ||
| ``` | ||
| /// struct Storage { |
There was a problem hiding this comment.
noir snippets can be annotated rust for better results
Maddiaa0
left a comment
There was a problem hiding this comment.
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.
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); // 1000Solidity 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 |
| #### 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.
| 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.
| 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.
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.
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