Skip to content

Commit

Permalink
using partial flow in test private mint
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 28, 2024
1 parent b5dfd46 commit 3d9db71
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,14 +480,14 @@ contract Token {
fn transfer_to_private(to: AztecAddress, amount: Field) {
let from = context.msg_sender();

let nft = Token::at(context.this_address());
let token = Token::at(context.this_address());

// We prepare the transfer.
let hiding_point_slot = _prepare_transfer_to_private(to, &mut context, storage);

// At last we finalize the transfer. Usafe of the `unsafe` method here is safe because we set the `from`
// function argument to a message sender, guaranteeing that he can transfer only his own NFTs.
nft._finalize_transfer_to_private_unsafe(from, amount, hiding_point_slot).enqueue(
// function argument to a message sender, guaranteeing that he can transfer only his own tokens.
token._finalize_transfer_to_private_unsafe(from, amount, hiding_point_slot).enqueue(
&mut context,
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use dep::aztec::{
hash::compute_secret_hash,
oracle::{
execution::{get_block_number, get_contract_address},
random::random,
Expand All @@ -11,6 +10,8 @@ use dep::aztec::{
};

use crate::{Token, types::transparent_note::TransparentNote};
use dep::uint_note::uint_note::UintNote;
use aztec::keys::getters::get_public_keys;

pub unconstrained fn setup(
with_account_contracts: bool,
Expand Down Expand Up @@ -59,27 +60,28 @@ pub unconstrained fn setup_and_mint_public(
pub unconstrained fn setup_and_mint_private(
with_account_contracts: bool,
) -> (&mut TestEnvironment, AztecAddress, AztecAddress, AztecAddress, Field) {
// Setup
let (env, token_contract_address, owner, recipient) = setup(with_account_contracts);
// Setup the tokens and mint public balance
let (env, token_contract_address, owner, recipient) =
setup_and_mint_public(with_account_contracts);
let mint_amount = 10000;
// Mint some tokens
let secret = random();
let secret_hash = compute_secret_hash(secret);
Token::at(token_contract_address).mint_private(mint_amount, secret_hash).call(&mut env.public());
// Transfer the public balance to private
Token::at(token_contract_address).transfer_to_private(owner, mint_amount).call(
&mut env.private(),
);

// docs:start:txe_test_add_note
// We need to manually add the note to TXE because `TransparentNote` does not support automatic note log delivery.
// TODO(#8771): We need to manually add the note because in the partial notes flow `notify_created_note_oracle`
// is not called and we don't have a `NoteProcessor` in TXE.
let owner_npk_m_hash = get_public_keys(owner).npk_m.hash();
let balances_owner_slot =
derive_storage_slot_in_map(Token::storage_layout().balances.slot, owner);

env.add_note(
&mut TransparentNote::new(mint_amount, secret_hash),
Token::storage_layout().pending_shields.slot,
&mut UintNote::new(U128::from_integer(mint_amount), owner_npk_m_hash),
balances_owner_slot,
token_contract_address,
);
// docs:end:txe_test_add_note
// Redeem our shielded tokens
Token::at(token_contract_address).redeem_shield(owner, mint_amount, secret).call(
&mut env.private(),
);

(env, token_contract_address, owner, recipient, mint_amount)
}

Expand Down

0 comments on commit 3d9db71

Please sign in to comment.