Skip to content

Commit 8c1cf88

Browse files
committed
wip
1 parent 8f705b3 commit 8c1cf88

File tree

7 files changed

+54
-4
lines changed

7 files changed

+54
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

program/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ thiserror = "2.0"
3434
bincode = "1.3.1"
3535

3636
[dev-dependencies]
37+
agave-feature-set = "2.3.4"
3738
assert_matches = "1.5.0"
3839
proptest = "1.7"
3940
solana-program-test = "2.3.4"

program/tests/deposit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ use {
99
borsh1::try_from_slice_unchecked,
1010
instruction::{AccountMeta, Instruction, InstructionError},
1111
pubkey::Pubkey,
12-
sysvar,
1312
},
1413
solana_program_test::*,
1514
solana_sdk::{
1615
signature::{Keypair, Signer},
16+
sysvar,
1717
transaction::{Transaction, TransactionError},
1818
transport::TransportError,
1919
},
@@ -89,6 +89,7 @@ async fn setup(
8989

9090
let first_normal_slot = context.genesis_config().epoch_schedule.first_normal_slot;
9191
context.warp_to_slot(first_normal_slot + 1).unwrap();
92+
fix_stake_history(&mut context).await;
9293
stake_pool_accounts
9394
.update_all(
9495
&mut context.banks_client,

program/tests/deposit_edge_cases.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ async fn setup(
8383

8484
let first_normal_slot = context.genesis_config().epoch_schedule.first_normal_slot;
8585
context.warp_to_slot(first_normal_slot + 1).unwrap();
86+
fix_stake_history(&mut context).await;
8687
stake_pool_accounts
8788
.update_all(
8889
&mut context.banks_client,
227 KB
Binary file not shown.

program/tests/helpers/mod.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![allow(dead_code)]
22

33
use {
4+
agave_feature_set::stake_raise_minimum_delegation_to_1_sol,
45
borsh::BorshDeserialize,
56
solana_program::{
67
borsh1::{get_instance_packed_len, get_packed_len, try_from_slice_unchecked},
@@ -12,10 +13,11 @@ use {
1213
},
1314
solana_program_test::{processor, BanksClient, ProgramTest, ProgramTestContext},
1415
solana_sdk::{
15-
account::{Account as SolanaAccount, WritableAccount},
16+
account::{Account as SolanaAccount, AccountSharedData, ReadableAccount, WritableAccount},
1617
clock::{Clock, Epoch},
1718
compute_budget::ComputeBudgetInstruction,
1819
signature::{Keypair, Signer},
20+
sysvar::{stake_history::StakeHistory, SysvarId},
1921
transaction::Transaction,
2022
transport::TransportError,
2123
},
@@ -53,6 +55,8 @@ const ACCOUNT_RENT_EXEMPTION: u64 = 1_000_000_000; // go with something big to b
5355

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

90+
pub async fn fix_stake_history(context: &mut ProgramTestContext) {
91+
let clock = bincode::deserialize::<Clock>(
92+
get_account(&mut context.banks_client, &Clock::id())
93+
.await
94+
.data(),
95+
)
96+
.unwrap();
97+
98+
let stake_history_account = get_account(&mut context.banks_client, &StakeHistory::id()).await;
99+
100+
let mut stake_history =
101+
bincode::deserialize::<StakeHistory>(&stake_history_account.data()).unwrap();
102+
103+
let mut stake_history_entry = stake_history.get(0).cloned().unwrap_or_default();
104+
stake_history_entry.effective +=
105+
stake_history_entry.activating - stake_history_entry.deactivating;
106+
stake_history_entry.activating = 0;
107+
stake_history_entry.deactivating = 0;
108+
109+
for epoch in 1..clock.epoch {
110+
stake_history.add(epoch, stake_history_entry.clone());
111+
}
112+
113+
let stake_history_account = AccountSharedData::create(
114+
stake_history_account.lamports(),
115+
bincode::serialize(&stake_history).unwrap(),
116+
*stake_history_account.owner(),
117+
false,
118+
u64::MAX,
119+
);
120+
121+
context.set_account(&StakeHistory::id(), &stake_history_account);
122+
context.warp_to_slot(clock.slot + 1).unwrap();
123+
}
124+
86125
#[allow(clippy::too_many_arguments)]
87126
pub async fn create_mint(
88127
banks_client: &mut BanksClient,

program/tests/huge_pool.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,13 @@ async fn add_validator_to_pool(max_validators: u32) {
451451
let (mut context, stake_pool_accounts, _, test_vote_address, _, _, _) =
452452
setup(max_validators, max_validators - 1, STAKE_AMOUNT).await;
453453

454+
let minimum_delegation = stake_pool_get_minimum_delegation(
455+
&mut context.banks_client,
456+
&context.payer,
457+
&context.last_blockhash,
458+
)
459+
.await;
460+
454461
let last_index = max_validators as usize - 1;
455462
let stake_pool_pubkey = stake_pool_accounts.stake_pool.pubkey();
456463
let (stake_address, _) =
@@ -480,7 +487,7 @@ async fn add_validator_to_pool(max_validators: u32) {
480487
assert_eq!(last_element.status, StakeStatus::Active.into());
481488
assert_eq!(
482489
u64::from(last_element.active_stake_lamports),
483-
LAMPORTS_PER_SOL + STAKE_ACCOUNT_RENT_EXEMPTION
490+
minimum_delegation + STAKE_ACCOUNT_RENT_EXEMPTION
484491
);
485492
assert_eq!(u64::from(last_element.transient_stake_lamports), 0);
486493
assert_eq!(last_element.vote_account_address, test_vote_address);
@@ -518,7 +525,7 @@ async fn add_validator_to_pool(max_validators: u32) {
518525
assert_eq!(last_element.status, StakeStatus::Active.into());
519526
assert_eq!(
520527
u64::from(last_element.active_stake_lamports),
521-
LAMPORTS_PER_SOL + STAKE_ACCOUNT_RENT_EXEMPTION
528+
minimum_delegation + STAKE_ACCOUNT_RENT_EXEMPTION
522529
);
523530
assert_eq!(
524531
u64::from(last_element.transient_stake_lamports),

0 commit comments

Comments
 (0)