Skip to content

Commit

Permalink
✅ Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikrk committed Feb 27, 2024
1 parent 938cc7f commit c8bfc37
Show file tree
Hide file tree
Showing 7 changed files with 1,932 additions and 2,424 deletions.
4,280 changes: 1,870 additions & 2,410 deletions crates/client/tests/test_data/expanded_source_codes/expanded_fuzz_example3.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,4 @@ impl<'info> WithdrawUnlockedSnapshot<'info> {
})
}
}
pub type WithdrawDummySnapshot<'info> = WithdrawUnlockedSnapshot<'info>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod fuzz_example3_fuzz_instructions {
pub enum FuzzInstruction {
InitVesting(InitVesting),
WithdrawUnlocked(WithdrawUnlocked),
WithdrawDummy(WithdrawDummy),
}
#[derive(Arbitrary, Debug)]
pub struct InitVesting {
Expand Down Expand Up @@ -48,6 +49,24 @@ pub mod fuzz_example3_fuzz_instructions {
}
#[derive(Arbitrary, Debug)]
pub struct WithdrawUnlockedData {}
#[derive(Arbitrary, Debug)]
pub struct WithdrawDummy {
pub accounts: WithdrawDummyAccounts,
pub data: WithdrawDummyData,
}
#[derive(Arbitrary, Debug)]
pub struct WithdrawDummyAccounts {
pub recipient: AccountId,
pub recipient_token_account: AccountId,
pub escrow: AccountId,
pub escrow_token_account: AccountId,
pub escrow_pda_authority: AccountId,
pub mint: AccountId,
pub token_program: AccountId,
pub system_program: AccountId,
}
#[derive(Arbitrary, Debug)]
pub struct WithdrawDummyData {}
impl<'info> IxOps<'info> for InitVesting {
type IxData = fuzz_example3::instruction::InitVesting;
type IxAccounts = FuzzAccounts;
Expand Down Expand Up @@ -104,7 +123,39 @@ pub mod fuzz_example3_fuzz_instructions {
fuzz_accounts: &mut FuzzAccounts,
) -> Result<(Vec<Keypair>, Vec<AccountMeta>), FuzzingError> {
let signers = vec![todo!()];
let acc_meta = fuzz_example3::accounts::WithdrawUnlocked {
let acc_meta = fuzz_example3::accounts::Withdraw {
recipient: todo!(),
recipient_token_account: todo!(),
escrow: todo!(),
escrow_token_account: todo!(),
escrow_pda_authority: todo!(),
mint: todo!(),
token_program: todo!(),
system_program: todo!(),
}
.to_account_metas(None);
Ok((signers, acc_meta))
}
}
impl<'info> IxOps<'info> for WithdrawDummy {
type IxData = fuzz_example3::instruction::WithdrawDummy;
type IxAccounts = FuzzAccounts;
type IxSnapshot = WithdrawDummySnapshot<'info>;
fn get_data(
&self,
_client: &mut impl FuzzClient,
_fuzz_accounts: &mut FuzzAccounts,
) -> Result<Self::IxData, FuzzingError> {
let data = fuzz_example3::instruction::WithdrawDummy {};
Ok(data)
}
fn get_accounts(
&self,
client: &mut impl FuzzClient,
fuzz_accounts: &mut FuzzAccounts,
) -> Result<(Vec<Keypair>, Vec<AccountMeta>), FuzzingError> {
let signers = vec![todo!()];
let acc_meta = fuzz_example3::accounts::Withdraw {
recipient: todo!(),
recipient_token_account: todo!(),
escrow: todo!(),
Expand Down Expand Up @@ -133,9 +184,4 @@ pub mod fuzz_example3_fuzz_instructions {
system_program: AccountsStorage<todo!()>,
token_program: AccountsStorage<todo!()>,
}
impl FuzzAccounts {
pub fn new() -> Self {
Default::default()
}
}
}
3 changes: 0 additions & 3 deletions crates/client/tests/test_program/fuzz_example3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,3 @@ default = []
[dependencies]
anchor-lang = "0.29.0"
anchor-spl = "0.29.0"
# ahash is unused but got an error during `anchor build`
# fix: https://solana.stackexchange.com/questions/8796/anchor-build-failed-the-error-is-use-of-unstable-library-feature-build-hasher-s
ahash = "=0.8.6"
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn _init_vesting(
escrow.end_time = end_at;
escrow.interval = interval;
escrow.recipient = recipient;
escrow.bump = *ctx.bumps.get("escrow").unwrap();
escrow.bump = ctx.bumps.escrow;

let (escrow_pda_authority, _) =
Pubkey::find_program_address(&[b"ESCROW_PDA_AUTHORITY"], ctx.program_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anchor_spl::token::{transfer, Mint, Token, TokenAccount, Transfer};

use crate::{state::Escrow, VestingError};

pub fn _withdraw_unlocked(ctx: Context<WithdrawUnlocked>) -> Result<()> {
pub fn _withdraw_unlocked(ctx: Context<Withdraw>) -> Result<()> {
let escrow = &mut ctx.accounts.escrow;

let current_time = Clock::get()?.unix_timestamp as u64;
Expand All @@ -13,7 +13,7 @@ pub fn _withdraw_unlocked(ctx: Context<WithdrawUnlocked>) -> Result<()> {

let seeds = &[
b"ESCROW_PDA_AUTHORITY".as_ref(),
&[*ctx.bumps.get("escrow_pda_authority").unwrap()],
&[ctx.bumps.escrow_pda_authority],
];

transfer(
Expand All @@ -35,7 +35,7 @@ pub fn _withdraw_unlocked(ctx: Context<WithdrawUnlocked>) -> Result<()> {
}

#[derive(Accounts)]
pub struct WithdrawUnlocked<'info> {
pub struct Withdraw<'info> {
#[account(mut)]
pub recipient: Signer<'info>,

Expand Down
6 changes: 5 additions & 1 deletion crates/client/tests/test_program/fuzz_example3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ pub mod fuzz_example3 {
_init_vesting(ctx, recipient, amount, start_at, end_at, interval)
}

pub fn withdraw_unlocked(ctx: Context<WithdrawUnlocked>) -> Result<()> {
pub fn withdraw_unlocked(ctx: Context<Withdraw>) -> Result<()> {
_withdraw_unlocked(ctx)
}

pub fn withdraw_dummy(ctx: Context<Withdraw>) -> Result<()> {
Ok(())
}
}

0 comments on commit c8bfc37

Please sign in to comment.