This PR extends the FuzzClient trait and the functionality of AccountsStorage in order to have more flexibility to create and store an arbitrary account. This removes the previous limitation that only basic accounts operations were possible.
Now, one can create and store any kind of account. For example:
to add account that uses the #[account(zero)] anchor constraint (must be rent exempt, owned by our program, with empty data)
let state = fuzz_accounts
.state
.storage()
.entry(self.accounts.state)
.or_insert_with(|| {
let space = State::SIZE;
let rent_exempt_lamports = client.get_rent().unwrap().minimum_balance(space);
let keypair = Keypair::new();
let account = AccountSharedData::new_data_with_space::<[u8; 0]>(
rent_exempt_lamports,
&[],
space,
&my_program::id(),
)
.unwrap();
client.set_account_custom(&keypair.pubkey(), &account);
keypair
});
to add a new system owned account with a specific PDAdress
let rent_exempt_for_token_acc = client
.get_rent()
.unwrap()
.minimum_balance(anchor_spl::token::spl_token::state::Account::LEN);
let reserve_pda = fuzz_accounts
.reserve_pda
.storage()
.entry(self.accounts.reserve_pda)
.or_insert_with(|| {
let seeds = &[b"some-seeds"];
let pda = Pubkey::find_program_address(seeds, &my_program::id()).0;
let account = AccountSharedData::new_data_with_space::<[u8; 0]>(
rent_exempt_for_token_acc,
&[],
0,
&SYSTEM_PROGRAM_ID,
)
.unwrap();
client.set_account_custom(&pda, &account);
let vec_of_seeds: Vec<Vec> = seeds.iter().map(|&seed| seed.to_vec()).collect();
PdaStore {
pubkey: pda,
seeds: vec_of_seeds,
}
})
.pubkey();
This PR extends the FuzzClient trait and the functionality of AccountsStorage in order to have more flexibility to create and store an arbitrary account. This removes the previous limitation that only basic accounts operations were possible.
Now, one can create and store any kind of account. For example:
to add account that uses the
#[account(zero)]
anchor constraint (must be rent exempt, owned by our program, with empty data)to add a new system owned account with a specific PDAdress
let reserve_pda = fuzz_accounts .reserve_pda .storage() .entry(self.accounts.reserve_pda) .or_insert_with(|| { let seeds = &[b"some-seeds"]; let pda = Pubkey::find_program_address(seeds, &my_program::id()).0; let account = AccountSharedData::new_data_with_space::<[u8; 0]>( rent_exempt_for_token_acc, &[], 0, &SYSTEM_PROGRAM_ID, ) .unwrap(); client.set_account_custom(&pda, &account); let vec_of_seeds: Vec<Vec> = seeds.iter().map(|&seed| seed.to_vec()).collect();
PdaStore {
pubkey: pda,
seeds: vec_of_seeds,
}
})
.pubkey();