-
Notifications
You must be signed in to change notification settings - Fork 283
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: Initial cheatcode loadPublic
#1353
Conversation
import { AztecRPC } from '@aztec/types'; | ||
|
||
const toFr = (what: Fr | bigint): Fr => { | ||
return typeof what === 'bigint' ? new Fr(what) : what; |
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.
😂 "what"
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.
may i suggest "value" hahah
@@ -95,7 +104,12 @@ describe('e2e_public_token_contract', () => { | |||
expect(receipts.map(r => r.status)).toEqual(times(3, () => TxStatus.MINED)); | |||
expect(receipts.map(r => r.blockNumber)).toEqual(times(3, () => receipts[0].blockNumber)); | |||
|
|||
await expectAztecStorageSlot(logger, aztecRpcServer, contract, balanceSlot, recipient.toField(), mintAmount * 3n); | |||
const balance = await cc.l2.loadPublic( |
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.
given how often this is used, we can probably make another helper like getPublicBalanceOf(contractAddress, balanceSlot, recipient)
that calls this
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.
Actually, what is the reason for not using a view function? If supported, seems like it would be much more clear then 🤷
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.
lgtm, mostly naming nits etc
yarn-project/end-to-end/src/utils.ts
Outdated
@@ -533,35 +540,6 @@ export async function calculateAztecStorageSlot(slot: bigint, key: Fr): Promise< | |||
return storageSlot; //.value; |
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 function can be removed now the cheat code exists
@@ -72,7 +75,13 @@ describe('e2e_public_token_contract', () => { | |||
const receipt = await tx.getReceipt(); | |||
|
|||
expect(receipt.status).toBe(TxStatus.MINED); | |||
await expectAztecStorageSlot(logger, aztecRpcServer, contract, balanceSlot, recipient.toField(), mintAmount); | |||
|
|||
const balance = await cc.l2.loadPublic( |
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.
I prefered the shortness of the previous diff, i agree with rahul a helper function can be used here
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.
I redid it as this using the cheatcodes mainly to make the check that was performed more explicit.
public logger = createDebugLogger('aztec:cheat_codes:l1'), | ||
) {} | ||
|
||
async rpcCall(method: string, params: string) { |
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.
params would be more conviently an array that gets converted into a string in this method
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.
Ye, used a string as I just recalled there being some weirdness with how the params were passed, but might just be a weird initial setup. Will change it.
contract.address, | ||
cc.l2.computeSlotInMap(2n, account.address.toField()), | ||
); | ||
storageValues['private_debt'] = await cc.l2.loadPublic(contract.address, cc.l2.computeSlotInMap(3n, accountKey)); |
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.
utility funcs for stuff like this would read nicer
* @param slot - The storage slot to lookup | ||
* @returns The value stored at the given slot | ||
*/ | ||
public async loadPublic(who: AztecAddress, slot: Fr | bigint): Promise<Fr> { |
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.
load public is a bit ambiguous as a name, load public slot it more explicit
who could also just be address.
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.
Were using this naming to make it closer to foundry cheatcodes.
Description
Fixes #1281.
Introduces an initial
CheatCodes
class that will contain the non-intrusive cheatcodes, and can later be altered as a fork of the node.Checklist: