@@ -1749,8 +1749,8 @@ pub fn test_process_close_account(accounts: &[AccountInfo; 3]) -> ProgramResult
17491749 let src_initialised = get_account ( & accounts[ 0 ] ) . is_initialized ( ) ;
17501750 let src_data_len = accounts[ 0 ] . data_len ( ) ;
17511751 let src_init_amount = get_account ( & accounts[ 0 ] ) . amount ( ) ;
1752- let dst_init_lamports = accounts[ 0 ] . lamports ( ) ;
1753- let src_init_lamports = accounts[ 1 ] . lamports ( ) ;
1752+ let src_init_lamports = accounts[ 0 ] . lamports ( ) ;
1753+ let dst_init_lamports = accounts[ 1 ] . lamports ( ) ;
17541754 let src_is_native = get_account ( & accounts[ 0 ] ) . is_native ( ) ;
17551755 let src_owned_sys_inc = get_account ( & accounts[ 0 ] ) . is_owned_by_system_program_or_incinerator ( ) ;
17561756 let authority = get_account ( & accounts[ 0 ] )
@@ -1800,6 +1800,7 @@ pub fn test_process_close_account(accounts: &[AccountInfo; 3]) -> ProgramResult
18001800 }
18011801
18021802 // Validate owner falls through to here if no error
1803+ assert_eq ! ( accounts[ 0 ] . lamports( ) , 0 ) ;
18031804 assert_eq ! (
18041805 accounts[ 1 ] . lamports( ) ,
18051806 dst_init_lamports + src_init_lamports
@@ -3057,70 +3058,70 @@ fn test_process_set_authority_account(
30573058 } else if account_data_len != Account :: LEN && account_data_len != Mint :: LEN {
30583059 assert_eq ! ( result, Err ( ProgramError :: InvalidArgument ) ) ;
30593060 return result;
3060- } else {
3061- assert_eq ! ( account_data_len, Account :: LEN ) ; // established by cheatcode_is_account
3062- if account_data_len == Account :: LEN {
3063- if src_initialised. is_err ( ) {
3064- assert_eq ! ( result, Err ( ProgramError :: InvalidAccountData ) ) ;
3065- return result;
3066- } else if !src_initialised. unwrap ( ) {
3067- assert_eq ! ( result, Err ( ProgramError :: UninitializedAccount ) ) ;
3068- return result;
3069- } else if src_init_state. unwrap ( ) == account_state:: AccountState :: Frozen {
3070- assert_eq ! ( result, Err ( ProgramError :: Custom ( 17 ) ) ) ;
3071- return result;
3072- } else if instruction_data[ 0 ] != 2 && instruction_data[ 0 ] != 3 {
3073- // AuthorityType neither AccountOwner nor CloseAccount
3074- assert_eq ! ( result, Err ( ProgramError :: Custom ( 15 ) ) ) ;
3061+ } else if account_data_len == Account :: LEN {
3062+ // established by cheatcode_is_account
3063+ if src_initialised. is_err ( ) {
3064+ assert_eq ! ( result, Err ( ProgramError :: InvalidAccountData ) ) ;
3065+ return result;
3066+ } else if !src_initialised. unwrap ( ) {
3067+ assert_eq ! ( result, Err ( ProgramError :: UninitializedAccount ) ) ;
3068+ return result;
3069+ } else if src_init_state. unwrap ( ) == account_state:: AccountState :: Frozen {
3070+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 17 ) ) ) ;
3071+ return result;
3072+ } else if instruction_data[ 0 ] != 2 && instruction_data[ 0 ] != 3 {
3073+ // AuthorityType neither AccountOwner nor CloseAccount
3074+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 15 ) ) ) ;
3075+ return result;
3076+ } else if instruction_data[ 0 ] == 2 {
3077+ // AccountOwner
3078+ // Validate Owner
3079+ inner_test_validate_owner (
3080+ & src_owner, // expected_owner
3081+ & accounts[ 1 ] , // owner_account_info
3082+ & accounts[ 2 ..] , // tx_signers
3083+ maybe_multisig_is_initialised,
3084+ result. clone ( ) ,
3085+ ) ?;
3086+
3087+ if instruction_data[ 1 ] != 1 || instruction_data. len ( ) < 34 {
3088+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 12 ) ) ) ;
30753089 return result;
3076- } else if instruction_data[ 0 ] == 2 {
3077- // AccountOwner
3090+ }
30783091
3079- // Validate Owner
3080- inner_test_validate_owner (
3081- & src_owner, // expected_owner
3082- & accounts[ 1 ] , // owner_account_info
3083- & accounts[ 2 ..] , // tx_signers
3084- maybe_multisig_is_initialised,
3085- result. clone ( ) ,
3086- ) ?;
3092+ assert_eq ! ( get_account( & accounts[ 0 ] ) . owner, instruction_data[ 2 ..34 ] ) ;
3093+ assert_eq ! ( get_account( & accounts[ 0 ] ) . delegate( ) , None ) ;
3094+ assert_eq ! ( get_account( & accounts[ 0 ] ) . delegated_amount( ) , 0 ) ;
3095+ if get_account ( & accounts[ 0 ] ) . is_native ( ) {
3096+ assert_eq ! ( get_account( & accounts[ 0 ] ) . close_authority( ) , None ) ;
3097+ }
3098+ assert ! ( result. is_ok( ) )
3099+ } else {
3100+ // CloseAccount
3101+ assert_eq ! ( instruction_data[ 0 ] , 3 ) ; // If not AccountOwner (2), must be CloseAccount (3)
30873102
3088- if instruction_data[ 1 ] != 1 || instruction_data. len ( ) < 34 {
3089- assert_eq ! ( result, Err ( ProgramError :: Custom ( 12 ) ) ) ;
3090- return result;
3091- }
3103+ // Validate Owner
3104+ inner_test_validate_owner (
3105+ & authority, // expected_owner
3106+ & accounts[ 1 ] , // owner_account_info
3107+ & accounts[ 2 ..] , // tx_signers
3108+ maybe_multisig_is_initialised,
3109+ result. clone ( ) ,
3110+ ) ?;
30923111
3093- assert_eq ! ( get_account( & accounts[ 0 ] ) . owner, instruction_data[ 2 ..34 ] ) ;
3094- assert_eq ! ( get_account( & accounts[ 0 ] ) . delegate( ) , None ) ;
3095- assert_eq ! ( get_account( & accounts[ 0 ] ) . delegated_amount( ) , 0 ) ;
3096- if get_account ( & accounts[ 0 ] ) . is_native ( ) {
3097- assert_eq ! ( get_account( & accounts[ 0 ] ) . close_authority( ) , None ) ;
3098- }
3099- assert ! ( result. is_ok( ) )
3112+ if instruction_data[ 1 ] == 1 {
3113+ // 1 ==> 34 <= instruction_data.len()
3114+ assert_eq ! (
3115+ get_account( & accounts[ 0 ] ) . close_authority( ) . unwrap( ) ,
3116+ & instruction_data[ 2 ..34 ]
3117+ ) ;
31003118 } else {
3101- // Close Account
3102-
3103- // Validate Owner
3104- inner_test_validate_owner (
3105- & authority, // expected_owner
3106- & accounts[ 1 ] , // owner_account_info
3107- & accounts[ 2 ..] , // tx_signers
3108- maybe_multisig_is_initialised,
3109- result. clone ( ) ,
3110- ) ?;
3111-
3112- if instruction_data[ 1 ] == 1 {
3113- // 1 ==> 34 <= instruction_data.len()
3114- assert_eq ! (
3115- get_account( & accounts[ 0 ] ) . close_authority( ) . unwrap( ) ,
3116- & instruction_data[ 2 ..34 ]
3117- ) ;
3118- } else {
3119- assert_eq ! ( get_account( & accounts[ 0 ] ) . close_authority( ) , None ) ;
3120- }
3121- assert ! ( result. is_ok( ) )
3119+ assert_eq ! ( get_account( & accounts[ 0 ] ) . close_authority( ) , None ) ;
31223120 }
3121+ assert ! ( result. is_ok( ) )
31233122 }
3123+ } else {
3124+ unreachable ! ( ) // account_data_len == Account::LEN must hold
31243125 }
31253126
31263127 result
@@ -3288,8 +3289,8 @@ fn test_process_set_authority_mint(
32883289 } else if mint_data_len != Account :: LEN && mint_data_len != Mint :: LEN {
32893290 assert_eq ! ( result, Err ( ProgramError :: InvalidArgument ) ) ;
32903291 return result;
3291- } else {
3292- assert_eq ! ( mint_data_len , Mint :: LEN ) ; // established by cheatcode_is_mint
3292+ } else if mint_data_len == Mint :: LEN {
3293+ // established by cheatcode_is_mint
32933294 if !mint_is_initialised. unwrap ( ) {
32943295 assert_eq ! ( result, Err ( ProgramError :: UninitializedAccount ) ) ;
32953296 return result;
@@ -3325,6 +3326,7 @@ fn test_process_set_authority_mint(
33253326 assert ! ( result. is_ok( ) )
33263327 } else {
33273328 // FreezeAccount
3329+ assert_eq ! ( instruction_data[ 0 ] , 1 ) ; // If not MintTokens (0), must be FreezeAccount (1)
33283330 if old_freeze_authority_is_none {
33293331 assert_eq ! ( result, Err ( ProgramError :: Custom ( 16 ) ) ) ;
33303332 return result;
@@ -3350,6 +3352,8 @@ fn test_process_set_authority_mint(
33503352 }
33513353 assert ! ( result. is_ok( ) )
33523354 }
3355+ } else {
3356+ unreachable ! ( ) ; // mint_data_len == Mint::LEN must hold
33533357 }
33543358
33553359 result
0 commit comments