Skip to content
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

feat: TXE::store_note_in_cache --> TXE::add_note #8547

Merged
merged 1 commit into from
Sep 16, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ You can add [authwits](../writing_contracts/authwit.md) to the TXE. Here is an e

Sometimes we have to tell TXE about notes that are not generated by ourselves, but someone else. This allows us to check if we are able to decrypt them:

#include_code txe_test_store_note /noir-projects/noir-contracts/contracts/token_contract/src/test/utils.nr rust
#include_code txe_test_add_note /noir-projects/noir-contracts/contracts/token_contract/src/test/utils.nr rust

### Time traveling

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ impl TestEnvironment {
);
}

pub fn store_note_in_cache<Note, let N: u32, let M: u32>(
/// Manually adds a note to TXE. This needs to be called if you want to work with a note in your test with the note
/// not having an encrypted log emitted. TXE alternative to `PXE.addNote(...)`.
pub fn add_note<Note, let N: u32, let M: u32>(
_self: Self,
note: &mut Note,
storage_slot: Field,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ unconstrained fn transfer_to_private_to_a_different_account() {
let recipient_npk_m_hash = get_current_public_keys(&mut context, recipient).npk_m.hash();
let private_nfts_recipient_slot = derive_storage_slot_in_map(NFT::storage().private_nfts.slot, recipient);

env.store_note_in_cache(
env.add_note(
&mut NFTNote { token_id, npk_m_hash: recipient_npk_m_hash, randomness: note_randomness, header: NoteHeader::empty() },
private_nfts_recipient_slot,
nft_contract_address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn setup_mint_and_transfer_to_private(with_account_contracts: bool) -> (&mut
let owner_npk_m_hash = get_current_public_keys(&mut context, owner).npk_m.hash();
let private_nfts_owner_slot = derive_storage_slot_in_map(NFT::storage().private_nfts.slot, owner);

env.store_note_in_cache(
env.add_note(
&mut NFTNote {
token_id: minted_token_id,
npk_m_hash: owner_npk_m_hash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ unconstrained fn mint_private_success() {
// Time travel so we can read keys from the registry
env.advance_block_by(6);

// Store a note in the cache so we can redeem it
env.store_note_in_cache(
// We need to manually add the note to TXE because `TransparentNote` does not support automatic note log delivery.
env.add_note(
&mut TransparentNote::new(mint_amount, secret_hash),
Token::storage().pending_shields.slot,
token_contract_address
Expand Down Expand Up @@ -105,8 +105,8 @@ unconstrained fn mint_private_failure_double_spend() {
// Time travel so we can read keys from the registry
env.advance_block_by(6);

// Store a note in the cache so we can redeem it
env.store_note_in_cache(
// We need to manually add the note to TXE because `TransparentNote` does not support automatic note log delivery.
env.add_note(
&mut TransparentNote::new(mint_amount, secret_hash),
Token::storage().pending_shields.slot,
token_contract_address
Expand Down Expand Up @@ -164,8 +164,8 @@ unconstrained fn mint_private_failure_overflow_recipient() {
// Time travel so we can read keys from the registry
env.advance_block_by(6);

// Store a note in the cache so we can redeem it
env.store_note_in_cache(
// We need to manually add the note to TXE because `TransparentNote` does not support automatic note log delivery.
env.add_note(
&mut TransparentNote::new(mint_amount, secret_hash),
Token::storage().pending_shields.slot,
token_contract_address
Expand Down Expand Up @@ -205,12 +205,12 @@ unconstrained fn mint_private_failure_overflow_total_supply() {
env.advance_block_by(6);

// Store 2 notes in the cache so we can redeem it for owner and recipient
env.store_note_in_cache(
env.add_note(
&mut TransparentNote::new(mint_amount, secret_hash_owner),
Token::storage().pending_shields.slot,
token_contract_address
);
env.store_note_in_cache(
env.add_note(
&mut TransparentNote::new(mint_amount, secret_hash_recipient),
Token::storage().pending_shields.slot,
token_contract_address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ unconstrained fn setup_refund_success() {
//`mint_amount - funded_amount`. When completing the refund, we would've constructed a hash corresponding to a note
// worth `funded_amount - transaction_fee`. We "know" the transaction fee was 1 (it is hardcoded in
// `executePublicFunction` TXE oracle) but we need to notify TXE of the note (preimage).
env.store_note_in_cache(
env.add_note(
&mut TokenNote {
amount: U128::from_integer(funded_amount - 1),
npk_m_hash: user_npk_m_hash,
Expand All @@ -53,7 +53,7 @@ unconstrained fn setup_refund_success() {
user_balances_slot,
token_contract_address
);
env.store_note_in_cache(
env.add_note(
&mut TokenNote {
amount: U128::from_integer(1),
npk_m_hash: fee_payer_npk_m_hash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ unconstrained fn shielding_on_behalf_of_self() {
let shield_call_interface = Token::at(token_contract_address).shield(owner, shield_amount, secret_hash, 0);
env.call_public(shield_call_interface);

// Store a note in the cache so we can redeem it
env.store_note_in_cache(
// We need to manually add the note to TXE because `TransparentNote` does not support automatic note log delivery.
env.add_note(
&mut TransparentNote::new(shield_amount, secret_hash),
Token::storage().pending_shields.slot,
token_contract_address
Expand Down Expand Up @@ -47,8 +47,8 @@ unconstrained fn shielding_on_behalf_of_other() {

// Become owner again
env.impersonate(owner);
// Store a note in the cache so we can redeem it
env.store_note_in_cache(
// We need to manually add the note to TXE because `TransparentNote` does not support automatic note log delivery.
env.add_note(
&mut TransparentNote::new(shield_amount, secret_hash),
Token::storage().pending_shields.slot,
token_contract_address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ pub fn setup_and_mint(with_account_contracts: bool) -> (&mut TestEnvironment, Az
// Time travel so we can read keys from the registry
env.advance_block_by(6);

// docs:start:txe_test_store_note
// Store a note in the cache so we can redeem it
env.store_note_in_cache(
// docs:start:txe_test_add_note
// We need to manually add the note to TXE because `TransparentNote` does not support automatic note log delivery.
env.add_note(
&mut TransparentNote::new(mint_amount, secret_hash),
Token::storage().pending_shields.slot,
token_contract_address
);
// docs:end:txe_test_store_note
// docs:end:txe_test_add_note

// Redeem our shielded tokens
let redeem_shield_call_interface = Token::at(token_contract_address).redeem_shield(owner, mint_amount, secret);
Expand Down
Loading