Skip to content

Commit

Permalink
Attempt fix fuzz
Browse files Browse the repository at this point in the history
  • Loading branch information
jgur-psyops committed Aug 28, 2024
1 parent 6de23a5 commit 59eec2f
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 16 deletions.
128 changes: 114 additions & 14 deletions programs/marginfi/fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 51 additions & 1 deletion programs/marginfi/fuzz/src/account_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ use anchor_spl::token_2022::spl_token_2022::{
state::Mint,
};
use bumpalo::Bump;
use marginfi::{constants::PYTH_ID, state::marginfi_group::BankVaultType};
use marginfi::{
constants::{FEE_STATE_SEED, PYTH_ID},
state::marginfi_group::BankVaultType,
};
use pyth_sdk_solana::state::{
AccountType, PriceInfo, PriceStatus, Rational, SolanaPriceAccount, MAGIC, VERSION_2,
};
Expand Down Expand Up @@ -60,6 +63,25 @@ impl AccountsState {
)
}

pub fn new_fee_state<'a>(&'a self, program_id: Pubkey) -> (AccountInfo<'a>, u8) {
let (fee_state_key, fee_state_bump) =
Pubkey::find_program_address(&[FEE_STATE_SEED.as_bytes()], &marginfi::id());

(
AccountInfo::new(
self.bump.alloc(fee_state_key),
false,
true,
self.bump.alloc(0),
&mut [],
self.bump.alloc(program_id),
false,
Epoch::default(),
),
fee_state_bump,
)
}

pub fn new_token_mint<'bump>(
&'bump self,
rent: Rent,
Expand Down Expand Up @@ -244,6 +266,17 @@ impl AccountsState {
)
}

pub fn new_blank_owned_account_with_key(
&self,
key: Pubkey,
owner_pubkey: Pubkey,
) -> AccountInfo {
self.new_dex_owned_blank_account_with_key(
self.bump.alloc(key),
self.bump.alloc(owner_pubkey),
)
}

pub fn new_dex_owned_account_with_lamports<'bump>(
&'bump self,
unpadded_len: usize,
Expand All @@ -262,6 +295,23 @@ impl AccountsState {
)
}

pub fn new_dex_owned_blank_account_with_key<'bump>(
&'bump self,
key: &'bump Pubkey,
program_id: &'bump Pubkey,
) -> AccountInfo<'bump> {
AccountInfo::new(
key,
false,
true,
self.bump.alloc(0),
&mut [],
program_id,
false,
Epoch::default(),
)
}

fn allocate_dex_owned_account<'bump>(&'bump self, unpadded_size: usize) -> &mut [u8] {
assert_eq!(unpadded_size % 8, 0);
let padded_size = unpadded_size + 12;
Expand Down
Loading

0 comments on commit 59eec2f

Please sign in to comment.