diff --git a/yarn-project/end-to-end/src/e2e_note_getter.test.ts b/yarn-project/end-to-end/src/e2e_note_getter.test.ts index ed00016612ac..974c800a1248 100644 --- a/yarn-project/end-to-end/src/e2e_note_getter.test.ts +++ b/yarn-project/end-to-end/src/e2e_note_getter.test.ts @@ -1,4 +1,4 @@ -import { AztecAddress, Comparator, Fr, Wallet, toBigInt } from '@aztec/aztec.js'; +import { AztecAddress, Comparator, Fr, TxStatus, Wallet, toBigInt } from '@aztec/aztec.js'; import { DocsExampleContract, TestContract } from '@aztec/noir-contracts'; import { setup } from './fixtures/utils.js'; @@ -25,6 +25,29 @@ describe('e2e_note_getter', () => { afterAll(() => teardown()); + describe.only('Get note and push into contract', () => { + let contract: DocsExampleContract; + + beforeAll(async () => { + contract = await DocsExampleContract.deploy(wallet).send().deployed(); + // sets card value to 1 and leader to sender. + await contract.methods.initialize_private(Fr.random(), 1).send().wait(); + }, 25_000); + + it('Issues with passing note as argument', async () => { + const card = await contract.methods.get_legendary_card().view(); + console.log(card); + const a = contract.methods.match_card(card).request(); + console.log("Request: ", a); + + // eslint-disable-next-line camelcase + card.header.is_transient = new Fr(234); + + const receipt = await contract.methods.match_card(card).send().wait(); + expect(receipt.status).toEqual(TxStatus.MINED); + }); + }); + describe('comparators', () => { let contract: DocsExampleContract; diff --git a/yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr b/yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr index 7182013b426d..c0c820417965 100644 --- a/yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr +++ b/yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr @@ -33,6 +33,7 @@ contract DocsExample { card_note::{CardNote, CARD_NOTE_LEN}, leader::Leader, }; + use dep::aztec::oracle::debug_log::{debug_log_format, debug_log_array_with_prefix}; struct Storage { // Shows how to create a custom struct in PublicState @@ -208,6 +209,23 @@ contract DocsExample { storage.leader.read() } + #[aztec(private)] + fn match_card(new_card: CardNote) { + let card = storage.legendary_card.get_note(false); + let fields = card.serialize(); + + debug_log_array_with_prefix("Card: ", fields); + + assert(card.points == new_card.points, "Invalid points"); + assert(card.randomness == new_card.randomness, "Invalid randomness"); + assert(card.owner == new_card.owner, "Invalid owner"); + assert(card.header.contract_address == new_card.header.contract_address, "Invalid contract address"); + debug_log_format("CARD MATCHING: {0} != {1}", [card.header.nonce, new_card.header.nonce]); + assert(card.header.nonce == new_card.header.nonce, "Invalid nonce"); + assert(card.header.storage_slot == new_card.header.storage_slot, "Invalid storage slot"); + assert(card.header.is_transient == new_card.header.is_transient, "Invalid transient"); + } + unconstrained fn get_legendary_card() -> pub CardNote { storage.legendary_card.view_note() } diff --git a/yarn-project/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr b/yarn-project/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr index 8128f58e3cad..17580fe9e03a 100644 --- a/yarn-project/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr +++ b/yarn-project/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr @@ -13,12 +13,13 @@ use dep::aztec::{ context::PrivateContext, protocol_types::{ address::AztecAddress, - traits::Empty + traits::{Empty, Serialize} } }; // Shows how to create a custom note +global FULL_CARD_NOTE_LEN: Field = 7; global CARD_NOTE_LEN: Field = 3; // docs:start:state_vars-CardNote @@ -41,6 +42,22 @@ impl CardNote { } } +impl Serialize for CardNote { + fn serialize(self) -> [Field; FULL_CARD_NOTE_LEN] { + let fields = [ + self.points as Field, + self.randomness, + self.owner.to_field(), + self.header.contract_address.to_field(), + self.header.nonce, + self.header.storage_slot, + self.header.is_transient as Field, + ]; + + fields + } +} + impl NoteInterface for CardNote { fn serialize_content(self) -> [Field; CARD_NOTE_LEN] { [self.points as Field, self.randomness, self.owner.to_field()]