Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit b9fed11

Browse files
authored
stake-pool: Add end-to-end testing using ProgramTest (#828)
* WIP: stake-pool: Add end-to-end testing using ProgramTest * Run cargo fmt * Add deposit test and extra requirements * Update Cargo.lock after rebuild * Bring token program sdk version back to 1.4.7
1 parent 5030a87 commit b9fed11

File tree

5 files changed

+475
-7
lines changed

5 files changed

+475
-7
lines changed

Cargo.lock

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stake-pool/program/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ spl-token = { path = "../../token/program", features = [ "no-entrypoint" ] }
2222
thiserror = "1.0"
2323

2424
[dev-dependencies]
25+
bincode = "1.3.1"
26+
solana-program-test = "1.4.7"
2527
solana-sdk = "1.4.7"
28+
tokio = { version = "0.3", features = ["macros"]}
2629

2730
[lib]
2831
crate-type = ["cdylib", "lib"]

stake-pool/program/src/entrypoint.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Program entrypoint
22
3+
#![cfg(all(target_arch = "bpf", not(feature = "no-entrypoint")))]
4+
35
use crate::{error::Error, processor::Processor};
46
use solana_program::{
57
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult,

stake-pool/program/src/stake.rs

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
33
use serde_derive::{Deserialize, Serialize};
44
use solana_program::{
5+
clock::{Epoch, UnixTimestamp},
56
instruction::{AccountMeta, Instruction},
67
pubkey::Pubkey,
7-
sysvar,
8+
system_instruction, sysvar,
89
};
910

1011
solana_program::declare_id!("Stake11111111111111111111111111111111111111");
@@ -21,7 +22,7 @@ pub enum StakeInstruction {
2122
/// Authorized carries pubkeys that must sign staker transactions
2223
/// and withdrawer transactions.
2324
/// Lockup carries information about withdrawal restrictions
24-
InitializeNOTUSED,
25+
Initialize(Authorized, Lockup),
2526

2627
/// Authorize a key to manage stake or withdrawal
2728
///
@@ -102,6 +103,55 @@ pub enum StakeInstruction {
102103
AuthorizeWithSeedNOTUSED,
103104
}
104105

106+
/// FIXME copied from the stake program
107+
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Copy)]
108+
#[allow(clippy::large_enum_variant)]
109+
pub enum StakeState {
110+
/// FIXME copied from the stake program
111+
Uninitialized,
112+
/// FIXME copied from the stake program
113+
Initialized(Meta),
114+
/// FIXME copied from the stake program
115+
Stake(Meta, Stake),
116+
/// FIXME copied from the stake program
117+
RewardsPool,
118+
}
119+
120+
/// FIXME copied from the stake program
121+
#[derive(Default, Debug, Serialize, Deserialize, PartialEq, Clone, Copy)]
122+
pub struct Meta {
123+
/// FIXME copied from the stake program
124+
pub rent_exempt_reserve: u64,
125+
/// FIXME copied from the stake program
126+
pub authorized: Authorized,
127+
/// FIXME copied from the stake program
128+
pub lockup: Lockup,
129+
}
130+
131+
/// FIXME copied from the stake program
132+
#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Clone, Copy)]
133+
pub struct Stake {
134+
/// FIXME copied from the stake program
135+
pub delegation: Delegation,
136+
/// credits observed is credits from vote account state when delegated or redeemed
137+
pub credits_observed: u64,
138+
}
139+
140+
/// FIXME copied from the stake program
141+
#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Clone, Copy)]
142+
pub struct Delegation {
143+
/// to whom the stake is delegated
144+
pub voter_pubkey: Pubkey,
145+
/// activated stake amount, set at delegate() time
146+
pub stake: u64,
147+
/// epoch at which this stake was activated, std::Epoch::MAX if is a bootstrap stake
148+
pub activation_epoch: Epoch,
149+
/// epoch the stake was deactivated, std::Epoch::MAX if not deactivated
150+
pub deactivation_epoch: Epoch,
151+
/// how much stake we can activate per-epoch as a fraction of currently effective stake
152+
pub warmup_cooldown_rate: f64,
153+
}
154+
105155
/// FIXME copied from the stake program
106156
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Copy)]
107157
pub enum StakeAuthorize {
@@ -110,6 +160,28 @@ pub enum StakeAuthorize {
110160
/// FIXME copied from the stake program
111161
Withdrawer,
112162
}
163+
/// FIXME copied from the stake program
164+
#[derive(Default, Debug, Serialize, Deserialize, PartialEq, Clone, Copy)]
165+
pub struct Authorized {
166+
/// FIXME copied from the stake program
167+
pub staker: Pubkey,
168+
/// FIXME copied from the stake program
169+
pub withdrawer: Pubkey,
170+
}
171+
172+
/// FIXME copied from the stake program
173+
#[derive(Default, Debug, Serialize, Deserialize, PartialEq, Clone, Copy)]
174+
pub struct Lockup {
175+
/// UnixTimestamp at which this stake will allow withdrawal, unless the
176+
/// transaction is signed by the custodian
177+
pub unix_timestamp: UnixTimestamp,
178+
/// epoch height at which this stake will allow withdrawal, unless the
179+
/// transaction is signed by the custodian
180+
pub epoch: Epoch,
181+
/// custodian signature on a transaction exempts the operation from
182+
/// lockup constraints
183+
pub custodian: Pubkey,
184+
}
113185

114186
/// FIXME copied from the stake program
115187
pub fn split_only(
@@ -163,3 +235,35 @@ pub fn merge(
163235

164236
Instruction::new(id(), &StakeInstruction::Merge, account_metas)
165237
}
238+
239+
/// FIXME copied from the stake program
240+
pub fn create_account(
241+
from_pubkey: &Pubkey,
242+
stake_pubkey: &Pubkey,
243+
authorized: &Authorized,
244+
lockup: &Lockup,
245+
lamports: u64,
246+
) -> Vec<Instruction> {
247+
vec![
248+
system_instruction::create_account(
249+
from_pubkey,
250+
stake_pubkey,
251+
lamports,
252+
std::mem::size_of::<StakeState>() as u64,
253+
&id(),
254+
),
255+
initialize(stake_pubkey, authorized, lockup),
256+
]
257+
}
258+
259+
/// FIXME copied from the stake program
260+
fn initialize(stake_pubkey: &Pubkey, authorized: &Authorized, lockup: &Lockup) -> Instruction {
261+
Instruction::new(
262+
id(),
263+
&StakeInstruction::Initialize(*authorized, *lockup),
264+
vec![
265+
AccountMeta::new(*stake_pubkey, false),
266+
AccountMeta::new_readonly(sysvar::rent::id(), false),
267+
],
268+
)
269+
}

0 commit comments

Comments
 (0)