feat: testing private events from Aztec.nr#20640
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
e3ee438 to
21ff0cc
Compare
557d5c7 to
58006da
Compare
58006da to
7d799f3
Compare
7d799f3 to
74001a2
Compare
74001a2 to
7dc8ff2
Compare
noir-projects/aztec-nr/aztec/src/test/helpers/test_environment/test/events.nr
Show resolved
Hide resolved
|
@nchamo LMK if you would not feel comfortable enough yet to review this. Can re-assing if that's the case. |
noir-projects/aztec-nr/aztec/src/test/helpers/test_environment/test/events.nr
Outdated
Show resolved
Hide resolved
| // experimental | ||
| pub(crate) unconstrained fn get_private_events( | ||
| selector: EventSelector, | ||
| pub unconstrained fn get_private_events<Event>( |
There was a problem hiding this comment.
| pub unconstrained fn get_private_events<Event>( | |
| /// Experimental - there may be breaking API changes. | |
| pub unconstrained fn get_private_events<Event>( |
We want to somehow flag this. I imagine something like get_private_events will very likely take some sort of filter or something.
There was a problem hiding this comment.
If we're making this pub, we should also at the very least document that we only search for events in the last block.
There was a problem hiding this comment.
Added the docs in f575bfa and this how they get rendered:
Do you like it?
BTW do you know if there is a way how the MAX_PRIVATE_EVENTS_PER_TXE_QUERY constant could get rendered there? I tried to Claude it but it says there is no way.
There was a problem hiding this comment.
Hmm I wishit were more obvious. Perhaps we could do horizontal separators with ---?
like
---
this
There was a problem hiding this comment.
I don't follow. What is supposed to be more obvious? And where do you want me to place the separator?
| from: AztecAddress, | ||
| to: AztecAddress, | ||
| amount: u128, | ||
| pub struct Transfer { |
There was a problem hiding this comment.
We probably want to either make all of these pub, or suggest that they are made pub.
There was a problem hiding this comment.
Documented this in 908c4d6
Is that would you meant by suggesting making them pub, right?
There was a problem hiding this comment.
I meant that the event macro should do it, linking to the doc piece you just wrote. We don't need pub though do we?
There was a problem hiding this comment.
I was originally hesitant to make the event macro apply the pub there as it makes it feel a bit more magical (events are just structs but with some extra stuff) but given that by definition they are a piece of data to be consumed by "the world out of the contract" I came to agree that it makes sense to not be annoying here and just auto-expose it.
Addressed in 6da2825
But I have one question about this:
linking to the doc piece you just wrote
Isn't it strange to link from the event macro code docs to the doc piece I wrote given that the event macro docs are way more "low-level"? Or is that not what you meant?
Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com>
3660419 to
908c4d6
Compare
Flakey Tests🤖 says: This CI run detected 1 tests that failed, but were tolerated due to a .test_patterns.yml entry. |
noir-projects/aztec-nr/aztec/src/test/helpers/test_environment/test/events.nr
Outdated
Show resolved
Hide resolved
| /// Returns up to `MAX_PRIVATE_EVENTS_PER_TXE_QUERY` private events of type `Event` that were emitted by | ||
| /// `contract_address` and available in `scope`. |
There was a problem hiding this comment.
This is inaccurate as it is missing the fact that it only searches the last block. It also does not explain wtf scope is.
There was a problem hiding this comment.
Somewhat addressed in 3361896
But I am not sure about this:
This is inaccurate as it is missing the fact that it only searches the last block.
Do you mean by that "up to last block"?
By searching only the last block I imagine events emitted in the last block. Or is your mental model here that "last block" contains any state that got accumulated by the chain up to that block?
I don't know the code of TXE enough to be sure here.
noir-projects/noir-contracts/contracts/app/token_contract/src/test/utils.nr
Outdated
Show resolved
Hide resolved
Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com>
Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com>
Wraps the low-level oracle so users don't need to import and call the oracle directly. This provides a higher-level API consistent with the rest of TestEnvironment. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Short first paragraph, clarify that only last block is searched, explain what scope means (event recipient), mention self.emit, and point users to TestEnvironment method instead of using the oracle directly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move experimental warning to top of section as a note block. Use env.get_private_events instead of importing the oracle directly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ents_from_aztec.nr
|
@nventuro Re-requested a review here even though the PR is not yet finished as I need some clarifications - left the questions in unresolved discussions above. Also please LMK if merging |

Note: We will probably want to merge
SerializeandDeserializetraits before merging this as it would make the diff smaller - waiting for response from Mitch to see whether it's a good time to do that change.Closes https://linear.app/aztec-labs/issue/F-300/feature-access-events-in-aztecnr-tests