-
Notifications
You must be signed in to change notification settings - Fork 599
fix: processing events in contracts with no notes #14528
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
Merged
nventuro
merged 6 commits into
master
from
05-26-fix_processing_events_in_contracts_with_no_notes
May 27, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4316a2f
fix: processing events in contracts with no notes
benesjan 49dea45
contract finished
benesjan 96d4a9f
test finished - should fail now
benesjan 9a4642e
test fix
benesjan ff68a2e
the fix
benesjan c2d89e7
better comments
benesjan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
noir-projects/noir-contracts/contracts/test/event_only_contract/Nargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [package] | ||
| name = "event_only_contract" | ||
| authors = [""] | ||
| compiler_version = ">=0.25.0" | ||
| type = "contract" | ||
|
|
||
| [dependencies] | ||
| aztec = { path = "../../../../aztec-nr/aztec" } |
30 changes: 30 additions & 0 deletions
30
noir-projects/noir-contracts/contracts/test/event_only_contract/src/main.nr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| use aztec::macros::aztec; | ||
|
|
||
| /// This contract is used to test that the private event synchronization is working correctly even when the contract | ||
| /// doesn't work with notes. | ||
| #[aztec] | ||
| contract EventOnly { | ||
| use aztec::{ | ||
| event::event_interface::EventInterface, | ||
| macros::{events::event, functions::private}, | ||
| messages::logs::event::encode_and_encrypt_event_unconstrained, | ||
| protocol_types::traits::Serialize, | ||
| }; | ||
| use std::meta::derive; | ||
|
|
||
| #[derive(Serialize)] | ||
| #[event] | ||
| struct TestEvent { | ||
| value: Field, | ||
| } | ||
|
|
||
| #[private] | ||
| fn emit_event_for_msg_sender(value: Field) { | ||
| let sender = context.msg_sender(); | ||
| TestEvent { value }.emit(encode_and_encrypt_event_unconstrained( | ||
| &mut context, | ||
| sender, | ||
| sender, | ||
| )); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { type AccountWalletWithSecretKey, Fr } from '@aztec/aztec.js'; | ||
| import { EventOnlyContract, type TestEvent } from '@aztec/noir-test-contracts.js/EventOnly'; | ||
|
|
||
| import { jest } from '@jest/globals'; | ||
|
|
||
| import { ensureAccountsPubliclyDeployed, setup } from './fixtures/utils.js'; | ||
|
|
||
| const TIMEOUT = 120_000; | ||
|
|
||
| /// Tests that a private event can be obtained for a contract that does not work with notes. | ||
| describe('EventOnly', () => { | ||
| let eventOnlyContract: EventOnlyContract; | ||
| jest.setTimeout(TIMEOUT); | ||
|
|
||
| let wallets: AccountWalletWithSecretKey[]; | ||
| let teardown: () => Promise<void>; | ||
|
|
||
| beforeAll(async () => { | ||
| ({ teardown, wallets } = await setup(2)); | ||
| await ensureAccountsPubliclyDeployed(wallets[0], wallets.slice(0, 2)); | ||
| eventOnlyContract = await EventOnlyContract.deploy(wallets[0]).send().deployed(); | ||
| }); | ||
|
|
||
| afterAll(() => teardown()); | ||
|
|
||
| it('emits and retrieves a private event for a contract with no notes', async () => { | ||
| const value = Fr.random(); | ||
| const tx = await eventOnlyContract.methods.emit_event_for_msg_sender(value).send().wait(); | ||
|
|
||
| const events = await wallets[0].getPrivateEvents<TestEvent>( | ||
| eventOnlyContract.address, | ||
| EventOnlyContract.events.TestEvent, | ||
| tx.blockNumber!, | ||
| 1, | ||
| [wallets[0].getAddress()], | ||
| ); | ||
|
|
||
| expect(events.length).toBe(1); | ||
| expect(events[0].value).toBe(value.toBigInt()); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
"doesn't work with notes" sounds like notes are broken, or that if we added them the contract with break.