Fix parsing CreateAccountWithSeed instructions (#13513)

* Reduce required num_system_accounts and handle 2-account instructions properly

* Update CreateAccountWithSeed account docs to be correct

* Add CreateAccountWithSeed test
This commit is contained in:
Tyera Eulberg
2020-11-10 16:51:53 -07:00
committed by GitHub
parent 9ca8e98525
commit 91f4e99b4c
3 changed files with 67 additions and 7 deletions

View File

@ -479,6 +479,43 @@ mod tests {
assert_eq!(to_account.borrow().data, [0, 0]);
}
#[test]
fn test_create_account_with_seed_separate_base_account() {
let new_owner = Pubkey::new(&[9; 32]);
let from = solana_sdk::pubkey::new_rand();
let base = solana_sdk::pubkey::new_rand();
let seed = "shiny pepper";
let to = Pubkey::create_with_seed(&base, seed, &new_owner).unwrap();
let from_account = Account::new_ref(100, 0, &system_program::id());
let to_account = Account::new_ref(0, 0, &Pubkey::default());
let base_account = Account::new_ref(0, 0, &Pubkey::default());
assert_eq!(
process_instruction(
&Pubkey::default(),
&[
KeyedAccount::new(&from, true, &from_account),
KeyedAccount::new(&to, false, &to_account),
KeyedAccount::new(&base, true, &base_account)
],
&bincode::serialize(&SystemInstruction::CreateAccountWithSeed {
base,
seed: seed.to_string(),
lamports: 50,
space: 2,
owner: new_owner
})
.unwrap()
),
Ok(())
);
assert_eq!(from_account.borrow().lamports, 50);
assert_eq!(to_account.borrow().lamports, 50);
assert_eq!(to_account.borrow().owner, new_owner);
assert_eq!(to_account.borrow().data, [0, 0]);
}
#[test]
fn test_address_create_with_seed_mismatch() {
let from = solana_sdk::pubkey::new_rand();