@@ -72,6 +72,46 @@ async fn setup(
7272 )
7373}
7474
75+ // Setup function that returns ProgramTestContext for tests that need epoch warping
76+ async fn setup_with_context (
77+ num_validators : u64 ,
78+ ) -> ( ProgramTestContext , StakePoolAccounts , ValidatorStakeAccount ) {
79+ let mut context = program_test ( ) . start_with_context ( ) . await ;
80+ let rent = context. banks_client . get_rent ( ) . await . unwrap ( ) ;
81+ let stake_rent = rent. minimum_balance ( std:: mem:: size_of :: < stake:: state:: StakeStateV2 > ( ) ) ;
82+ let current_minimum_delegation = stake_pool_get_minimum_delegation (
83+ & mut context. banks_client ,
84+ & context. payer ,
85+ & context. last_blockhash ,
86+ )
87+ . await ;
88+ let minimum_for_validator = stake_rent + current_minimum_delegation;
89+
90+ let stake_pool_accounts = StakePoolAccounts :: default ( ) ;
91+ stake_pool_accounts
92+ . initialize_stake_pool (
93+ & mut context. banks_client ,
94+ & context. payer ,
95+ & context. last_blockhash ,
96+ MINIMUM_RESERVE_LAMPORTS + num_validators * minimum_for_validator,
97+ )
98+ . await
99+ . unwrap ( ) ;
100+
101+ let validator_stake =
102+ ValidatorStakeAccount :: new ( & stake_pool_accounts. stake_pool . pubkey ( ) , None , 0 ) ;
103+ create_vote (
104+ & mut context. banks_client ,
105+ & context. payer ,
106+ & context. last_blockhash ,
107+ & validator_stake. validator ,
108+ & validator_stake. vote ,
109+ )
110+ . await ;
111+
112+ ( context, stake_pool_accounts, validator_stake)
113+ }
114+
75115#[ tokio:: test]
76116async fn success ( ) {
77117 let ( mut banks_client, payer, recent_blockhash, stake_pool_accounts, validator_stake) =
@@ -501,10 +541,66 @@ async fn fail_add_too_many_validator_stake_accounts() {
501541}
502542
503543#[ tokio:: test]
504- async fn fail_with_unupdated_stake_pool ( ) { } // TODO
544+ async fn fail_with_not_updated_stake_pool ( ) {
545+ let ( mut context, stake_pool_accounts, validator_stake) = setup_with_context ( 1 ) . await ;
546+
547+ // Move to next epoch
548+ let first_normal_slot = context. genesis_config ( ) . epoch_schedule . first_normal_slot ;
549+ let slots_per_epoch = context. genesis_config ( ) . epoch_schedule . slots_per_epoch ;
550+ let slot = first_normal_slot + slots_per_epoch + 1 ;
551+ context. warp_to_slot ( slot) . unwrap ( ) ;
552+
553+ // Do not update stake pool
554+
555+ let transaction_error = stake_pool_accounts
556+ . add_validator_to_pool (
557+ & mut context. banks_client ,
558+ & context. payer ,
559+ & context. last_blockhash ,
560+ & validator_stake. stake_account ,
561+ & validator_stake. vote . pubkey ( ) ,
562+ validator_stake. validator_stake_seed ,
563+ )
564+ . await ;
565+ let transaction_error = transaction_error. unwrap ( ) ;
566+ let program_error = StakePoolError :: StakeListAndPoolOutOfDate as u32 ;
567+ match transaction_error {
568+ TransportError :: TransactionError ( TransactionError :: InstructionError ( _, error) ) => {
569+ assert_eq ! ( error, InstructionError :: Custom ( program_error) ) ;
570+ }
571+ _ => panic ! ( "Wrong error occurs while trying to add validator to outdated stake pool" ) ,
572+ }
573+ }
505574
506575#[ tokio:: test]
507- async fn fail_with_uninitialized_validator_list_account ( ) { } // TODO
576+ async fn fail_with_uninitialized_validator_list_account ( ) {
577+ let ( mut context, stake_pool_accounts, validator_stake) = setup_with_context ( 1 ) . await ;
578+
579+ // Set the validator list to an uninitialized account
580+ set_validator_list_to_uninitialized_account ( & mut context, & stake_pool_accounts) . await ;
581+
582+ // Attempt to add validator to pool with uninitialized validator list
583+ let transaction_error = stake_pool_accounts
584+ . add_validator_to_pool (
585+ & mut context. banks_client ,
586+ & context. payer ,
587+ & context. last_blockhash ,
588+ & validator_stake. stake_account ,
589+ & validator_stake. vote . pubkey ( ) ,
590+ validator_stake. validator_stake_seed ,
591+ )
592+ . await ;
593+ let transaction_error = transaction_error. unwrap ( ) ;
594+ let program_error = StakePoolError :: InvalidState as u32 ;
595+ match transaction_error {
596+ TransportError :: TransactionError ( TransactionError :: InstructionError ( _, error) ) => {
597+ assert_eq ! ( error, InstructionError :: Custom ( program_error) ) ;
598+ }
599+ _ => panic ! (
600+ "Wrong error occurs while trying to add validator with uninitialized validator list"
601+ ) ,
602+ }
603+ }
508604
509605#[ tokio:: test]
510606async fn fail_on_non_vote_account ( ) {
0 commit comments