@@ -4,7 +4,7 @@ use anchor_lang::solana_program::{
44 system_instruction,
55} ;
66
7- use anchor_lang:: system_program:: { Transfer , transfer } ;
7+ use anchor_lang:: system_program:: { transfer , Transfer } ;
88
99declare_id ! ( "11111111111111111111111111111111" ) ;
1010
@@ -319,56 +319,18 @@ pub mod missing_account_reload_tests {
319319 }
320320
321321 // Pattern 17: CPI call with self implementation - safe
322- pub fn invoke_with_self_implementation_safe (
323- ctx : Context < SolTransfer3 > ,
324- amount : u64 ,
325- ) -> Result < ( ) > {
322+ pub fn invoke_with_self_implementation_safe ( ctx : Context < SolTransfer3 > , amount : u64 ) -> Result < ( ) > {
326323 ctx. accounts . cpi_call_safe ( amount) ?;
327324 let _final_data = ctx. accounts . pda_account . data ; // [safe_account_accessed]
328325 Ok ( ( ) )
329326 }
330327
331328 // Pattern 18: CPI call with self implementation - unsafe
332- pub fn invoke_with_self_implementation_unsafe (
333- ctx : Context < SolTransfer3 > ,
334- amount : u64 ,
335- ) -> Result < ( ) > {
329+ pub fn invoke_with_self_implementation_unsafe ( ctx : Context < SolTransfer3 > , amount : u64 ) -> Result < ( ) > {
336330 ctx. accounts . cpi_call_unsafe ( amount) ?;
337331 let _final_data = ctx. accounts . pda_account . data ; // [unsafe_account_accessed]
338332 Ok ( ( ) )
339333 }
340-
341- /// Patten 19: load_mut() then CPI — unsafe.
342- pub fn test_lazy_account_unsafe (
343- ctx : Context < LazyAccountCpiAccounts > ,
344- amount : u64 ,
345- ) -> Result < ( ) > {
346- let data = ctx. accounts . lazy_acc . load_mut ( ) ?; // ref held across CPI
347- let _ = data. value ;
348- let new_space = ctx. accounts . lazy_acc . to_account_info ( ) . data_len ( ) as u64 + amount;
349- let ix = system_instruction:: allocate ( & ctx. accounts . lazy_acc . key ( ) , new_space) ;
350- let account_infos = vec ! [
351- ctx. accounts. lazy_acc. to_account_info( ) ,
352- ctx. accounts. system_program. to_account_info( ) ,
353- ] ;
354- invoke ( & ix, & account_infos) ?; // [cpi_call]
355- let _ = data. value ; // [unsafe_account_accessed]
356- Ok ( ( ) )
357- }
358-
359- // Pattern 20: load_mut() then CPI with load_mut() — safe
360- pub fn test_lazy_account_safe ( ctx : Context < LazyAccountCpiAccounts > , amount : u64 ) -> Result < ( ) > {
361- let new_space = ctx. accounts . lazy_acc . to_account_info ( ) . data_len ( ) as u64 + amount;
362- let ix = system_instruction:: allocate ( & ctx. accounts . lazy_acc . key ( ) , new_space) ;
363- let account_infos = vec ! [
364- ctx. accounts. lazy_acc. to_account_info( ) ,
365- ctx. accounts. system_program. to_account_info( ) ,
366- ] ;
367- invoke ( & ix, & account_infos) ?;
368- let data = ctx. accounts . lazy_acc . load_mut ( ) ?;
369- let _ = data. value ; // [safe_account_accessed]
370- Ok ( ( ) )
371- }
372334}
373335pub fn cpi_call_safe ( ctx_a : & mut Context < SolTransfer3 > , amount : u64 ) -> Result < ( ) > {
374336 let from_pubkey = ctx_a. accounts . pda_account . to_account_info ( ) ;
@@ -647,18 +609,6 @@ impl<'info> SolTransfer3<'info> {
647609 }
648610}
649611
650- #[ account]
651- pub struct LazyLoadable {
652- pub value : u64 ,
653- }
654-
655- #[ derive( Accounts ) ]
656- pub struct LazyAccountCpiAccounts < ' info > {
657- #[ account( mut ) ]
658- pub lazy_acc : LazyAccount < ' info , LazyLoadable > ,
659- pub system_program : Program < ' info , System > ,
660- }
661-
662612#[ account]
663613pub struct UserState {
664614 pub data : u64 ,
0 commit comments