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
25 changes: 24 additions & 1 deletion yarn-project/end-to-end/src/e2e_note_getter.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,6 +42,22 @@ impl CardNote {
}
}

impl Serialize<FULL_CARD_NOTE_LEN> 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<CARD_NOTE_LEN> for CardNote {
fn serialize_content(self) -> [Field; CARD_NOTE_LEN] {
[self.points as Field, self.randomness, self.owner.to_field()]
Expand Down