Skip to content

Commit

Permalink
[program-test] adding method warp_to_epoch (#34620)
Browse files Browse the repository at this point in the history
* [program-test] adding method warp_to_epoch

* formatting fix
  • Loading branch information
ochaloup authored Jan 3, 2024
1 parent 431fd91 commit 8330dee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 9 additions & 1 deletion program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use {
solana_sdk::{
account::{create_account_shared_data_for_test, Account, AccountSharedData},
account_info::AccountInfo,
clock::Slot,
clock::{Epoch, Slot},
entrypoint::{deserialize, ProgramResult, SUCCESS},
feature_set::FEATURE_NAMES,
fee_calculator::{FeeCalculator, FeeRateGovernor, DEFAULT_TARGET_LAMPORTS_PER_SIGNATURE},
Expand Down Expand Up @@ -1207,6 +1207,14 @@ impl ProgramTestContext {
Ok(())
}

pub fn warp_to_epoch(&mut self, warp_epoch: Epoch) -> Result<(), ProgramTestError> {
let warp_slot = self
.genesis_config
.epoch_schedule
.get_first_slot_in_epoch(warp_epoch);
self.warp_to_slot(warp_slot)
}

/// warp forward one more slot and force reward interval end
pub fn warp_forward_force_reward_interval_end(&mut self) -> Result<(), ProgramTestError> {
let mut bank_forks = self.bank_forks.write().unwrap();
Expand Down
9 changes: 8 additions & 1 deletion program-test/tests/warp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,15 @@ async fn stake_merge_immediately_after_activation() {
check_credits_observed(&mut context.banks_client, base_stake_address, 100).await;
context.increment_vote_account_credits(&vote_address, 100);

let clock_account = context
.banks_client
.get_account(clock::id())
.await
.expect("account exists")
.unwrap();
let clock: Clock = deserialize(&clock_account.data).unwrap();
context.warp_to_epoch(clock.epoch + 1).unwrap();
current_slot += slots_per_epoch;
context.warp_to_slot(current_slot).unwrap();
context.warp_forward_force_reward_interval_end().unwrap();

// make another stake which will just have its credits observed advanced
Expand Down

0 comments on commit 8330dee

Please sign in to comment.