From 7def0c466462126b6dd79781ae0647b076c7d70e Mon Sep 17 00:00:00 2001 From: moudyellaz Date: Thu, 2 Apr 2026 00:41:55 +0200 Subject: [PATCH] refactor: pass self_program_id to ProgramOutput in test and example guest programs --- .../program_deployment/methods/guest/src/bin/hello_world.rs | 5 ++--- .../methods/guest/src/bin/hello_world_with_authorization.rs | 5 ++--- .../methods/guest/src/bin/hello_world_with_move_function.rs | 5 ++--- .../methods/guest/src/bin/simple_tail_call.rs | 5 ++--- .../methods/guest/src/bin/tail_call_with_pda.rs | 5 ++--- test_program_methods/guest/src/bin/burner.rs | 4 ++-- test_program_methods/guest/src/bin/chain_caller.rs | 4 ++-- test_program_methods/guest/src/bin/changer_claimer.rs | 5 ++--- test_program_methods/guest/src/bin/claimer.rs | 5 ++--- test_program_methods/guest/src/bin/data_changer.rs | 4 ++-- test_program_methods/guest/src/bin/extra_output.rs | 3 ++- .../guest/src/bin/malicious_authorization_changer.rs | 4 ++-- test_program_methods/guest/src/bin/minter.rs | 3 ++- test_program_methods/guest/src/bin/missing_output.rs | 3 ++- test_program_methods/guest/src/bin/modified_transfer.rs | 5 ++--- test_program_methods/guest/src/bin/nonce_changer.rs | 3 ++- test_program_methods/guest/src/bin/noop.rs | 4 ++-- test_program_methods/guest/src/bin/program_owner_changer.rs | 3 ++- .../guest/src/bin/simple_balance_transfer.rs | 4 ++-- test_program_methods/guest/src/bin/validity_window.rs | 4 ++-- .../guest/src/bin/validity_window_chain_caller.rs | 4 ++-- 21 files changed, 42 insertions(+), 45 deletions(-) diff --git a/examples/program_deployment/methods/guest/src/bin/hello_world.rs b/examples/program_deployment/methods/guest/src/bin/hello_world.rs index bf1bbe14..a28b90f4 100644 --- a/examples/program_deployment/methods/guest/src/bin/hello_world.rs +++ b/examples/program_deployment/methods/guest/src/bin/hello_world.rs @@ -18,8 +18,7 @@ type Instruction = Vec; fn main() { // Read inputs let ( - ProgramInput { - self_program_id: _, + ProgramInput { self_program_id, pre_states, instruction: greeting, }, @@ -51,5 +50,5 @@ fn main() { // with the NSSA program rules. // WARNING: constructing a `ProgramOutput` has no effect on its own. `.write()` must be // called to commit the output. - ProgramOutput::new(instruction_data, vec![pre_state], vec![post_state]).write(); + ProgramOutput::new(self_program_id, instruction_data, vec![pre_state], vec![post_state]).write(); } diff --git a/examples/program_deployment/methods/guest/src/bin/hello_world_with_authorization.rs b/examples/program_deployment/methods/guest/src/bin/hello_world_with_authorization.rs index 15e658c4..57e90195 100644 --- a/examples/program_deployment/methods/guest/src/bin/hello_world_with_authorization.rs +++ b/examples/program_deployment/methods/guest/src/bin/hello_world_with_authorization.rs @@ -18,8 +18,7 @@ type Instruction = Vec; fn main() { // Read inputs let ( - ProgramInput { - self_program_id: _, + ProgramInput { self_program_id, pre_states, instruction: greeting, }, @@ -58,5 +57,5 @@ fn main() { // with the NSSA program rules. // WARNING: constructing a `ProgramOutput` has no effect on its own. `.write()` must be // called to commit the output. - ProgramOutput::new(instruction_data, vec![pre_state], vec![post_state]).write(); + ProgramOutput::new(self_program_id, instruction_data, vec![pre_state], vec![post_state]).write(); } diff --git a/examples/program_deployment/methods/guest/src/bin/hello_world_with_move_function.rs b/examples/program_deployment/methods/guest/src/bin/hello_world_with_move_function.rs index f9cddc35..bbeb1ce0 100644 --- a/examples/program_deployment/methods/guest/src/bin/hello_world_with_move_function.rs +++ b/examples/program_deployment/methods/guest/src/bin/hello_world_with_move_function.rs @@ -65,8 +65,7 @@ fn move_data(from_pre: AccountWithMetadata, to_pre: AccountWithMetadata) -> Vec< fn main() { // Read input accounts. let ( - ProgramInput { - self_program_id: _, + ProgramInput { self_program_id, pre_states, instruction: (function_id, data), }, @@ -86,5 +85,5 @@ fn main() { // WARNING: constructing a `ProgramOutput` has no effect on its own. `.write()` must be // called to commit the output. - ProgramOutput::new(instruction_words, pre_states, post_states).write(); + ProgramOutput::new(self_program_id, instruction_words, pre_states, post_states).write(); } diff --git a/examples/program_deployment/methods/guest/src/bin/simple_tail_call.rs b/examples/program_deployment/methods/guest/src/bin/simple_tail_call.rs index 18ff8e9c..8107cc34 100644 --- a/examples/program_deployment/methods/guest/src/bin/simple_tail_call.rs +++ b/examples/program_deployment/methods/guest/src/bin/simple_tail_call.rs @@ -26,8 +26,7 @@ fn hello_world_program_id() -> ProgramId { fn main() { // Read inputs let ( - ProgramInput { - self_program_id: _, + ProgramInput { self_program_id, pre_states, instruction: (), }, @@ -56,7 +55,7 @@ fn main() { // Write the outputs. // WARNING: constructing a `ProgramOutput` has no effect on its own. `.write()` must be // called to commit the output. - ProgramOutput::new(instruction_data, vec![pre_state], vec![post_state]) + ProgramOutput::new(self_program_id, instruction_data, vec![pre_state], vec![post_state]) .with_chained_calls(vec![chained_call]) .write(); } diff --git a/examples/program_deployment/methods/guest/src/bin/tail_call_with_pda.rs b/examples/program_deployment/methods/guest/src/bin/tail_call_with_pda.rs index 8f4e3941..682dc210 100644 --- a/examples/program_deployment/methods/guest/src/bin/tail_call_with_pda.rs +++ b/examples/program_deployment/methods/guest/src/bin/tail_call_with_pda.rs @@ -32,8 +32,7 @@ fn hello_world_program_id() -> ProgramId { fn main() { // Read inputs let ( - ProgramInput { - self_program_id: _, + ProgramInput { self_program_id, pre_states, instruction: (), }, @@ -69,7 +68,7 @@ fn main() { // Write the outputs. // WARNING: constructing a `ProgramOutput` has no effect on its own. `.write()` must be // called to commit the output. - ProgramOutput::new(instruction_data, vec![pre_state], vec![post_state]) + ProgramOutput::new(self_program_id, instruction_data, vec![pre_state], vec![post_state]) .with_chained_calls(vec![chained_call]) .write(); } diff --git a/test_program_methods/guest/src/bin/burner.rs b/test_program_methods/guest/src/bin/burner.rs index d5cbc4e5..20bc3cb6 100644 --- a/test_program_methods/guest/src/bin/burner.rs +++ b/test_program_methods/guest/src/bin/burner.rs @@ -4,8 +4,7 @@ type Instruction = u128; fn main() { let ( - ProgramInput { - self_program_id: _, + ProgramInput { self_program_id, pre_states, instruction: balance_to_burn, }, @@ -21,6 +20,7 @@ fn main() { account_post.balance = account_post.balance.saturating_sub(balance_to_burn); ProgramOutput::new( + self_program_id, instruction_words, vec![pre], vec![AccountPostState::new(account_post)], diff --git a/test_program_methods/guest/src/bin/chain_caller.rs b/test_program_methods/guest/src/bin/chain_caller.rs index c619d5e1..3f7794d8 100644 --- a/test_program_methods/guest/src/bin/chain_caller.rs +++ b/test_program_methods/guest/src/bin/chain_caller.rs @@ -12,8 +12,7 @@ type Instruction = (u128, ProgramId, u32, Option); /// program. fn main() { let ( - ProgramInput { - self_program_id: _, + ProgramInput { self_program_id, pre_states, instruction: (balance, auth_transfer_id, num_chain_calls, pda_seed), }, @@ -56,6 +55,7 @@ fn main() { } ProgramOutput::new( + self_program_id, instruction_words, vec![sender_pre.clone(), recipient_pre.clone()], vec![ diff --git a/test_program_methods/guest/src/bin/changer_claimer.rs b/test_program_methods/guest/src/bin/changer_claimer.rs index 53435db0..bc0f054a 100644 --- a/test_program_methods/guest/src/bin/changer_claimer.rs +++ b/test_program_methods/guest/src/bin/changer_claimer.rs @@ -5,8 +5,7 @@ type Instruction = (Option>, bool); /// A program that optionally modifies the account data and optionally claims it. fn main() { let ( - ProgramInput { - self_program_id: _, + ProgramInput { self_program_id, pre_states, instruction: (data_opt, should_claim), }, @@ -34,5 +33,5 @@ fn main() { AccountPostState::new(account_post) }; - ProgramOutput::new(instruction_words, vec![pre], vec![post_state]).write(); + ProgramOutput::new(self_program_id, instruction_words, vec![pre], vec![post_state]).write(); } diff --git a/test_program_methods/guest/src/bin/claimer.rs b/test_program_methods/guest/src/bin/claimer.rs index c9d391ff..c3794a23 100644 --- a/test_program_methods/guest/src/bin/claimer.rs +++ b/test_program_methods/guest/src/bin/claimer.rs @@ -4,8 +4,7 @@ type Instruction = (); fn main() { let ( - ProgramInput { - self_program_id: _, + ProgramInput { self_program_id, pre_states, instruction: (), }, @@ -18,5 +17,5 @@ fn main() { let account_post = AccountPostState::new_claimed(pre.account.clone(), Claim::Authorized); - ProgramOutput::new(instruction_words, vec![pre], vec![account_post]).write(); + ProgramOutput::new(self_program_id, instruction_words, vec![pre], vec![account_post]).write(); } diff --git a/test_program_methods/guest/src/bin/data_changer.rs b/test_program_methods/guest/src/bin/data_changer.rs index 4680376f..6ff68dab 100644 --- a/test_program_methods/guest/src/bin/data_changer.rs +++ b/test_program_methods/guest/src/bin/data_changer.rs @@ -5,8 +5,7 @@ type Instruction = Vec; /// A program that modifies the account data by setting bytes sent in instruction. fn main() { let ( - ProgramInput { - self_program_id: _, + ProgramInput { self_program_id, pre_states, instruction: data, }, @@ -24,6 +23,7 @@ fn main() { .expect("provided data should fit into data limit"); ProgramOutput::new( + self_program_id, instruction_words, vec![pre], vec![AccountPostState::new_claimed( diff --git a/test_program_methods/guest/src/bin/extra_output.rs b/test_program_methods/guest/src/bin/extra_output.rs index 3adc591c..f6e1f970 100644 --- a/test_program_methods/guest/src/bin/extra_output.rs +++ b/test_program_methods/guest/src/bin/extra_output.rs @@ -6,7 +6,7 @@ use nssa_core::{ type Instruction = (); fn main() { - let (ProgramInput { pre_states, .. }, instruction_words) = read_nssa_inputs::(); + let (ProgramInput { self_program_id, pre_states, .. }, instruction_words) = read_nssa_inputs::(); let Ok([pre]) = <[_; 1]>::try_from(pre_states) else { return; @@ -15,6 +15,7 @@ fn main() { let account_pre = pre.account.clone(); ProgramOutput::new( + self_program_id, instruction_words, vec![pre], vec![ diff --git a/test_program_methods/guest/src/bin/malicious_authorization_changer.rs b/test_program_methods/guest/src/bin/malicious_authorization_changer.rs index a177cbe0..768dc990 100644 --- a/test_program_methods/guest/src/bin/malicious_authorization_changer.rs +++ b/test_program_methods/guest/src/bin/malicious_authorization_changer.rs @@ -13,8 +13,7 @@ type Instruction = (u128, ProgramId); /// but sets the `is_authorized` field of the first account to true. fn main() { let ( - ProgramInput { - self_program_id: _, + ProgramInput { self_program_id, pre_states, instruction: (balance, transfer_program_id), }, @@ -41,6 +40,7 @@ fn main() { }; ProgramOutput::new( + self_program_id, instruction_words, vec![sender.clone(), receiver.clone()], vec![ diff --git a/test_program_methods/guest/src/bin/minter.rs b/test_program_methods/guest/src/bin/minter.rs index ac29e4d3..3bebbb1f 100644 --- a/test_program_methods/guest/src/bin/minter.rs +++ b/test_program_methods/guest/src/bin/minter.rs @@ -3,7 +3,7 @@ use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nss type Instruction = (); fn main() { - let (ProgramInput { pre_states, .. }, instruction_words) = read_nssa_inputs::(); + let (ProgramInput { self_program_id, pre_states, .. }, instruction_words) = read_nssa_inputs::(); let Ok([pre]) = <[_; 1]>::try_from(pre_states) else { return; @@ -17,6 +17,7 @@ fn main() { .expect("Balance overflow"); ProgramOutput::new( + self_program_id, instruction_words, vec![pre], vec![AccountPostState::new(account_post)], diff --git a/test_program_methods/guest/src/bin/missing_output.rs b/test_program_methods/guest/src/bin/missing_output.rs index b485e87a..36f72bf8 100644 --- a/test_program_methods/guest/src/bin/missing_output.rs +++ b/test_program_methods/guest/src/bin/missing_output.rs @@ -3,7 +3,7 @@ use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nss type Instruction = (); fn main() { - let (ProgramInput { pre_states, .. }, instruction_words) = read_nssa_inputs::(); + let (ProgramInput { self_program_id, pre_states, .. }, instruction_words) = read_nssa_inputs::(); let Ok([pre1, pre2]) = <[_; 2]>::try_from(pre_states) else { return; @@ -12,6 +12,7 @@ fn main() { let account_pre1 = pre1.account.clone(); ProgramOutput::new( + self_program_id, instruction_words, vec![pre1, pre2], vec![AccountPostState::new(account_pre1)], diff --git a/test_program_methods/guest/src/bin/modified_transfer.rs b/test_program_methods/guest/src/bin/modified_transfer.rs index 969e139e..97578512 100644 --- a/test_program_methods/guest/src/bin/modified_transfer.rs +++ b/test_program_methods/guest/src/bin/modified_transfer.rs @@ -63,8 +63,7 @@ fn transfer( fn main() { // Read input accounts. let ( - ProgramInput { - self_program_id: _, + ProgramInput { self_program_id, pre_states, instruction: balance_to_move, }, @@ -81,5 +80,5 @@ fn main() { } _ => panic!("invalid params"), }; - ProgramOutput::new(instruction_data, pre_states, post_states).write(); + ProgramOutput::new(self_program_id, instruction_data, pre_states, post_states).write(); } diff --git a/test_program_methods/guest/src/bin/nonce_changer.rs b/test_program_methods/guest/src/bin/nonce_changer.rs index 0cecdc81..30e2f4e8 100644 --- a/test_program_methods/guest/src/bin/nonce_changer.rs +++ b/test_program_methods/guest/src/bin/nonce_changer.rs @@ -3,7 +3,7 @@ use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nss type Instruction = (); fn main() { - let (ProgramInput { pre_states, .. }, instruction_words) = read_nssa_inputs::(); + let (ProgramInput { self_program_id, pre_states, .. }, instruction_words) = read_nssa_inputs::(); let Ok([pre]) = <[_; 1]>::try_from(pre_states) else { return; @@ -14,6 +14,7 @@ fn main() { account_post.nonce.public_account_nonce_increment(); ProgramOutput::new( + self_program_id, instruction_words, vec![pre], vec![AccountPostState::new(account_post)], diff --git a/test_program_methods/guest/src/bin/noop.rs b/test_program_methods/guest/src/bin/noop.rs index 35a07765..eba068c8 100644 --- a/test_program_methods/guest/src/bin/noop.rs +++ b/test_program_methods/guest/src/bin/noop.rs @@ -3,11 +3,11 @@ use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nss type Instruction = (); fn main() { - let (ProgramInput { pre_states, .. }, instruction_words) = read_nssa_inputs::(); + let (ProgramInput { self_program_id, pre_states, .. }, instruction_words) = read_nssa_inputs::(); let post_states = pre_states .iter() .map(|account| AccountPostState::new(account.account.clone())) .collect(); - ProgramOutput::new(instruction_words, pre_states, post_states).write(); + ProgramOutput::new(self_program_id, instruction_words, pre_states, post_states).write(); } diff --git a/test_program_methods/guest/src/bin/program_owner_changer.rs b/test_program_methods/guest/src/bin/program_owner_changer.rs index 7e421351..1a6fadbb 100644 --- a/test_program_methods/guest/src/bin/program_owner_changer.rs +++ b/test_program_methods/guest/src/bin/program_owner_changer.rs @@ -3,7 +3,7 @@ use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nss type Instruction = (); fn main() { - let (ProgramInput { pre_states, .. }, instruction_words) = read_nssa_inputs::(); + let (ProgramInput { self_program_id, pre_states, .. }, instruction_words) = read_nssa_inputs::(); let Ok([pre]) = <[_; 1]>::try_from(pre_states) else { return; @@ -14,6 +14,7 @@ fn main() { account_post.program_owner = [0, 1, 2, 3, 4, 5, 6, 7]; ProgramOutput::new( + self_program_id, instruction_words, vec![pre], vec![AccountPostState::new(account_post)], diff --git a/test_program_methods/guest/src/bin/simple_balance_transfer.rs b/test_program_methods/guest/src/bin/simple_balance_transfer.rs index b0a33764..3c71310f 100644 --- a/test_program_methods/guest/src/bin/simple_balance_transfer.rs +++ b/test_program_methods/guest/src/bin/simple_balance_transfer.rs @@ -4,8 +4,7 @@ type Instruction = u128; fn main() { let ( - ProgramInput { - self_program_id: _, + ProgramInput { self_program_id, pre_states, instruction: balance, }, @@ -28,6 +27,7 @@ fn main() { .expect("Overflow when adding balance"); ProgramOutput::new( + self_program_id, instruction_words, vec![sender_pre, receiver_pre], vec![ diff --git a/test_program_methods/guest/src/bin/validity_window.rs b/test_program_methods/guest/src/bin/validity_window.rs index 864ba24b..3bcd9daf 100644 --- a/test_program_methods/guest/src/bin/validity_window.rs +++ b/test_program_methods/guest/src/bin/validity_window.rs @@ -7,8 +7,7 @@ type Instruction = (BlockValidityWindow, TimestampValidityWindow); fn main() { let ( - ProgramInput { - self_program_id: _, + ProgramInput { self_program_id, pre_states, instruction: (block_validity_window, timestamp_validity_window), }, @@ -22,6 +21,7 @@ fn main() { let post = pre.account.clone(); ProgramOutput::new( + self_program_id, instruction_words, vec![pre], vec![AccountPostState::new(post)], diff --git a/test_program_methods/guest/src/bin/validity_window_chain_caller.rs b/test_program_methods/guest/src/bin/validity_window_chain_caller.rs index acc11d17..4ea4abcf 100644 --- a/test_program_methods/guest/src/bin/validity_window_chain_caller.rs +++ b/test_program_methods/guest/src/bin/validity_window_chain_caller.rs @@ -15,8 +15,7 @@ type Instruction = (BlockValidityWindow, ProgramId, BlockValidityWindow); fn main() { let ( - ProgramInput { - self_program_id: _, + ProgramInput { self_program_id, pre_states, instruction: (block_validity_window, chained_program_id, chained_block_validity_window), }, @@ -39,6 +38,7 @@ fn main() { }; ProgramOutput::new( + self_program_id, instruction_words, vec![pre], vec![AccountPostState::new(post)],