Skip to content
Merged
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
67 changes: 44 additions & 23 deletions src/dripper/src/tests/token_helper.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@
use dep::token::Token;

use aztec::{
note::{constants::MAX_NOTES_PER_PAGE, note_getter::view_notes},
note::{
constants::MAX_NOTES_PER_PAGE, note_getter::view_notes,
note_viewer_options::NoteViewerOptions // @dev - aztec v2.0.3
},
oracle::{
execution::{get_block_number, get_contract_address},
random::random,
storage::storage_read,
},
prelude::{AztecAddress, NoteViewerOptions},
protocol_types::storage::map::derive_storage_slot_in_map,
//prelude::{AztecAddress, NoteViewerOptions},
protocol_types::{
address::AztecAddress, // @dev - aztec v2.0.3
storage::map::derive_storage_slot_in_map
},
test::helpers::{test_environment::TestEnvironment},
};
use aztec::test::helpers::authwit as thwit_cheatcodes;

//use aztec::authwit as authwit_cheatcodes; // @dev - aztec v2.0.3
use aztec::test::helpers::authwit as authwit_cheatcodes; // @dev - Both aztec v1.2.1 and v2.0.3

use std::ops::WrappingSub;
use std::test::OracleMock;
use uint_note::uint_note::UintNote;
Expand All @@ -26,12 +35,12 @@ pub unconstrained fn setup_with_initial_supply(
// Setup env, generate keys
let mut env = TestEnvironment::new();
let (owner, recipient) = if with_account_contracts {
let owner = env.create_contract_account(1);
let recipient = env.create_contract_account(2);
let owner = env.create_contract_account();
let recipient = env.create_contract_account();
(owner, recipient)
} else {
let owner = env.create_light_account(1);
let recipient = env.create_light_account(2);
let owner = env.create_light_account();
let recipient = env.create_light_account();
(owner, recipient)
};

Expand All @@ -47,14 +56,14 @@ pub unconstrained fn setup_with_minter(
// Setup env, generate keys
let mut env = TestEnvironment::new();
let (owner, recipient, minter) = if with_account_contracts {
let owner = env.create_contract_account(1);
let recipient = env.create_contract_account(2);
let minter = env.create_contract_account(3);
let owner = env.create_contract_account();
let recipient = env.create_contract_account();
let minter = env.create_contract_account();
(owner, recipient, minter)
} else {
let owner = env.create_light_account(1);
let recipient = env.create_light_account(2);
let minter = env.create_light_account(3);
let owner = env.create_light_account();
let recipient = env.create_light_account();
let minter = env.create_light_account();
(owner, recipient, minter)
};

Expand All @@ -69,12 +78,12 @@ pub unconstrained fn setup_with_asset(
// Setup env, generate keys
let mut env = TestEnvironment::new();
let (owner, recipient) = if with_account_contracts {
let owner = env.create_contract_account(1);
let recipient = env.create_contract_account(2)au;
let owner = env.create_contract_account();
let recipient = env.create_contract_account()au;
(owner, recipient)
} else {
let owner = env.create_light_account(1);
let recipient = env.create_light_account(2);
let owner = env.create_light_account();
let recipient = env.create_light_account();
(owner, recipient)
};

Expand Down Expand Up @@ -322,11 +331,18 @@ pub unconstrained fn add_token_note(
let balances_owner_slot =
derive_storage_slot_in_map(Token::storage_layout().private_balances.slot, owner);

env.add_note(
UintNote { value: amount, owner: owner, randomness: note_randomness },
balances_owner_slot,
token_contract_address,
let make_tx_hybrid = false;
let contract = Token::at(token_contract_address);

env.call_private(
owner,
contract.call_create_note(amount, owner, balances_owner_slot, make_tx_hybrid),
);
// env.add_note(
// UintNote { value: amount, owner: owner, randomness: note_randomness },
// balances_owner_slot,
// token_contract_address,
// );
}

pub unconstrained fn get_private_balance_notes(
Expand Down Expand Up @@ -367,6 +383,7 @@ pub unconstrained fn authorize_transfer_private_to_public(
) {
let transfer_private_to_public_call_interface =
Token::at(token).transfer_private_to_public(from, caller, amount, nonce);

authwit_cheatcodes::add_private_authwit_from_call_interface(
from,
caller,
Expand All @@ -382,12 +399,16 @@ pub unconstrained fn authorize_transfer_public_to_public(
amount: u128,
nonce: Field,
) {
let mut env = TestEnvironment::new();

let transfer_public_to_public_call_interface =
Token::at(token).transfer_public_to_public(from, caller, amount, nonce);

authwit_cheatcodes::add_public_authwit_from_call_interface(
env,
from,
caller,
transfer_public_to_public_call_interface,
transfer_public_to_public_call_interface
);
}

Expand Down
Loading