Add test to ensure instructions sysvar behaves as expected from within a CPI
This commit is contained in:
parent
94ca5063de
commit
46230185c2
|
@ -2,14 +2,21 @@
|
||||||
|
|
||||||
extern crate solana_program;
|
extern crate solana_program;
|
||||||
use solana_program::{
|
use solana_program::{
|
||||||
account_info::next_account_info, account_info::AccountInfo, entrypoint,
|
account_info::next_account_info,
|
||||||
entrypoint::ProgramResult, msg, program_error::ProgramError, pubkey::Pubkey,
|
account_info::AccountInfo,
|
||||||
|
entrypoint,
|
||||||
|
entrypoint::ProgramResult,
|
||||||
|
instruction::{AccountMeta, Instruction},
|
||||||
|
msg,
|
||||||
|
program::invoke,
|
||||||
|
program_error::ProgramError,
|
||||||
|
pubkey::Pubkey,
|
||||||
sysvar::instructions,
|
sysvar::instructions,
|
||||||
};
|
};
|
||||||
|
|
||||||
entrypoint!(process_instruction);
|
entrypoint!(process_instruction);
|
||||||
fn process_instruction(
|
fn process_instruction(
|
||||||
_program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
accounts: &[AccountInfo],
|
accounts: &[AccountInfo],
|
||||||
instruction_data: &[u8],
|
instruction_data: &[u8],
|
||||||
) -> ProgramResult {
|
) -> ProgramResult {
|
||||||
|
@ -41,5 +48,19 @@ fn process_instruction(
|
||||||
|
|
||||||
msg!(&format!("data[0]: {}", instruction.data[0]));
|
msg!(&format!("data[0]: {}", instruction.data[0]));
|
||||||
msg!(&format!("index: {}", current_instruction));
|
msg!(&format!("index: {}", current_instruction));
|
||||||
|
|
||||||
|
if instruction_data.len() == 2 {
|
||||||
|
// CPI ourself with the same arguments to confirm the instructions sysvar reports the same
|
||||||
|
// results from within a CPI
|
||||||
|
invoke(
|
||||||
|
&Instruction::new_with_bytes(
|
||||||
|
*program_id,
|
||||||
|
&[instruction_data[0], instruction_data[1], 1],
|
||||||
|
vec![AccountMeta::new_readonly(instructions::id(), false)],
|
||||||
|
),
|
||||||
|
&[instruction_accounts.clone()],
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue