Skip to content

Commit

Permalink
test: minting only private or public balance in Token TXE tests (#9491)
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan authored Oct 28, 2024
1 parent 26416b6 commit b8c015b
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use dep::aztec::oracle::random::random;
#[test]
unconstrained fn burn_public_success() {
let (env, token_contract_address, owner, recipient, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ false);
utils::setup_and_mint_public(/* with_account_contracts */ false);
let burn_amount = mint_amount / 10;

// Burn less than balance
Expand All @@ -17,7 +17,7 @@ unconstrained fn burn_public_success() {
#[test]
unconstrained fn burn_public_on_behalf_of_other() {
let (env, token_contract_address, owner, recipient, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ true);
utils::setup_and_mint_public(/* with_account_contracts */ true);
let burn_amount = mint_amount / 10;

// Burn on behalf of other
Expand All @@ -38,7 +38,7 @@ unconstrained fn burn_public_on_behalf_of_other() {
#[test(should_fail_with = "attempt to subtract with underflow")]
unconstrained fn burn_public_failure_more_than_balance() {
let (env, token_contract_address, owner, _, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ false);
utils::setup_and_mint_public(/* with_account_contracts */ false);

// Burn more than balance
let burn_amount = mint_amount * 10;
Expand All @@ -49,7 +49,7 @@ unconstrained fn burn_public_failure_more_than_balance() {
#[test(should_fail_with = "invalid nonce")]
unconstrained fn burn_public_failure_on_behalf_of_self_non_zero_nonce() {
let (env, token_contract_address, owner, _, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ false);
utils::setup_and_mint_public(/* with_account_contracts */ false);

// Burn on behalf of self with non-zero nonce
let burn_amount = mint_amount / 10;
Expand All @@ -62,7 +62,7 @@ unconstrained fn burn_public_failure_on_behalf_of_self_non_zero_nonce() {
#[test(should_fail_with = "unauthorized")]
unconstrained fn burn_public_failure_on_behalf_of_other_without_approval() {
let (env, token_contract_address, owner, recipient, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ true);
utils::setup_and_mint_public(/* with_account_contracts */ true);

// Burn on behalf of other without approval
let burn_amount = mint_amount / 10;
Expand All @@ -76,7 +76,7 @@ unconstrained fn burn_public_failure_on_behalf_of_other_without_approval() {
#[test(should_fail_with = "unauthorized")]
unconstrained fn burn_public_failure_on_behalf_of_other_wrong_caller() {
let (env, token_contract_address, owner, recipient, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ true);
utils::setup_and_mint_public(/* with_account_contracts */ true);

// Burn on behalf of other, wrong designated caller
let burn_amount = mint_amount / 10;
Expand All @@ -91,7 +91,7 @@ unconstrained fn burn_public_failure_on_behalf_of_other_wrong_caller() {
#[test]
unconstrained fn burn_private_on_behalf_of_self() {
let (env, token_contract_address, owner, _, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ false);
utils::setup_and_mint_private(/* with_account_contracts */ false);
let burn_amount = mint_amount / 10;

// Burn less than balance
Expand All @@ -102,7 +102,7 @@ unconstrained fn burn_private_on_behalf_of_self() {
#[test]
unconstrained fn burn_private_on_behalf_of_other() {
let (env, token_contract_address, owner, recipient, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ true);
utils::setup_and_mint_private(/* with_account_contracts */ true);
let burn_amount = mint_amount / 10;

// Burn on behalf of other
Expand All @@ -122,7 +122,7 @@ unconstrained fn burn_private_on_behalf_of_other() {
#[test(should_fail_with = "Balance too low")]
unconstrained fn burn_private_failure_more_than_balance() {
let (env, token_contract_address, owner, _, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ false);
utils::setup_and_mint_public(/* with_account_contracts */ false);

// Burn more than balance
let burn_amount = mint_amount * 10;
Expand All @@ -132,7 +132,7 @@ unconstrained fn burn_private_failure_more_than_balance() {
#[test(should_fail_with = "invalid nonce")]
unconstrained fn burn_private_failure_on_behalf_of_self_non_zero_nonce() {
let (env, token_contract_address, owner, _, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ false);
utils::setup_and_mint_public(/* with_account_contracts */ false);

// Burn more than balance
let burn_amount = mint_amount / 10;
Expand All @@ -142,7 +142,7 @@ unconstrained fn burn_private_failure_on_behalf_of_self_non_zero_nonce() {
#[test(should_fail_with = "Balance too low")]
unconstrained fn burn_private_failure_on_behalf_of_other_more_than_balance() {
let (env, token_contract_address, owner, recipient, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ true);
utils::setup_and_mint_public(/* with_account_contracts */ true);

// Burn more than balance
let burn_amount = mint_amount * 10;
Expand All @@ -161,7 +161,7 @@ unconstrained fn burn_private_failure_on_behalf_of_other_more_than_balance() {
#[test(should_fail_with = "Authorization not found for message hash")]
unconstrained fn burn_private_failure_on_behalf_of_other_without_approval() {
let (env, token_contract_address, owner, recipient, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ true);
utils::setup_and_mint_public(/* with_account_contracts */ true);

// Burn more than balance
let burn_amount = mint_amount / 10;
Expand All @@ -175,7 +175,7 @@ unconstrained fn burn_private_failure_on_behalf_of_other_without_approval() {
#[test(should_fail_with = "Authorization not found for message hash")]
unconstrained fn burn_private_failure_on_behalf_of_other_wrong_designated_caller() {
let (env, token_contract_address, owner, recipient, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ true);
utils::setup_and_mint_public(/* with_account_contracts */ true);

// Burn more than balance
let burn_amount = mint_amount / 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use std::test::OracleMock;

#[test]
unconstrained fn setup_refund_success() {
let (env, token_contract_address, owner, recipient, mint_amount) = utils::setup_and_mint(true);
let (env, token_contract_address, owner, recipient, mint_amount) =
utils::setup_and_mint_private(true);

// Renaming owner and recipient to match naming in Token
let user = owner;
Expand Down Expand Up @@ -78,7 +79,8 @@ unconstrained fn setup_refund_success() {
//#[test(should_fail_with="funded amount not enough to cover tx fee")]
#[test(should_fail_with = "Balance too low")]
unconstrained fn setup_refund_insufficient_funded_amount() {
let (env, token_contract_address, owner, recipient, _mint_amount) = utils::setup_and_mint(true);
let (env, token_contract_address, owner, recipient, _mint_amount) =
utils::setup_and_mint_private(true);

// Renaming owner and recipient to match naming in Token
let user = owner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use dep::aztec::{hash::compute_secret_hash, oracle::random::random};
unconstrained fn shielding_on_behalf_of_self() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, token_contract_address, owner, _, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ false);
utils::setup_and_mint_public(/* with_account_contracts */ false);
let secret = random();
let secret_hash = compute_secret_hash(secret);
// Shield tokens
Expand All @@ -30,13 +30,13 @@ unconstrained fn shielding_on_behalf_of_self() {

// Check balances
utils::check_public_balance(token_contract_address, owner, mint_amount - shield_amount);
utils::check_private_balance(token_contract_address, owner, mint_amount + shield_amount);
utils::check_private_balance(token_contract_address, owner, shield_amount);
}

#[test]
unconstrained fn shielding_on_behalf_of_other() {
let (env, token_contract_address, owner, recipient, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ true);
utils::setup_and_mint_public(/* with_account_contracts */ true);
let secret = random();
let secret_hash = compute_secret_hash(secret);

Expand Down Expand Up @@ -70,14 +70,14 @@ unconstrained fn shielding_on_behalf_of_other() {

// Check balances
utils::check_public_balance(token_contract_address, owner, mint_amount - shield_amount);
utils::check_private_balance(token_contract_address, owner, mint_amount + shield_amount);
utils::check_private_balance(token_contract_address, owner, shield_amount);
}

#[test]
unconstrained fn shielding_failure_on_behalf_of_self_more_than_balance() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, token_contract_address, owner, _, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ true);
utils::setup_and_mint_public(/* with_account_contracts */ true);
let secret = random();
let secret_hash = compute_secret_hash(secret);
// Shield tokens
Expand All @@ -88,14 +88,14 @@ unconstrained fn shielding_failure_on_behalf_of_self_more_than_balance() {

// Check balances
utils::check_public_balance(token_contract_address, owner, mint_amount);
utils::check_private_balance(token_contract_address, owner, mint_amount);
utils::check_private_balance(token_contract_address, owner, 0);
}

#[test]
unconstrained fn shielding_failure_on_behalf_of_self_invalid_nonce() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, token_contract_address, owner, _, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ true);
utils::setup_and_mint_public(/* with_account_contracts */ true);
let secret = random();
let secret_hash = compute_secret_hash(secret);
// Shield tokens
Expand All @@ -106,14 +106,14 @@ unconstrained fn shielding_failure_on_behalf_of_self_invalid_nonce() {

// Check balances
utils::check_public_balance(token_contract_address, owner, mint_amount);
utils::check_private_balance(token_contract_address, owner, mint_amount);
utils::check_private_balance(token_contract_address, owner, 0);
}

#[test]
unconstrained fn shielding_failure_on_behalf_of_other_more_than_balance() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, token_contract_address, owner, recipient, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ true);
utils::setup_and_mint_public(/* with_account_contracts */ true);
let secret = random();
let secret_hash = compute_secret_hash(secret);
// Shield tokens on behalf of owner
Expand All @@ -132,14 +132,14 @@ unconstrained fn shielding_failure_on_behalf_of_other_more_than_balance() {

// Check balances
utils::check_public_balance(token_contract_address, owner, mint_amount);
utils::check_private_balance(token_contract_address, owner, mint_amount);
utils::check_private_balance(token_contract_address, owner, 0);
}

#[test]
unconstrained fn shielding_failure_on_behalf_of_other_wrong_caller() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, token_contract_address, owner, recipient, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ true);
utils::setup_and_mint_public(/* with_account_contracts */ true);
let secret = random();
let secret_hash = compute_secret_hash(secret);
// Shield tokens on behalf of owner
Expand All @@ -154,14 +154,14 @@ unconstrained fn shielding_failure_on_behalf_of_other_wrong_caller() {

// Check balances
utils::check_public_balance(token_contract_address, owner, mint_amount);
utils::check_private_balance(token_contract_address, owner, mint_amount);
utils::check_private_balance(token_contract_address, owner, 0);
}

#[test]
unconstrained fn shielding_failure_on_behalf_of_other_without_approval() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, token_contract_address, owner, recipient, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ true);
utils::setup_and_mint_public(/* with_account_contracts */ true);
let secret = random();
let secret_hash = compute_secret_hash(secret);
// Shield tokens on behalf of owner
Expand All @@ -175,5 +175,5 @@ unconstrained fn shielding_failure_on_behalf_of_other_without_approval() {

// Check balances
utils::check_public_balance(token_contract_address, owner, mint_amount);
utils::check_private_balance(token_contract_address, owner, mint_amount);
utils::check_private_balance(token_contract_address, owner, 0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use dep::aztec::test::helpers::cheatcodes;
unconstrained fn transfer_private() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, token_contract_address, owner, recipient, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ false);
utils::setup_and_mint_private(/* with_account_contracts */ false);

// docs:start:txe_test_transfer_private
// Transfer tokens
Expand All @@ -23,7 +23,7 @@ unconstrained fn transfer_private() {
unconstrained fn transfer_private_to_self() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, token_contract_address, owner, _, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ false);
utils::setup_and_mint_private(/* with_account_contracts */ false);
// Transfer tokens
let transfer_amount = 1000;
Token::at(token_contract_address).transfer(owner, transfer_amount).call(&mut env.private());
Expand All @@ -36,7 +36,7 @@ unconstrained fn transfer_private_to_self() {
unconstrained fn transfer_private_to_non_deployed_account() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, token_contract_address, owner, _, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ false);
utils::setup_and_mint_private(/* with_account_contracts */ false);
let not_deployed = cheatcodes::create_account();
// Transfer tokens
let transfer_amount = 1000;
Expand All @@ -57,7 +57,7 @@ unconstrained fn transfer_private_to_non_deployed_account() {
unconstrained fn transfer_private_on_behalf_of_other() {
// Setup with account contracts. Slower since we actually deploy them, but needed for authwits.
let (env, token_contract_address, owner, recipient, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ true);
utils::setup_and_mint_private(/* with_account_contracts */ true);
// Add authwit
// docs:start:private_authwit
let transfer_amount = 1000;
Expand All @@ -82,7 +82,7 @@ unconstrained fn transfer_private_on_behalf_of_other() {
unconstrained fn transfer_private_failure_more_than_balance() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, token_contract_address, _, recipient, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ false);
utils::setup_and_mint_private(/* with_account_contracts */ false);
// Transfer tokens
let transfer_amount = mint_amount + 1;
Token::at(token_contract_address).transfer(recipient, transfer_amount).call(&mut env.private());
Expand All @@ -93,7 +93,7 @@ unconstrained fn transfer_private_failure_more_than_balance() {
unconstrained fn transfer_private_failure_on_behalf_of_self_non_zero_nonce() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, token_contract_address, owner, recipient, _) =
utils::setup_and_mint(/* with_account_contracts */ false);
utils::setup_and_mint_private(/* with_account_contracts */ false);
// Add authwit
let transfer_amount = 1000;
let transfer_private_from_call_interface =
Expand All @@ -112,7 +112,7 @@ unconstrained fn transfer_private_failure_on_behalf_of_self_non_zero_nonce() {
unconstrained fn transfer_private_failure_on_behalf_of_more_than_balance() {
// Setup with account contracts. Slower since we actually deploy them, but needed for authwits.
let (env, token_contract_address, owner, recipient, mint_amount) =
utils::setup_and_mint(/* with_account_contracts */ true);
utils::setup_and_mint_private(/* with_account_contracts */ true);
// Add authwit
let transfer_amount = mint_amount + 1;
let transfer_private_from_call_interface =
Expand All @@ -132,7 +132,7 @@ unconstrained fn transfer_private_failure_on_behalf_of_more_than_balance() {
unconstrained fn transfer_private_failure_on_behalf_of_other_without_approval() {
// Setup with account contracts. Slower since we actually deploy them, but needed for authwits.
let (env, token_contract_address, owner, recipient, _) =
utils::setup_and_mint(/* with_account_contracts */ true);
utils::setup_and_mint_private(/* with_account_contracts */ true);
// Add authwit
let transfer_amount = 1000;
let transfer_private_from_call_interface =
Expand All @@ -147,7 +147,7 @@ unconstrained fn transfer_private_failure_on_behalf_of_other_without_approval()
unconstrained fn transfer_private_failure_on_behalf_of_other_wrong_caller() {
// Setup with account contracts. Slower since we actually deploy them, but needed for authwits.
let (env, token_contract_address, owner, recipient, _) =
utils::setup_and_mint(/* with_account_contracts */ true);
utils::setup_and_mint_private(/* with_account_contracts */ true);
// Add authwit
let transfer_amount = 1000;
let transfer_private_from_call_interface =
Expand Down
Loading

0 comments on commit b8c015b

Please sign in to comment.