Add return data implementation

This consists of:
 - syscalls
 - passing return data from invoked to invoker
 - printing to stable log
 - rust and C SDK changes
This commit is contained in:
Sean Young
2021-09-01 10:14:01 +01:00
parent 2dee098b91
commit 098585234d
23 changed files with 641 additions and 35 deletions

View File

@ -10,7 +10,7 @@ use solana_program::{
entrypoint,
entrypoint::{ProgramResult, MAX_PERMITTED_DATA_INCREASE},
msg,
program::{invoke, invoke_signed},
program::{get_return_data, invoke, invoke_signed, set_return_data},
program_error::ProgramError,
pubkey::{Pubkey, PubkeyError},
system_instruction,
@ -394,6 +394,27 @@ fn process_instruction(
assert_eq!(data[i], i as u8);
}
}
msg!("Test return data via invoked");
{
// this should be cleared on entry, the invoked tests for this
set_return_data(b"x");
let instruction = create_instruction(
*accounts[INVOKED_PROGRAM_INDEX].key,
&[(accounts[ARGUMENT_INDEX].key, false, true)],
vec![SET_RETURN_DATA],
);
let _ = invoke(&instruction, accounts);
assert_eq!(
get_return_data(),
Some((
*accounts[INVOKED_PROGRAM_INDEX].key,
b"Set by invoked".to_vec()
))
);
}
}
TEST_PRIVILEGE_ESCALATION_SIGNER => {
msg!("Test privilege escalation signer");