test: verify malicious self_program_id is rejected in public execution

This commit is contained in:
moudyellaz
2026-04-03 22:13:58 +02:00
parent 3cfc74695b
commit 1d0c93e9cf
3 changed files with 65 additions and 0 deletions
@@ -0,0 +1,31 @@
use nssa_core::program::{
AccountPostState, DEFAULT_PROGRAM_ID, ProgramInput, ProgramOutput, read_nssa_inputs,
};
type Instruction = ();
fn main() {
let (
ProgramInput {
self_program_id: _, // ignore the correct ID
caller_program_id: _,
pre_states,
instruction: (),
},
instruction_words,
) = read_nssa_inputs::<Instruction>();
let post_states = pre_states
.iter()
.map(|a| AccountPostState::new(a.account.clone()))
.collect();
// Deliberately output wrong self_program_id
ProgramOutput::new(
DEFAULT_PROGRAM_ID, // WRONG: should be self_program_id
instruction_words,
pre_states,
post_states,
)
.write();
}