Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions noir-projects/noir-contracts/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ members = [
"contracts/schnorr_single_key_account_contract",
"contracts/stateful_test_contract",
"contracts/test_contract",
"contracts/test_log_contract",
"contracts/token_contract",
"contracts/token_blacklist_contract",
"contracts/token_bridge_contract",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "test_log_contract"
authors = [""]
compiler_version = ">=0.25.0"
type = "contract"

[dependencies]
aztec = { path = "../../../aztec-nr/aztec" }
value_note = { path = "../../../aztec-nr/value-note" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
contract TestLog {
use dep::aztec::prelude::PrivateSet;
use dep::value_note::value_note::ValueNote;

#[aztec(event)]
struct ExampleEvent {
value: Field,
}

#[aztec(storage)]
struct Storage {
example_set: PrivateSet<ValueNote>,
}

#[aztec(private)]
fn emit_encrypted_log(randomness: Field, event_type_id: Field, preimage: [Field; 6]) {
let header = context.get_header();
let msg_sender_ivpk_m = header.get_ivpk_m(&mut context, context.msg_sender());
let msg_sender_ovpk_m = header.get_ovpk_m(&mut context, context.msg_sender());

context.encrypt_and_emit_log(
context.this_address(),
randomness,
event_type_id,
msg_sender_ovpk_m,
msg_sender_ivpk_m,
preimage
);
}
}
1 change: 1 addition & 0 deletions yarn-project/aztec.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export {
createAztecNodeClient,
merkleTreeIds,
mockTx,
TaggedNote,
} from '@aztec/circuit-types';
export { NodeInfo } from '@aztec/types/interfaces';

Expand Down
3 changes: 3 additions & 0 deletions yarn-project/end-to-end/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ e2e-public-to-private-messaging:
e2e-state-vars:
DO +E2E_TEST --test=./src/e2e_state_vars.test.ts

e2e-logs:
DO +E2E_TEST --test=./src/e2e_logs.test.ts

e2e-static-calls:
DO +E2E_TEST --test=./src/e2e_static_calls.test.ts

Expand Down
53 changes: 53 additions & 0 deletions yarn-project/end-to-end/src/e2e_logs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { type AccountWalletWithSecretKey, Fr, TaggedNote } from '@aztec/aztec.js';
import { deriveMasterIncomingViewingSecretKey } from '@aztec/circuits.js';
import { makeTuple } from '@aztec/foundation/array';
import { TestLogContract } from '@aztec/noir-contracts.js';

import { jest } from '@jest/globals';

import { publicDeployAccounts, setup } from './fixtures/utils.js';

const TIMEOUT = 120_000;

describe('Logs', () => {
let testLogContract: TestLogContract;
jest.setTimeout(TIMEOUT);

let wallets: AccountWalletWithSecretKey[];

let teardown: () => Promise<void>;

beforeAll(async () => {
({ teardown, wallets } = await setup(2));

await publicDeployAccounts(wallets[0], wallets.slice(0, 2));

testLogContract = await TestLogContract.deploy(wallets[0]).send().deployed();
});

afterAll(() => teardown());

describe('emits an encrypted log', () => {
it('works', async () => {
const randomness = Fr.random();
const eventTypeId = Fr.random();
const preimage = makeTuple(6, Fr.random);

const tx = await testLogContract.methods.emit_encrypted_log(randomness, eventTypeId, preimage).prove();

const encryptedLogs = tx.encryptedLogs.unrollLogs();

expect(encryptedLogs.length).toBe(1);

const decryptedLog = TaggedNote.decryptAsIncoming(
encryptedLogs[0].data,
deriveMasterIncomingViewingSecretKey(wallets[0].getSecretKey()),
);

expect(decryptedLog!.notePayload.contractAddress).toStrictEqual(testLogContract.address);
expect(decryptedLog!.notePayload.storageSlot).toStrictEqual(randomness);
expect(decryptedLog!.notePayload.noteTypeId).toStrictEqual(eventTypeId);
expect(decryptedLog!.notePayload.note.items).toStrictEqual(preimage);
});
});
});