* Add stable_log output when a program is loaded as native code instead of BPF (cherry picked from commit34f5020457
) * Add ProgramTest::add_builtin_program() This permits the unit testing of builtin programs in the ProgramTest environment (cherry picked from commit830ca369f1
) Co-authored-by: Michael Vines <mvines@gmail.com>
This commit is contained in:
@ -103,6 +103,9 @@ pub fn builtin_process_instruction(
|
|||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
set_invoke_context(invoke_context);
|
set_invoke_context(invoke_context);
|
||||||
|
|
||||||
|
let logger = invoke_context.get_logger();
|
||||||
|
stable_log::program_invoke(&logger, program_id, invoke_context.invoke_depth());
|
||||||
|
|
||||||
let keyed_accounts = invoke_context.get_keyed_accounts()?;
|
let keyed_accounts = invoke_context.get_keyed_accounts()?;
|
||||||
|
|
||||||
// Copy all the accounts into a HashMap to ensure there are no duplicates
|
// Copy all the accounts into a HashMap to ensure there are no duplicates
|
||||||
@ -151,7 +154,12 @@ pub fn builtin_process_instruction(
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Execute the program
|
// Execute the program
|
||||||
process_instruction(program_id, &account_infos, input).map_err(u64::from)?;
|
process_instruction(program_id, &account_infos, input).map_err(|err| {
|
||||||
|
let err = u64::from(err);
|
||||||
|
stable_log::program_failure(&logger, program_id, &err.into());
|
||||||
|
err
|
||||||
|
})?;
|
||||||
|
stable_log::program_success(&logger, program_id);
|
||||||
|
|
||||||
// Commit AccountInfo changes back into KeyedAccounts
|
// Commit AccountInfo changes back into KeyedAccounts
|
||||||
for keyed_account in keyed_accounts {
|
for keyed_account in keyed_accounts {
|
||||||
@ -706,6 +714,20 @@ impl ProgramTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add a builtin program to the test environment.
|
||||||
|
///
|
||||||
|
/// Note that builtin programs are responsible for their own `stable_log` output.
|
||||||
|
pub fn add_builtin_program(
|
||||||
|
&mut self,
|
||||||
|
program_name: &str,
|
||||||
|
program_id: Pubkey,
|
||||||
|
process_instruction: ProcessInstructionWithContext,
|
||||||
|
) {
|
||||||
|
info!("\"{}\" builtin program", program_name);
|
||||||
|
self.builtins
|
||||||
|
.push(Builtin::new(program_name, program_id, process_instruction));
|
||||||
|
}
|
||||||
|
|
||||||
fn setup_bank(
|
fn setup_bank(
|
||||||
&self,
|
&self,
|
||||||
) -> (
|
) -> (
|
||||||
|
Reference in New Issue
Block a user