Skip to content

Conversation

@juliaaschmidt
Copy link
Contributor

@juliaaschmidt juliaaschmidt commented Dec 15, 2025

Closes #527

This pull request adds new tests to improve coverage of validator removal scenarios in the stake pool program. The tests ensure correct handling when removing validators, particularly those with transient stake, and verify that stake decrease operations fail as expected after removal.

Validator removal and stake deactivation logic:

  • Added a test to verify that removing a validator with both active and transient stake correctly updates the validator's status to DeactivatingAll and triggers deactivation of both stake accounts. This ensures the pool handles stake transitions safely when a validator is removed.

Decrease stake error handling:

  • Added parameterized tests to confirm that attempting to decrease stake on a validator marked for removal fails with a ValidatorNotFound error, covering all relevant decrease instruction types. This guards against unauthorized stake changes after validator removal.

Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall! Just some small questions

Comment on lines +972 to +982
// Update the validator list to register the transient stake
let error = stake_pool_accounts
.update_validator_list_balance(
&mut context.banks_client,
&context.payer,
&context.last_blockhash,
1,
true, // no_merge = true to keep transient stake separate
)
.await;
assert!(error.is_none(), "{:?}", error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step shouldn't be needed -- the transient stake is registered during increase

Comment on lines +1227 to +1245
// Now manually modify the first validator to have some remaining active lamports
let mut modified_validator_list = updated_validator_list.clone();
modified_validator_list.validators[0].active_stake_lamports = PodU64::from(1_000_000u64); // 1 SOL remaining
modified_validator_list.validators[0].transient_stake_lamports = PodU64::from(0u64); // No transient stake
let validator_list_account = context
.banks_client
.get_account(stake_pool_accounts.validator_list.pubkey())
.await
.unwrap()
.unwrap();
let mut modified_account = validator_list_account.clone();

let mut serialized_data = borsh::to_vec(&modified_validator_list).unwrap();
serialized_data.resize(modified_account.data.len(), 0);
modified_account.data = serialized_data;
context.set_account(
&stake_pool_accounts.validator_list.pubkey(),
&modified_account.into(),
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I'm being dense here, but how would this be possible? If the active lamports number gets increased, then some stake needs to get merged into the account, no?

Comment on lines +58 to +65
println!(
"Validator stake after decrease: {} lamports",
validator_stake_account_after_decrease.lamports
);
println!(
"Transient stake after decrease: {} lamports",
transient_stake_account_after_decrease.lamports
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we remove all the prints in this PR? We don't typically have prints in the tests and prefer asserts do the job, so they can print in case something goes wrong

@joncinque
Copy link
Contributor

Also, I'm not totally sure why, but CI hasn't run on the PR -- can you try rebasing to see if that kicks it off?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Increase Test Coverage for Stake Pool Logic Changes in v2.0.4

2 participants