From 0dcbc1d12d51cd3e282acf9c7d20eb7750dde055 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 19 Dec 2024 03:43:13 +0000 Subject: [PATCH] WIP --- .../aztec-nr/aztec/src/oracle/pxe_store.nr | 4 +-- .../contracts/test_contract/src/main.nr | 15 ++++---- .../end-to-end/src/e2e_pxe_store.test.ts | 35 +++++++++++++++++++ 3 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 yarn-project/end-to-end/src/e2e_pxe_store.test.ts diff --git a/noir-projects/aztec-nr/aztec/src/oracle/pxe_store.nr b/noir-projects/aztec-nr/aztec/src/oracle/pxe_store.nr index edb417534cc9..46c43bb2ed1f 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/pxe_store.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/pxe_store.nr @@ -2,8 +2,8 @@ unconstrained fn store_oracle(key: Field, values: [Field; N]) -> Field {} /// Store an array of values in local PXE database. The data is scoped to the current contract. -pub unconstrained fn store(key: Field, values: [Field; N]) -> Field { - store_oracle(key, values) +pub unconstrained fn store(key: Field, values: [Field; N]) { + let _ = store_oracle(key, values); } #[oracle(load)] diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr index ed3918d1f68b..cb41ace264d9 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -32,7 +32,7 @@ contract Test { note_getter::{get_notes, view_notes}, note_getter_options::NoteStatus, }, - oracle::random::random, + oracle::pxe_store::{load, store}, utils::comparison::Comparator, }; use dep::token_portal_content_hash_lib::{ @@ -458,16 +458,19 @@ contract Test { constant.value } + unconstrained fn store_in_pxe_store(key: Field, values: [Field; 3]) { + store(key, values); + } + + unconstrained fn load_from_pxe_store(key: Field) -> pub [Field; 3] { + load(key) + } + #[private] fn test_nullifier_key_freshness(address: AztecAddress, public_nullifying_key: Point) { assert_eq(get_public_keys(address).npk_m.inner, public_nullifying_key); } - // Purely exists for testing - unconstrained fn get_random(kinda_seed: Field) -> pub Field { - kinda_seed * random() - } - pub struct DummyNote { amount: Field, secret_hash: Field, diff --git a/yarn-project/end-to-end/src/e2e_pxe_store.test.ts b/yarn-project/end-to-end/src/e2e_pxe_store.test.ts new file mode 100644 index 000000000000..0430e7cd35cc --- /dev/null +++ b/yarn-project/end-to-end/src/e2e_pxe_store.test.ts @@ -0,0 +1,35 @@ +import { + type Wallet +} from '@aztec/aztec.js'; +import { TestContract } from '@aztec/noir-contracts.js/Test'; + +import { jest } from '@jest/globals'; + +import { setup } from './fixtures/utils.js'; + +const TIMEOUT = 120_000; + +// TODO(#10724): Nuke this once the linked issue is implemented. Made this ugly test to check it works when first +// implementing this. +describe('Keys', () => { + jest.setTimeout(TIMEOUT); + + let teardown: () => Promise; + + let testContract: TestContract; + + beforeAll(async () => { + let wallet: Wallet; + ({ teardown, wallet } = await setup(1)); + testContract = await TestContract.deploy(wallet).send().deployed(); + }); + + afterAll(() => teardown()); + + describe('using nsk_app to detect nullification', async () => { + const key = 6n; + const value = [268n, 862n, 268n ]; + await testContract.methods.store_in_pxe_store(key, value).simulate(); + expect(await testContract.methods.load_from_pxe_store(key).simulate()).toEqual(value); + }); +});