Native/builtin programs now receive an InvokeContext
This commit is contained in:
@@ -3,15 +3,19 @@
|
||||
use crate::ConfigKeys;
|
||||
use bincode::deserialize;
|
||||
use log::*;
|
||||
use solana_sdk::instruction::InstructionError;
|
||||
use solana_sdk::keyed_account::{next_keyed_account, KeyedAccount};
|
||||
use solana_sdk::program_utils::limited_deserialize;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::{
|
||||
instruction::InstructionError,
|
||||
keyed_account::{next_keyed_account, KeyedAccount},
|
||||
process_instruction::InvokeContext,
|
||||
program_utils::limited_deserialize,
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
|
||||
pub fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
keyed_accounts: &[KeyedAccount],
|
||||
data: &[u8],
|
||||
_invoke_context: &mut dyn InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
let key_list: ConfigKeys = limited_deserialize(data)?;
|
||||
let keyed_accounts_iter = &mut keyed_accounts.iter();
|
||||
@@ -109,6 +113,7 @@ mod tests {
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
keyed_account::create_keyed_is_signer_accounts,
|
||||
process_instruction::MockInvokeContext,
|
||||
signature::{Keypair, Signer},
|
||||
system_instruction::SystemInstruction,
|
||||
};
|
||||
@@ -162,7 +167,12 @@ mod tests {
|
||||
let accounts = vec![(&config_pubkey, true, &config_account)];
|
||||
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
||||
assert_eq!(
|
||||
process_instruction(&id(), &keyed_accounts, &instructions[1].data),
|
||||
process_instruction(
|
||||
&id(),
|
||||
&keyed_accounts,
|
||||
&instructions[1].data,
|
||||
&mut MockInvokeContext::default()
|
||||
),
|
||||
Ok(())
|
||||
);
|
||||
|
||||
@@ -192,7 +202,12 @@ mod tests {
|
||||
let accounts = vec![(&config_pubkey, true, &config_account)];
|
||||
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
||||
assert_eq!(
|
||||
process_instruction(&id(), &keyed_accounts, &instruction.data),
|
||||
process_instruction(
|
||||
&id(),
|
||||
&keyed_accounts,
|
||||
&instruction.data,
|
||||
&mut MockInvokeContext::default()
|
||||
),
|
||||
Ok(())
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -214,7 +229,12 @@ mod tests {
|
||||
let accounts = vec![(&config_pubkey, true, &config_account)];
|
||||
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
||||
assert_eq!(
|
||||
process_instruction(&id(), &keyed_accounts, &instruction.data),
|
||||
process_instruction(
|
||||
&id(),
|
||||
&keyed_accounts,
|
||||
&instruction.data,
|
||||
&mut MockInvokeContext::default()
|
||||
),
|
||||
Err(InstructionError::InvalidInstructionData)
|
||||
);
|
||||
}
|
||||
@@ -232,7 +252,12 @@ mod tests {
|
||||
let accounts = vec![(&config_pubkey, false, &config_account)];
|
||||
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
||||
assert_eq!(
|
||||
process_instruction(&id(), &keyed_accounts, &instruction.data),
|
||||
process_instruction(
|
||||
&id(),
|
||||
&keyed_accounts,
|
||||
&instruction.data,
|
||||
&mut MockInvokeContext::default()
|
||||
),
|
||||
Err(InstructionError::MissingRequiredSignature)
|
||||
);
|
||||
}
|
||||
@@ -262,7 +287,12 @@ mod tests {
|
||||
];
|
||||
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
||||
assert_eq!(
|
||||
process_instruction(&id(), &keyed_accounts, &instruction.data),
|
||||
process_instruction(
|
||||
&id(),
|
||||
&keyed_accounts,
|
||||
&instruction.data,
|
||||
&mut MockInvokeContext::default()
|
||||
),
|
||||
Ok(())
|
||||
);
|
||||
let meta_data: ConfigKeys = deserialize(&config_account.borrow().data).unwrap();
|
||||
@@ -288,7 +318,12 @@ mod tests {
|
||||
let accounts = vec![(&signer0_pubkey, true, &signer0_account)];
|
||||
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
||||
assert_eq!(
|
||||
process_instruction(&id(), &keyed_accounts, &instruction.data),
|
||||
process_instruction(
|
||||
&id(),
|
||||
&keyed_accounts,
|
||||
&instruction.data,
|
||||
&mut MockInvokeContext::default()
|
||||
),
|
||||
Err(InstructionError::InvalidAccountData)
|
||||
);
|
||||
}
|
||||
@@ -314,7 +349,12 @@ mod tests {
|
||||
];
|
||||
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
||||
assert_eq!(
|
||||
process_instruction(&id(), &keyed_accounts, &instruction.data),
|
||||
process_instruction(
|
||||
&id(),
|
||||
&keyed_accounts,
|
||||
&instruction.data,
|
||||
&mut MockInvokeContext::default()
|
||||
),
|
||||
Err(InstructionError::MissingRequiredSignature)
|
||||
);
|
||||
|
||||
@@ -325,7 +365,12 @@ mod tests {
|
||||
];
|
||||
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
||||
assert_eq!(
|
||||
process_instruction(&id(), &keyed_accounts, &instruction.data),
|
||||
process_instruction(
|
||||
&id(),
|
||||
&keyed_accounts,
|
||||
&instruction.data,
|
||||
&mut MockInvokeContext::default()
|
||||
),
|
||||
Err(InstructionError::MissingRequiredSignature)
|
||||
);
|
||||
}
|
||||
@@ -357,7 +402,12 @@ mod tests {
|
||||
];
|
||||
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
||||
assert_eq!(
|
||||
process_instruction(&id(), &keyed_accounts, &instruction.data),
|
||||
process_instruction(
|
||||
&id(),
|
||||
&keyed_accounts,
|
||||
&instruction.data,
|
||||
&mut MockInvokeContext::default()
|
||||
),
|
||||
Ok(())
|
||||
);
|
||||
|
||||
@@ -372,7 +422,12 @@ mod tests {
|
||||
];
|
||||
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
||||
assert_eq!(
|
||||
process_instruction(&id(), &keyed_accounts, &instruction.data),
|
||||
process_instruction(
|
||||
&id(),
|
||||
&keyed_accounts,
|
||||
&instruction.data,
|
||||
&mut MockInvokeContext::default()
|
||||
),
|
||||
Ok(())
|
||||
);
|
||||
let meta_data: ConfigKeys = deserialize(&config_account.borrow().data).unwrap();
|
||||
@@ -392,7 +447,12 @@ mod tests {
|
||||
];
|
||||
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
||||
assert_eq!(
|
||||
process_instruction(&id(), &keyed_accounts, &instruction.data),
|
||||
process_instruction(
|
||||
&id(),
|
||||
&keyed_accounts,
|
||||
&instruction.data,
|
||||
&mut MockInvokeContext::default()
|
||||
),
|
||||
Err(InstructionError::MissingRequiredSignature)
|
||||
);
|
||||
|
||||
@@ -410,7 +470,12 @@ mod tests {
|
||||
];
|
||||
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
||||
assert_eq!(
|
||||
process_instruction(&id(), &keyed_accounts, &instruction.data),
|
||||
process_instruction(
|
||||
&id(),
|
||||
&keyed_accounts,
|
||||
&instruction.data,
|
||||
&mut MockInvokeContext::default()
|
||||
),
|
||||
Err(InstructionError::MissingRequiredSignature)
|
||||
);
|
||||
}
|
||||
@@ -443,7 +508,12 @@ mod tests {
|
||||
];
|
||||
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
||||
assert_eq!(
|
||||
process_instruction(&id(), &keyed_accounts, &instruction.data),
|
||||
process_instruction(
|
||||
&id(),
|
||||
&keyed_accounts,
|
||||
&instruction.data,
|
||||
&mut MockInvokeContext::default()
|
||||
),
|
||||
Ok(())
|
||||
);
|
||||
|
||||
@@ -457,7 +527,12 @@ mod tests {
|
||||
];
|
||||
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
||||
assert_eq!(
|
||||
process_instruction(&id(), &keyed_accounts, &instruction.data),
|
||||
process_instruction(
|
||||
&id(),
|
||||
&keyed_accounts,
|
||||
&instruction.data,
|
||||
&mut MockInvokeContext::default()
|
||||
),
|
||||
Ok(())
|
||||
);
|
||||
let meta_data: ConfigKeys = deserialize(&config_account.borrow().data).unwrap();
|
||||
@@ -473,7 +548,12 @@ mod tests {
|
||||
let accounts = vec![(&config_pubkey, true, &config_account)];
|
||||
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
||||
assert_eq!(
|
||||
process_instruction(&id(), &keyed_accounts, &instruction.data),
|
||||
process_instruction(
|
||||
&id(),
|
||||
&keyed_accounts,
|
||||
&instruction.data,
|
||||
&mut MockInvokeContext::default()
|
||||
),
|
||||
Err(InstructionError::MissingRequiredSignature)
|
||||
);
|
||||
}
|
||||
@@ -487,7 +567,12 @@ mod tests {
|
||||
let accounts = vec![];
|
||||
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
||||
assert_eq!(
|
||||
process_instruction(&id(), &keyed_accounts, &instructions[1].data),
|
||||
process_instruction(
|
||||
&id(),
|
||||
&keyed_accounts,
|
||||
&instructions[1].data,
|
||||
&mut MockInvokeContext::default()
|
||||
),
|
||||
Err(InstructionError::NotEnoughAccountKeys)
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user