Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ thiserror = "2.0"
bincode = "1.3.1"

[dev-dependencies]
agave-feature-set = "2.3.4"
assert_matches = "1.5.0"
proptest = "1.7"
solana-program-test = "2.3.4"
Expand Down
3 changes: 2 additions & 1 deletion program/tests/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use {
borsh1::try_from_slice_unchecked,
instruction::{AccountMeta, Instruction, InstructionError},
pubkey::Pubkey,
sysvar,
},
solana_program_test::*,
solana_sdk::{
signature::{Keypair, Signer},
sysvar,
transaction::{Transaction, TransactionError},
transport::TransportError,
},
Expand Down Expand Up @@ -89,6 +89,7 @@ async fn setup(

let first_normal_slot = context.genesis_config().epoch_schedule.first_normal_slot;
context.warp_to_slot(first_normal_slot + 1).unwrap();
fix_stake_history(&mut context).await;
stake_pool_accounts
.update_all(
&mut context.banks_client,
Expand Down
1 change: 1 addition & 0 deletions program/tests/deposit_edge_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ async fn setup(

let first_normal_slot = context.genesis_config().epoch_schedule.first_normal_slot;
context.warp_to_slot(first_normal_slot + 1).unwrap();
fix_stake_history(&mut context).await;
stake_pool_accounts
.update_all(
&mut context.banks_client,
Expand Down
Binary file added program/tests/fixtures/solana_stake_program.so
Binary file not shown.
41 changes: 40 additions & 1 deletion program/tests/helpers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(dead_code)]

use {
agave_feature_set::stake_raise_minimum_delegation_to_1_sol,
borsh::BorshDeserialize,
solana_program::{
borsh1::{get_instance_packed_len, get_packed_len, try_from_slice_unchecked},
Expand All @@ -12,10 +13,11 @@ use {
},
solana_program_test::{processor, BanksClient, ProgramTest, ProgramTestContext},
solana_sdk::{
account::{Account as SolanaAccount, WritableAccount},
account::{Account as SolanaAccount, AccountSharedData, ReadableAccount, WritableAccount},
clock::{Clock, Epoch},
compute_budget::ComputeBudgetInstruction,
signature::{Keypair, Signer},
sysvar::{stake_history::StakeHistory, SysvarId},
transaction::Transaction,
transport::TransportError,
},
Expand Down Expand Up @@ -53,6 +55,8 @@ const ACCOUNT_RENT_EXEMPTION: u64 = 1_000_000_000; // go with something big to b

pub fn program_test() -> ProgramTest {
let mut program_test = ProgramTest::new("spl_stake_pool", id(), processor!(Processor::process));
program_test.add_upgradeable_program_to_genesis("solana_stake_program", &stake::program::id());
program_test.deactivate_feature(stake_raise_minimum_delegation_to_1_sol::id());
program_test.prefer_bpf(false);
program_test.add_program(
"spl_token_2022",
Expand Down Expand Up @@ -83,6 +87,41 @@ pub async fn get_account(banks_client: &mut BanksClient, pubkey: &Pubkey) -> Sol
.expect("account not found")
}

pub async fn fix_stake_history(context: &mut ProgramTestContext) {
let clock = bincode::deserialize::<Clock>(
get_account(&mut context.banks_client, &Clock::id())
.await
.data(),
)
.unwrap();

let stake_history_account = get_account(&mut context.banks_client, &StakeHistory::id()).await;

let mut stake_history =
bincode::deserialize::<StakeHistory>(stake_history_account.data()).unwrap();

let mut stake_history_entry = stake_history.get(0).cloned().unwrap_or_default();
stake_history_entry.effective +=
stake_history_entry.activating - stake_history_entry.deactivating;
stake_history_entry.activating = 0;
stake_history_entry.deactivating = 0;

for epoch in 1..clock.epoch {
stake_history.add(epoch, stake_history_entry.clone());
}

let stake_history_account = AccountSharedData::create(
stake_history_account.lamports(),
bincode::serialize(&stake_history).unwrap(),
*stake_history_account.owner(),
false,
u64::MAX,
);

context.set_account(&StakeHistory::id(), &stake_history_account);
context.warp_to_slot(clock.slot + 1).unwrap();
}

#[allow(clippy::too_many_arguments)]
pub async fn create_mint(
banks_client: &mut BanksClient,
Expand Down
11 changes: 9 additions & 2 deletions program/tests/huge_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,13 @@ async fn add_validator_to_pool(max_validators: u32) {
let (mut context, stake_pool_accounts, _, test_vote_address, _, _, _) =
setup(max_validators, max_validators - 1, STAKE_AMOUNT).await;

let minimum_delegation = stake_pool_get_minimum_delegation(
&mut context.banks_client,
&context.payer,
&context.last_blockhash,
)
.await;

let last_index = max_validators as usize - 1;
let stake_pool_pubkey = stake_pool_accounts.stake_pool.pubkey();
let (stake_address, _) =
Expand Down Expand Up @@ -480,7 +487,7 @@ async fn add_validator_to_pool(max_validators: u32) {
assert_eq!(last_element.status, StakeStatus::Active.into());
assert_eq!(
u64::from(last_element.active_stake_lamports),
LAMPORTS_PER_SOL + STAKE_ACCOUNT_RENT_EXEMPTION
minimum_delegation + STAKE_ACCOUNT_RENT_EXEMPTION
);
assert_eq!(u64::from(last_element.transient_stake_lamports), 0);
assert_eq!(last_element.vote_account_address, test_vote_address);
Expand Down Expand Up @@ -518,7 +525,7 @@ async fn add_validator_to_pool(max_validators: u32) {
assert_eq!(last_element.status, StakeStatus::Active.into());
assert_eq!(
u64::from(last_element.active_stake_lamports),
LAMPORTS_PER_SOL + STAKE_ACCOUNT_RENT_EXEMPTION
minimum_delegation + STAKE_ACCOUNT_RENT_EXEMPTION
);
assert_eq!(
u64::from(last_element.transient_stake_lamports),
Expand Down
Loading