-
Notifications
You must be signed in to change notification settings - Fork 38
feat: add unit tests to cover code changes introduced in v2.0.4 #511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: add unit tests to cover code changes introduced in v2.0.4 #511
Conversation
joncinque
left a comment
There was a problem hiding this 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
| // 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); |
There was a problem hiding this comment.
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
| // 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(), | ||
| ); |
There was a problem hiding this comment.
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?
| println!( | ||
| "Validator stake after decrease: {} lamports", | ||
| validator_stake_account_after_decrease.lamports | ||
| ); | ||
| println!( | ||
| "Transient stake after decrease: {} lamports", | ||
| transient_stake_account_after_decrease.lamports | ||
| ); |
There was a problem hiding this comment.
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
|
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? |
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:
DeactivatingAlland triggers deactivation of both stake accounts. This ensures the pool handles stake transitions safely when a validator is removed.Decrease stake error handling:
ValidatorNotFounderror, covering all relevant decrease instruction types. This guards against unauthorized stake changes after validator removal.