Native/builtin programs now receive an InvokeContext
This commit is contained in:
@@ -6,6 +6,7 @@ use solana_sdk::{
|
||||
keyed_account::{from_keyed_account, get_signers, next_keyed_account, KeyedAccount},
|
||||
nonce,
|
||||
nonce_keyed_account::NonceKeyedAccount,
|
||||
process_instruction::InvokeContext,
|
||||
program_utils::limited_deserialize,
|
||||
pubkey::Pubkey,
|
||||
system_instruction::{SystemError, SystemInstruction, MAX_PERMITTED_DATA_LENGTH},
|
||||
@@ -213,6 +214,7 @@ pub fn process_instruction(
|
||||
_owner: &Pubkey,
|
||||
keyed_accounts: &[KeyedAccount],
|
||||
instruction_data: &[u8],
|
||||
_invoke_context: &mut dyn InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
let instruction = limited_deserialize(instruction_data)?;
|
||||
|
||||
@@ -363,7 +365,9 @@ mod tests {
|
||||
hash::{hash, Hash},
|
||||
instruction::{AccountMeta, Instruction, InstructionError},
|
||||
message::Message,
|
||||
nonce, nonce_account, recent_blockhashes_account,
|
||||
nonce, nonce_account,
|
||||
process_instruction::MockInvokeContext,
|
||||
recent_blockhashes_account,
|
||||
signature::{Keypair, Signer},
|
||||
system_instruction, system_program, sysvar,
|
||||
sysvar::recent_blockhashes::IterItem,
|
||||
@@ -381,6 +385,19 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn process_instruction(
|
||||
owner: &Pubkey,
|
||||
keyed_accounts: &[KeyedAccount],
|
||||
instruction_data: &[u8],
|
||||
) -> Result<(), InstructionError> {
|
||||
super::process_instruction(
|
||||
owner,
|
||||
keyed_accounts,
|
||||
instruction_data,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
}
|
||||
|
||||
fn create_default_account() -> RefCell<Account> {
|
||||
RefCell::new(Account::default())
|
||||
}
|
||||
@@ -1194,7 +1211,7 @@ mod tests {
|
||||
.zip(accounts.iter())
|
||||
.map(|(meta, account)| KeyedAccount::new(&meta.pubkey, meta.is_signer, account))
|
||||
.collect();
|
||||
super::process_instruction(&Pubkey::default(), &keyed_accounts, &instruction.data)
|
||||
process_instruction(&Pubkey::default(), &keyed_accounts, &instruction.data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1212,7 +1229,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_process_nonce_ix_no_keyed_accs_fail() {
|
||||
assert_eq!(
|
||||
super::process_instruction(
|
||||
process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[],
|
||||
&serialize(&SystemInstruction::AdvanceNonceAccount).unwrap()
|
||||
@@ -1224,7 +1241,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_process_nonce_ix_only_nonce_acc_fail() {
|
||||
assert_eq!(
|
||||
super::process_instruction(
|
||||
process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[KeyedAccount::new(
|
||||
&Pubkey::default(),
|
||||
@@ -1240,7 +1257,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_process_nonce_ix_bad_recent_blockhash_state_fail() {
|
||||
assert_eq!(
|
||||
super::process_instruction(
|
||||
process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[
|
||||
KeyedAccount::new(&Pubkey::default(), true, &create_default_account()),
|
||||
@@ -1259,7 +1276,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_process_nonce_ix_ok() {
|
||||
let nonce_acc = nonce_account::create_account(1_000_000);
|
||||
super::process_instruction(
|
||||
process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[
|
||||
KeyedAccount::new(&Pubkey::default(), true, &nonce_acc),
|
||||
@@ -1288,7 +1305,7 @@ mod tests {
|
||||
),
|
||||
);
|
||||
assert_eq!(
|
||||
super::process_instruction(
|
||||
process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[
|
||||
KeyedAccount::new(&Pubkey::default(), true, &nonce_acc,),
|
||||
@@ -1320,7 +1337,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_process_withdraw_ix_no_keyed_accs_fail() {
|
||||
assert_eq!(
|
||||
super::process_instruction(
|
||||
process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[],
|
||||
&serialize(&SystemInstruction::WithdrawNonceAccount(42)).unwrap(),
|
||||
@@ -1332,7 +1349,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_process_withdraw_ix_only_nonce_acc_fail() {
|
||||
assert_eq!(
|
||||
super::process_instruction(
|
||||
process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[KeyedAccount::new(
|
||||
&Pubkey::default(),
|
||||
@@ -1348,7 +1365,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_process_withdraw_ix_bad_recent_blockhash_state_fail() {
|
||||
assert_eq!(
|
||||
super::process_instruction(
|
||||
process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[
|
||||
KeyedAccount::new(&Pubkey::default(), true, &create_default_account()),
|
||||
@@ -1368,7 +1385,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_process_withdraw_ix_bad_rent_state_fail() {
|
||||
assert_eq!(
|
||||
super::process_instruction(
|
||||
process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[
|
||||
KeyedAccount::new(
|
||||
@@ -1393,7 +1410,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_process_withdraw_ix_ok() {
|
||||
assert_eq!(
|
||||
super::process_instruction(
|
||||
process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[
|
||||
KeyedAccount::new(
|
||||
@@ -1418,7 +1435,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_process_initialize_ix_no_keyed_accs_fail() {
|
||||
assert_eq!(
|
||||
super::process_instruction(
|
||||
process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[],
|
||||
&serialize(&SystemInstruction::InitializeNonceAccount(Pubkey::default())).unwrap(),
|
||||
@@ -1430,7 +1447,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_process_initialize_ix_only_nonce_acc_fail() {
|
||||
assert_eq!(
|
||||
super::process_instruction(
|
||||
process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[KeyedAccount::new(
|
||||
&Pubkey::default(),
|
||||
@@ -1446,7 +1463,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_process_initialize_bad_recent_blockhash_state_fail() {
|
||||
assert_eq!(
|
||||
super::process_instruction(
|
||||
process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[
|
||||
KeyedAccount::new(
|
||||
@@ -1469,7 +1486,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_process_initialize_ix_bad_rent_state_fail() {
|
||||
assert_eq!(
|
||||
super::process_instruction(
|
||||
process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[
|
||||
KeyedAccount::new(
|
||||
@@ -1493,7 +1510,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_process_initialize_ix_ok() {
|
||||
assert_eq!(
|
||||
super::process_instruction(
|
||||
process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[
|
||||
KeyedAccount::new(
|
||||
@@ -1517,7 +1534,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_process_authorize_ix_ok() {
|
||||
let nonce_acc = nonce_account::create_account(1_000_000);
|
||||
super::process_instruction(
|
||||
process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[
|
||||
KeyedAccount::new(&Pubkey::default(), true, &nonce_acc),
|
||||
@@ -1532,7 +1549,7 @@ mod tests {
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
super::process_instruction(
|
||||
process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[KeyedAccount::new(&Pubkey::default(), true, &nonce_acc,),],
|
||||
&serialize(&SystemInstruction::AuthorizeNonceAccount(Pubkey::default(),)).unwrap(),
|
||||
|
Reference in New Issue
Block a user