diff --git a/tests/src/steward_fixtures.rs b/tests/src/steward_fixtures.rs index bc376121..bea989ea 100644 --- a/tests/src/steward_fixtures.rs +++ b/tests/src/steward_fixtures.rs @@ -15,6 +15,7 @@ use jito_steward::{ bitmask::BitMask, constants::{MAX_VALIDATORS, SORTED_INDEX_DEFAULT, STAKE_POOL_WITHDRAW_SEED}, utils::StakePool, + utils::ValidatorList, Config, Delegation, LargeBitMask, Parameters, StewardState, StewardStateAccount, StewardStateEnum, UpdateParametersArgs, STATE_PADDING_0_SIZE, }; @@ -25,8 +26,8 @@ use solana_sdk::{ stake::state::StakeStateV2, transaction::Transaction, }; use spl_stake_pool::{ - find_stake_program_address, find_transient_stake_program_address, - state::{Fee, StakeStatus, ValidatorList, ValidatorStakeInfo}, + find_stake_program_address, find_transient_stake_program_address, minimum_delegation, + state::{Fee, StakeStatus, ValidatorList as SPLValidatorList, ValidatorStakeInfo}, }; use validator_history::{ self, constants::MAX_ALLOC_BYTES, CircBuf, CircBufCluster, ClusterHistory, ClusterHistoryEntry, @@ -364,6 +365,39 @@ impl TestFixture { self.submit_transaction_assert_success(transaction).await; } + pub async fn initialize_validator_list(&self, num_validators: usize) { + let stake_program_minimum = self.fetch_minimum_delegation().await; + let pool_minimum_delegation = minimum_delegation(stake_program_minimum); + let stake_rent = self.fetch_stake_rent().await; + let minimum_active_stake_with_rent = pool_minimum_delegation + stake_rent; + + let validator_list_account_info = + self.get_account(&self.stake_pool_meta.validator_list).await; + + let validator_list: ValidatorList = self + .load_and_deserialize(&self.stake_pool_meta.validator_list) + .await; + + let mut spl_validator_list = validator_list.as_ref().clone(); + + for _ in 0..num_validators { + spl_validator_list.validators.push(ValidatorStakeInfo { + active_stake_lamports: minimum_active_stake_with_rent.into(), + vote_account_address: Pubkey::new_unique(), + ..ValidatorStakeInfo::default() + }); + } + + self.ctx.borrow_mut().set_account( + &self.stake_pool_meta.validator_list, + &serialized_validator_list_account( + spl_validator_list.clone(), + Some(validator_list_account_info.data.len()), + ) + .into(), + ); + } + // Turn this into a fixture creator pub async fn initialize_cluster_history_account(&self) -> ClusterHistory { todo!() @@ -622,7 +656,7 @@ pub fn closed_vote_account() -> Account { // TODO write a function to serialize any account with T: AnchorSerialize pub fn serialized_validator_list_account( - validator_list: ValidatorList, + validator_list: SPLValidatorList, account_size: Option, ) -> Account { // Passes in size because zeros at the end will be truncated during serialization diff --git a/tests/tests/steward/test_integration.rs b/tests/tests/steward/test_integration.rs index 7cbb7d5a..5919214b 100644 --- a/tests/tests/steward/test_integration.rs +++ b/tests/tests/steward/test_integration.rs @@ -38,6 +38,7 @@ async fn test_compute_delegations() { fixture.initialize_stake_pool().await; fixture.initialize_steward(None).await; fixture.realloc_steward_state().await; + fixture.initialize_validator_list(MAX_VALIDATORS).await; let clock: Clock = fixture.get_sysvar().await; @@ -115,6 +116,7 @@ async fn test_compute_delegations() { &[&fixture.keypair], ctx.borrow().last_blockhash, ); + fixture.submit_transaction_assert_success(tx).await; let steward_state_account: StewardStateAccount = @@ -722,6 +724,8 @@ async fn test_idle() { steward_state_account.state.current_epoch = epoch_schedule.first_normal_epoch; steward_state_account.state.num_pool_validators = MAX_VALIDATORS as u64; + fixture.initialize_validator_list(MAX_VALIDATORS).await; + ctx.borrow_mut().set_account( &fixture.steward_state, &serialized_steward_state_account(steward_state_account).into(), @@ -749,6 +753,20 @@ async fn test_idle() { ctx.borrow().last_blockhash, ); + let steward_state_account: StewardStateAccount = + fixture.load_and_deserialize(&fixture.steward_state).await; + + let validator_list: ValidatorList = fixture + .load_and_deserialize(&fixture.stake_pool_meta.validator_list) + .await; + + println!("{:?}", validator_list.validators.len()); + println!( + "{:?}", + steward_state_account.state.num_pool_validators + + steward_state_account.state.validators_added as u64 + ); + fixture.submit_transaction_assert_success(tx).await; let mut steward_state_account: StewardStateAccount = @@ -1023,6 +1041,17 @@ async fn test_rebalance_increase() { fixture.submit_transaction_assert_success(tx).await; + let mut steward_state_account: StewardStateAccount = + fixture.load_and_deserialize(&fixture.steward_state).await; + + // Force validator into the active set, don't wait for next cycle + steward_state_account.state.num_pool_validators += 1; + steward_state_account.state.validators_added -= 1; + ctx.borrow_mut().set_account( + &fixture.steward_state, + &serialized_steward_state_account(steward_state_account).into(), + ); + let reserve_before_rebalance = fixture.get_account(&fixture.stake_pool_meta.reserve).await; let tx = Transaction::new_signed_with_payer( @@ -1231,6 +1260,17 @@ async fn test_rebalance_decrease() { ); fixture.submit_transaction_assert_success(tx).await; + let mut steward_state_account: StewardStateAccount = + fixture.load_and_deserialize(&fixture.steward_state).await; + + // Force validator into the active set, don't wait for next cycle + steward_state_account.state.num_pool_validators += 1; + steward_state_account.state.validators_added -= 1; + ctx.borrow_mut().set_account( + &fixture.steward_state, + &serialized_steward_state_account(steward_state_account).into(), + ); + // Simulating stake deposit let stake_account_data = fixture.get_account(&stake_account_address).await; @@ -1469,6 +1509,17 @@ async fn test_rebalance_other_cases() { ); fixture.submit_transaction_assert_success(tx).await; + let mut steward_state_account: StewardStateAccount = + fixture.load_and_deserialize(&fixture.steward_state).await; + + // Force validator into the active set, don't wait for next cycle + steward_state_account.state.num_pool_validators += 1; + steward_state_account.state.validators_added -= 1; + ctx.borrow_mut().set_account( + &fixture.steward_state, + &serialized_steward_state_account(steward_state_account).into(), + ); + let rebalance_ix = Instruction { program_id: jito_steward::id(), accounts: jito_steward::accounts::Rebalance {