allow stake tests to wait for rewards payout (#31821)

This commit is contained in:
Jeff Washington (jwash) 2023-05-30 08:56:02 -05:00 committed by GitHub
parent db8f118ec6
commit 03b260a29f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

View File

@ -39,15 +39,23 @@ pub fn check_ready(rpc_client: &RpcClient) {
}
}
pub fn wait_for_next_epoch(rpc_client: &RpcClient) -> Epoch {
pub fn wait_for_next_epoch_plus_n_slots(rpc_client: &RpcClient, n: u64) -> (Epoch, u64) {
let current_epoch = rpc_client.get_epoch_info().unwrap().epoch;
println!("waiting for epoch {}", current_epoch + 1);
let next_epoch = current_epoch + 1;
println!("waiting for epoch {next_epoch} plus {n} slots");
loop {
sleep(Duration::from_millis(DEFAULT_MS_PER_SLOT));
let next_epoch = rpc_client.get_epoch_info().unwrap().epoch;
if next_epoch > current_epoch {
return next_epoch;
let slot = rpc_client.get_slot().unwrap();
loop {
sleep(Duration::from_millis(DEFAULT_MS_PER_SLOT));
let new_slot = rpc_client.get_slot().unwrap();
if new_slot - slot > n {
return (next_epoch, new_slot);
}
}
}
}
}

View File

@ -6,7 +6,7 @@ use {
cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig},
spend_utils::SpendAmount,
stake::StakeAuthorizationIndexed,
test_utils::{check_ready, wait_for_next_epoch},
test_utils::{check_ready, wait_for_next_epoch_plus_n_slots},
},
solana_cli_output::{parse_sign_only_reply_string, OutputFormat},
solana_faucet::faucet::run_local_faucet,
@ -158,7 +158,7 @@ fn test_stake_redelegation() {
process_command(&config).unwrap();
// wait for new epoch
wait_for_next_epoch(&rpc_client);
wait_for_next_epoch_plus_n_slots(&rpc_client, 0);
// `stake_keypair` should now be delegated to `vote_keypair` and fully activated
let stake_account = rpc_client.get_account(&stake_keypair.pubkey()).unwrap();
@ -200,7 +200,7 @@ fn test_stake_redelegation() {
// wait for a new epoch to ensure the `Redelegate` happens as soon as possible in the epoch
// to reduce the risk of a race condition when checking the stake account correctly enters the
// deactivating state for the remainder of the current epoch
wait_for_next_epoch(&rpc_client);
wait_for_next_epoch_plus_n_slots(&rpc_client, 0);
// Redelegate to `vote2_keypair` via `stake2_keypair
config.signers = vec![&default_signer, &stake2_keypair];
@ -251,7 +251,7 @@ fn test_stake_redelegation() {
check_balance!(50_000_000_000, &rpc_client, &stake2_keypair.pubkey());
// wait for new epoch
wait_for_next_epoch(&rpc_client);
wait_for_next_epoch_plus_n_slots(&rpc_client, 0);
// `stake_keypair` should now be deactivated
assert_eq!(