add program account to bpf loader close instruction parser (#26926)

This commit is contained in:
Xavier59 2022-08-05 19:37:42 +02:00 committed by GitHub
parent 432bca3092
commit a7e72d0798
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 52 additions and 2 deletions

View File

@ -146,7 +146,12 @@ pub fn parse_bpf_upgradeable_loader(
info: json!({
"account": account_keys[instruction.accounts[0] as usize].to_string(),
"recipient": account_keys[instruction.accounts[1] as usize].to_string(),
"authority": account_keys[instruction.accounts[2] as usize].to_string()
"authority": account_keys[instruction.accounts[2] as usize].to_string(),
"programAccount": if instruction.accounts.len() > 3 {
Some(account_keys[instruction.accounts[3] as usize].to_string())
} else {
None
}
}),
})
}
@ -606,7 +611,7 @@ mod test {
}
#[test]
fn test_parse_bpf_upgradeable_loader_close_ix() {
fn test_parse_bpf_upgradeable_loader_close_buffer_ix() {
let close_address = Pubkey::new_unique();
let recipient_address = Pubkey::new_unique();
let authority_address = Pubkey::new_unique();
@ -625,6 +630,7 @@ mod test {
"account": close_address.to_string(),
"recipient": recipient_address.to_string(),
"authority": authority_address.to_string(),
"programAccount": Value::Null
}),
}
);
@ -641,4 +647,48 @@ mod test {
)
.is_err());
}
#[test]
fn test_parse_bpf_upgradeable_loader_close_program_ix() {
let close_address = Pubkey::new_unique();
let recipient_address = Pubkey::new_unique();
let authority_address = Pubkey::new_unique();
let program_address = Pubkey::new_unique();
let instruction = bpf_loader_upgradeable::close_any(
&close_address,
&recipient_address,
Some(&authority_address),
Some(&program_address),
);
let mut message = Message::new(&[instruction], None);
assert_eq!(
parse_bpf_upgradeable_loader(
&message.instructions[0],
&AccountKeys::new(&message.account_keys, None)
)
.unwrap(),
ParsedInstructionEnum {
instruction_type: "close".to_string(),
info: json!({
"account": close_address.to_string(),
"recipient": recipient_address.to_string(),
"authority": authority_address.to_string(),
"programAccount": program_address.to_string()
}),
}
);
assert!(parse_bpf_upgradeable_loader(
&message.instructions[0],
&AccountKeys::new(&message.account_keys[0..1], None)
)
.is_err());
let keys = message.account_keys.clone();
message.instructions[0].accounts.pop();
message.instructions[0].accounts.pop();
assert!(parse_bpf_upgradeable_loader(
&message.instructions[0],
&AccountKeys::new(&keys, None)
)
.is_err());
}
}