stake tests modification: next_epoch_and_n_slots (#32052)

stake tests modification: next_epoch_and_n_slots
This commit is contained in:
Jeff Washington (jwash) 2023-06-11 14:26:16 -05:00 committed by GitHub
parent 129b457c99
commit 2572df7452
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 8 deletions

29
runtime/tests/stake.rs Normal file → Executable file
View File

@ -29,14 +29,26 @@ use {
std::sync::Arc,
};
fn next_epoch(bank: &Arc<Bank>) -> Arc<Bank> {
/// get bank at next epoch + `n` slots
fn next_epoch_and_n_slots(bank: &Arc<Bank>, mut n: usize) -> Arc<Bank> {
bank.squash();
Arc::new(Bank::new_from_parent(
let mut bank = Arc::new(Bank::new_from_parent(
bank,
&Pubkey::default(),
bank.get_slots_in_epoch(bank.epoch()) + bank.slot(),
))
));
while n > 0 {
bank.squash();
bank = Arc::new(Bank::new_from_parent(
&bank,
&Pubkey::default(),
1 + bank.slot(),
));
n -= 1;
}
bank
}
fn fill_epoch_with_votes(
@ -385,7 +397,7 @@ fn test_stake_account_lifetime() {
break;
}
// Cycle thru banks until we're fully warmed up
bank = next_epoch(&bank);
bank = next_epoch_and_n_slots(&bank, 0);
}
// Reward redemption
@ -409,7 +421,7 @@ fn test_stake_account_lifetime() {
let pre_balance = bank.get_balance(&stake_pubkey);
// next epoch bank should pay rewards
bank = next_epoch(&bank);
bank = next_epoch_and_n_slots(&bank, 0);
// Test that balance increased, and that the balance got staked
let staked = get_staked(&bank, &stake_pubkey);
@ -477,7 +489,8 @@ fn test_stake_account_lifetime() {
.send_and_confirm_message(&[&mint_keypair, &stake_keypair], message)
.is_err());
let mut bank = next_epoch(&bank);
let mut bank = next_epoch_and_n_slots(&bank, 0);
let bank_client = BankClient::new_shared(&bank);
// assert we're still cooling down
@ -522,7 +535,7 @@ fn test_stake_account_lifetime() {
if get_staked(&bank, &split_stake_pubkey) == 0 {
break;
}
bank = next_epoch(&bank);
bank = next_epoch_and_n_slots(&bank, 0);
}
let bank_client = BankClient::new_shared(&bank);