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

@@ -68,12 +68,12 @@ pub fn parse_system(
space,
owner,
} => {
check_num_system_accounts(&instruction.accounts, 3)?;
check_num_system_accounts(&instruction.accounts, 2)?;
Ok(ParsedInstructionEnum {
instruction_type: "createAccountWithSeed".to_string(),
info: json!({
"source": account_keys[instruction.accounts[0] as usize].to_string(),
"newAccount": account_keys[instruction.accounts[2] as usize].to_string(),
"newAccount": account_keys[instruction.accounts[1] as usize].to_string(),
"base": base.to_string(),
"seed": seed,
"lamports": lamports,
@@ -260,7 +260,7 @@ mod test {
let seed = "test_seed";
let instruction = system_instruction::create_account_with_seed(
&keys[0], &keys[1], &keys[2], seed, lamports, space, &keys[3],
&keys[0], &keys[2], &keys[1], seed, lamports, space, &keys[3],
);
let message = Message::new(&[instruction], None);
assert_eq!(
@@ -269,16 +269,37 @@ mod test {
instruction_type: "createAccountWithSeed".to_string(),
info: json!({
"source": keys[0].to_string(),
"newAccount": keys[1].to_string(),
"newAccount": keys[2].to_string(),
"lamports": lamports,
"base": keys[2].to_string(),
"base": keys[1].to_string(),
"seed": seed,
"owner": keys[3].to_string(),
"space": space,
}),
}
);
assert!(parse_system(&message.instructions[0], &keys[0..2]).is_err());
let seed = "test_seed";
let instruction = system_instruction::create_account_with_seed(
&keys[0], &keys[1], &keys[0], seed, lamports, space, &keys[3],
);
let message = Message::new(&[instruction], None);
assert_eq!(
parse_system(&message.instructions[0], &keys[0..2]).unwrap(),
ParsedInstructionEnum {
instruction_type: "createAccountWithSeed".to_string(),
info: json!({
"source": keys[0].to_string(),
"newAccount": keys[1].to_string(),
"lamports": lamports,
"base": keys[0].to_string(),
"seed": seed,
"owner": keys[3].to_string(),
"space": space,
}),
}
);
assert!(parse_system(&message.instructions[0], &keys[0..1]).is_err());
let instruction = system_instruction::allocate(&keys[0], space);
let message = Message::new(&[instruction], None);