Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit e0dd05f

Browse files
authored
stake-pool: Add test for removing all validators from huge pool (#3806)
1 parent 135cbdf commit e0dd05f

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

stake-pool/program/tests/helpers/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,7 @@ pub fn add_vote_account(program_test: &mut ProgramTest) -> Pubkey {
17061706
vote_pubkey
17071707
}
17081708

1709+
#[allow(clippy::too_many_arguments)]
17091710
pub fn add_validator_stake_account(
17101711
program_test: &mut ProgramTest,
17111712
stake_pool: &mut state::StakePool,
@@ -1714,6 +1715,7 @@ pub fn add_validator_stake_account(
17141715
withdraw_authority: &Pubkey,
17151716
voter_pubkey: &Pubkey,
17161717
stake_amount: u64,
1718+
status: state::StakeStatus,
17171719
) {
17181720
let meta = stake::state::Meta {
17191721
rent_exempt_reserve: STAKE_ACCOUNT_RENT_EXEMPTION,
@@ -1756,7 +1758,7 @@ pub fn add_validator_stake_account(
17561758
let active_stake_lamports = stake_amount - LAMPORTS_PER_SOL;
17571759

17581760
validator_list.validators.push(state::ValidatorStakeInfo {
1759-
status: state::StakeStatus::Active,
1761+
status,
17601762
vote_account_address: *voter_pubkey,
17611763
active_stake_lamports,
17621764
transient_stake_lamports: 0,

stake-pool/program/tests/huge_pool.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ async fn setup(
5757
&stake_pool_accounts.withdraw_authority,
5858
vote_account_address,
5959
stake_amount,
60+
StakeStatus::Active,
6061
);
6162
}
6263

@@ -578,3 +579,62 @@ async fn withdraw() {
578579
.await;
579580
assert!(error.is_none(), "{:?}", error);
580581
}
582+
583+
#[tokio::test]
584+
async fn cleanup_all() {
585+
let mut program_test = program_test();
586+
let mut vote_account_pubkeys = vec![];
587+
let mut stake_pool_accounts = StakePoolAccounts::new();
588+
let max_validators = HUGE_POOL_SIZE;
589+
stake_pool_accounts.max_validators = max_validators;
590+
591+
let stake_pool_pubkey = stake_pool_accounts.stake_pool.pubkey();
592+
let (mut stake_pool, mut validator_list) = stake_pool_accounts.state();
593+
594+
for _ in 0..max_validators {
595+
vote_account_pubkeys.push(add_vote_account(&mut program_test));
596+
}
597+
598+
for vote_account_address in vote_account_pubkeys.iter() {
599+
add_validator_stake_account(
600+
&mut program_test,
601+
&mut stake_pool,
602+
&mut validator_list,
603+
&stake_pool_pubkey,
604+
&stake_pool_accounts.withdraw_authority,
605+
vote_account_address,
606+
STAKE_AMOUNT,
607+
StakeStatus::ReadyForRemoval,
608+
);
609+
}
610+
611+
add_stake_pool_account(
612+
&mut program_test,
613+
&stake_pool_accounts.stake_pool.pubkey(),
614+
&stake_pool,
615+
);
616+
add_validator_list_account(
617+
&mut program_test,
618+
&stake_pool_accounts.validator_list.pubkey(),
619+
&validator_list,
620+
max_validators,
621+
);
622+
let mut context = program_test.start_with_context().await;
623+
624+
let transaction = Transaction::new_signed_with_payer(
625+
&[instruction::cleanup_removed_validator_entries(
626+
&id(),
627+
&stake_pool_accounts.stake_pool.pubkey(),
628+
&stake_pool_accounts.validator_list.pubkey(),
629+
)],
630+
Some(&context.payer.pubkey()),
631+
&[&context.payer],
632+
context.last_blockhash,
633+
);
634+
let error = context
635+
.banks_client
636+
.process_transaction(transaction)
637+
.await
638+
.err();
639+
assert!(error.is_none());
640+
}

0 commit comments

Comments
 (0)