diff --git a/examples/fuzz_example3/programs/fuzz_example3/src/instructions/withdraw.rs b/examples/fuzz_example3/programs/fuzz_example3/src/instructions/withdraw.rs index 8a65e592..af9f41f0 100644 --- a/examples/fuzz_example3/programs/fuzz_example3/src/instructions/withdraw.rs +++ b/examples/fuzz_example3/programs/fuzz_example3/src/instructions/withdraw.rs @@ -15,10 +15,6 @@ pub fn _withdraw_unlocked(ctx: Context) -> Result<()> { b"ESCROW_PDA_AUTHORITY".as_ref(), &[*ctx.bumps.get("escrow_pda_authority").unwrap()], ]; - let token_acc_amount = ctx.accounts.escrow_token_account.amount; - msg!("withdrawal {}", escrow.withdrawal); - msg!("unlocked_amount {}", unlocked_amount); - msg!("token_acc_amount {}", token_acc_amount); transfer( CpiContext::new( diff --git a/examples/fuzz_example3/programs/fuzz_example3/src/state.rs b/examples/fuzz_example3/programs/fuzz_example3/src/state.rs index c84cc05b..35225c4c 100644 --- a/examples/fuzz_example3/programs/fuzz_example3/src/state.rs +++ b/examples/fuzz_example3/programs/fuzz_example3/src/state.rs @@ -20,21 +20,16 @@ impl Escrow { }; let duration = self.end_time.checked_sub(self.start_time)?; - msg!("duration {}", duration); - msg!("amount {}", self.amount); - msg!("interval {}", self.interval); let interval_amount = self .amount .checked_mul(self.interval)? .checked_div(duration)?; - msg!("interval_amount {}", interval_amount); let nr_intervals = time .checked_sub(self.start_time)? .checked_div(self.interval)? .checked_add(1)?; - msg!("nr_intervals {}", nr_intervals); nr_intervals .checked_mul(interval_amount)? diff --git a/examples/fuzz_example3/trdelnik-tests/src/accounts_snapshots.rs b/examples/fuzz_example3/trdelnik-tests/src/accounts_snapshots.rs index 1d506920..3d649a35 100644 --- a/examples/fuzz_example3/trdelnik-tests/src/accounts_snapshots.rs +++ b/examples/fuzz_example3/trdelnik-tests/src/accounts_snapshots.rs @@ -31,14 +31,12 @@ impl<'info> InitVestingSnapshot<'info> { let accounts = get_account_infos_option(accounts, metas) .map_err(|_| FuzzingError::CannotGetAccounts)?; let mut accounts_iter = accounts.into_iter(); - // eprintln!("deserializign sender"); let sender: Option> = accounts_iter .next() .ok_or(FuzzingError::NotEnoughAccounts)? .map(|acc| anchor_lang::accounts::signer::Signer::try_from(&acc)) .transpose() .map_err(|_| FuzzingError::CannotDeserializeAccount)?; - // eprintln!("deserializign sender ata"); let sender_token_account: Option> = accounts_iter .next() @@ -46,14 +44,12 @@ impl<'info> InitVestingSnapshot<'info> { .map(|acc| anchor_lang::accounts::account::Account::try_from(&acc)) .transpose() .map_err(|_| FuzzingError::CannotDeserializeAccount)?; - // eprintln!("deserializign escrow"); let escrow: Option> = accounts_iter .next() .ok_or(FuzzingError::NotEnoughAccounts)? .map(|acc| anchor_lang::accounts::account::Account::try_from(&acc)) .transpose() .map_err(|_| FuzzingError::CannotDeserializeAccount)?; - // eprintln!("deserializign escrow ata"); let escrow_token_account: Option> = accounts_iter .next() @@ -61,21 +57,18 @@ impl<'info> InitVestingSnapshot<'info> { .map(|acc| anchor_lang::accounts::account::Account::try_from(&acc)) .transpose() .map_err(|_| FuzzingError::CannotDeserializeAccount)?; - // eprintln!("deserializign mint"); let mint: Option> = accounts_iter .next() .ok_or(FuzzingError::NotEnoughAccounts)? .map(|acc| anchor_lang::accounts::account::Account::try_from(&acc)) .transpose() .map_err(|_| FuzzingError::CannotDeserializeAccount)?; - // eprintln!("deserializign token program"); let token_program: Option> = accounts_iter .next() .ok_or(FuzzingError::NotEnoughAccounts)? .map(|acc| anchor_lang::accounts::program::Program::try_from(&acc)) .transpose() .map_err(|_| FuzzingError::CannotDeserializeAccount)?; - // eprintln!("deserializign system program"); let system_program: Option> = accounts_iter .next() .ok_or(FuzzingError::NotEnoughAccounts)? diff --git a/examples/fuzz_example3/trdelnik-tests/src/fuzz_instructions.rs b/examples/fuzz_example3/trdelnik-tests/src/fuzz_instructions.rs index bd507220..b893beb2 100644 --- a/examples/fuzz_example3/trdelnik-tests/src/fuzz_instructions.rs +++ b/examples/fuzz_example3/trdelnik-tests/src/fuzz_instructions.rs @@ -24,8 +24,6 @@ pub mod fuzz_example3_fuzz_instructions { #[derive(Arbitrary, Clone)] pub struct InitVestingData { pub recipient: AccountId, - // the range is selected randomly - #[arbitrary(with = |u: &mut arbitrary::Unstructured| u.int_in_range(13581..=580743))] pub amount: u64, // we want start_at smaller than end_at // and for testing purposes we can run tests with times from the past @@ -250,47 +248,33 @@ pub mod fuzz_example3_fuzz_instructions { ) -> Result<(), &'static str> { if let Some(escrow) = pre_ix.escrow { let recipient = pre_ix.recipient.unwrap(); - if let Some(recepient_token_account_pre) = pre_ix.recipient_token_account { - if let Some(recepient_token_account_post) = post_ix.recipient_token_account { + if let Some(recipient_token_account_pre) = pre_ix.recipient_token_account { + if let Some(recipient_token_account_post) = post_ix.recipient_token_account { if escrow.recipient == *recipient.key { - if recepient_token_account_pre.amount - == recepient_token_account_post.amount + if recipient_token_account_pre.amount + == recipient_token_account_post.amount { // INFO Recipient was not able to withdraw return Err("Recipient was not able to withdraw any funds"); - } else if recepient_token_account_pre.amount + escrow.amount - != recepient_token_account_post.amount + } else if recipient_token_account_pre.amount + escrow.amount + != recipient_token_account_post.amount { - if recepient_token_account_pre.amount + escrow.amount - > recepient_token_account_post.amount + if recipient_token_account_pre.amount + escrow.amount + > recipient_token_account_post.amount { // INFO The recipient was able to withdraw, // but not as much as was initially intended. - eprintln!( - "Amount Mismatch (Recipient withdrew LESS) by: {}", - (recepient_token_account_pre.amount + escrow.amount) - - recepient_token_account_post.amount - ); + return Err("Recipient withdrew LESS"); } else { // INFO The recipient was able to withdraw, // but more as was initially intended. // This option is possible because the program uses one token accout with corresponding mint // across multiple Escrow Transactions, this means that we can actually withdraw more - // if prior to Withdraw call, was sufficient amount transfered to the escrow token account. + // if prior to Withdraw call, was sufficient amount transferred to the escrow token account. // (e.g. due to prior Initialization of different Escrow Transactions) - eprintln!( - "Amount Mismatch (Recipient withdrew MORE) by: {}", - recepient_token_account_post.amount - - (recepient_token_account_pre.amount + escrow.amount) - ); + // For testing purposes inside debug use eprintln!() + return Err("Recipient withdrew MORE"); } - eprintln!("Before: {}", recepient_token_account_pre.amount); - eprintln!("After: {}", recepient_token_account_post.amount); - eprintln!( - "Expected: {}", - recepient_token_account_pre.amount + escrow.amount - ); - return Err("Transfered amount mismatch"); } } }