Add test to enforce that program id account info for CPI is optional (#22069)

* Update tests to demonstrate that program id account info for CPI is optional

* Clean up comments that say that program id account info is required
This commit is contained in:
Justin Starry
2021-12-23 17:43:15 -06:00
committed by GitHub
parent b93ab5d295
commit ec7536faf6
7 changed files with 13 additions and 29 deletions

View File

@ -54,7 +54,7 @@ fn process_instruction(
&[instruction_data[0], instruction_data[1], 1],
vec![AccountMeta::new_readonly(instructions::id(), false)],
),
accounts,
&[instructions_account.clone()],
)?;
}

View File

@ -14,7 +14,6 @@ fn process_instruction(
instruction_data: &[u8],
) -> ProgramResult {
let to_call = accounts[0].key;
let infos = accounts;
let instruction = Instruction {
accounts: accounts[1..]
.iter()
@ -27,5 +26,7 @@ fn process_instruction(
data: instruction_data.to_owned(),
program_id: *to_call,
};
invoke(&instruction, infos)
// program id account is not required for invocations if the
// program id is not one of the instruction account metas.
invoke(&instruction, &accounts[1..])
}

View File

@ -8,13 +8,12 @@ use solana_program::{
entrypoint!(process_instruction);
fn process_instruction(
program_id: &Pubkey,
_program_id: &Pubkey,
accounts: &[AccountInfo],
_instruction_data: &[u8],
) -> ProgramResult {
msg!("Upgradeable program");
assert_eq!(accounts.len(), 2);
assert_eq!(accounts[0].key, program_id);
assert_eq!(*accounts[1].key, clock::id());
assert_eq!(accounts.len(), 1);
assert_eq!(*accounts[0].key, clock::id());
Err(42.into())
}

View File

@ -8,13 +8,12 @@ use solana_program::{
entrypoint!(process_instruction);
fn process_instruction(
program_id: &Pubkey,
_program_id: &Pubkey,
accounts: &[AccountInfo],
_instruction_data: &[u8],
) -> ProgramResult {
msg!("Upgraded program");
assert_eq!(accounts.len(), 2);
assert_eq!(accounts[0].key, program_id);
assert_eq!(*accounts[1].key, clock::id());
assert_eq!(accounts.len(), 1);
assert_eq!(*accounts[0].key, clock::id());
Err(43.into())
}