stake-pool: Rename instructions / structs (#1536)

* stake-pool: Rename instructions / structs

* Cargo fmt

* Fix proptest
This commit is contained in:
Jon Cinque 2021-03-30 23:54:06 +02:00 committed by GitHub
parent 024766161c
commit 9e4f190633
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 370 additions and 387 deletions

View File

@ -235,7 +235,7 @@ We created new validator stake accounts in the last step and staked them. Once
the stake activates, we can add them to the stake pool. the stake activates, we can add them to the stake pool.
```sh ```sh
$ spl-stake-pool add-validator-stake 3CLwo9CntMi4D1enHEFBe3pRJQzGJBCAYe66xFuEbmhC FYQB64aEzSmECvnG8RVvdAXBxRnzrLvcA3R22aGH2hUN $ spl-stake-pool add-validator 3CLwo9CntMi4D1enHEFBe3pRJQzGJBCAYe66xFuEbmhC FYQB64aEzSmECvnG8RVvdAXBxRnzrLvcA3R22aGH2hUN
Creating account to receive tokens Gu8xqzYFg2sPHWHhUivKNBeF9uikiauihLs9hLzziKu7 Creating account to receive tokens Gu8xqzYFg2sPHWHhUivKNBeF9uikiauihLs9hLzziKu7
Signature: 3N1K89rGV9gWueTTrPGTDBwKAp8BikQhKHMFoREw98Q1piXFeZSSxqfnRQexrfAZQfrpYH9qwsaPWRruwkVeBivV Signature: 3N1K89rGV9gWueTTrPGTDBwKAp8BikQhKHMFoREw98Q1piXFeZSSxqfnRQexrfAZQfrpYH9qwsaPWRruwkVeBivV
``` ```
@ -265,7 +265,7 @@ totally remove the validator stake account from the stake pool by providing
staking derivatives, just like `withdraw`. staking derivatives, just like `withdraw`.
```sh ```sh
$ spl-stake-pool remove-validator-stake 3CLwo9CntMi4D1enHEFBe3pRJQzGJBCAYe66xFuEbmhC CrStLEWfme37kDc3nubK9HsmWR5dsuVUuqEKqTR4Mc5E --withdraw-from 34XMHa3JUPv46ftU4dGHvemZ9oKVjnciRePYMcX3rjEF $ spl-stake-pool remove-validator 3CLwo9CntMi4D1enHEFBe3pRJQzGJBCAYe66xFuEbmhC CrStLEWfme37kDc3nubK9HsmWR5dsuVUuqEKqTR4Mc5E --withdraw-from 34XMHa3JUPv46ftU4dGHvemZ9oKVjnciRePYMcX3rjEF
Signature: 5rrQ3xhDWyiPkUTAQkNAeq31n6sMf1xsg2x9hVY8Vj1NonwBnhxuTv87nADLkwC8Xzc4CGTNCTX2Vph9esWnXk2d Signature: 5rrQ3xhDWyiPkUTAQkNAeq31n6sMf1xsg2x9hVY8Vj1NonwBnhxuTv87nADLkwC8Xzc4CGTNCTX2Vph9esWnXk2d
``` ```

View File

@ -34,9 +34,9 @@ use {
spl_stake_pool::{ spl_stake_pool::{
borsh::{get_instance_packed_len, try_from_slice_unchecked}, borsh::{get_instance_packed_len, try_from_slice_unchecked},
instruction::{ instruction::{
add_validator_stake_account, create_validator_stake_account, deposit, add_validator_to_pool, create_validator_stake_account, deposit,
initialize as initialize_pool, remove_validator_stake_account, set_owner, initialize as initialize_pool, remove_validator_from_pool, set_owner,
update_list_balance, update_pool_balance, withdraw, Fee as PoolFee, update_stake_pool_balance, update_validator_list_balance, withdraw, Fee as PoolFee,
}, },
processor::Processor as PoolProcessor, processor::Processor as PoolProcessor,
stake::authorize as authorize_stake, stake::authorize as authorize_stake,
@ -44,7 +44,7 @@ use {
stake::StakeAuthorize, stake::StakeAuthorize,
stake::StakeState, stake::StakeState,
state::StakePool, state::StakePool,
state::ValidatorStakeList, state::ValidatorList,
}, },
spl_token::{ spl_token::{
self, instruction::approve as approve_token, instruction::initialize_account, self, instruction::approve as approve_token, instruction::initialize_account,
@ -145,7 +145,7 @@ fn command_create_pool(config: &Config, fee: PoolFee, max_validators: u32) -> Co
let pool_account = Keypair::new(); let pool_account = Keypair::new();
println!("Creating stake pool {}", pool_account.pubkey()); println!("Creating stake pool {}", pool_account.pubkey());
let validator_stake_list = Keypair::new(); let validator_list = Keypair::new();
let mint_account_balance = config let mint_account_balance = config
.rpc_client .rpc_client
@ -156,15 +156,15 @@ fn command_create_pool(config: &Config, fee: PoolFee, max_validators: u32) -> Co
let pool_account_balance = config let pool_account_balance = config
.rpc_client .rpc_client
.get_minimum_balance_for_rent_exemption(get_packed_len::<StakePool>())?; .get_minimum_balance_for_rent_exemption(get_packed_len::<StakePool>())?;
let empty_validator_list = ValidatorStakeList::new_with_max_validators(max_validators); let empty_validator_list = ValidatorList::new_with_max_validators(max_validators);
let validator_stake_list_size = get_instance_packed_len(&empty_validator_list)?; let validator_list_size = get_instance_packed_len(&empty_validator_list)?;
let validator_stake_list_balance = config let validator_list_balance = config
.rpc_client .rpc_client
.get_minimum_balance_for_rent_exemption(validator_stake_list_size)?; .get_minimum_balance_for_rent_exemption(validator_list_size)?;
let total_rent_free_balances = mint_account_balance let total_rent_free_balances = mint_account_balance
+ pool_fee_account_balance + pool_fee_account_balance
+ pool_account_balance + pool_account_balance
+ validator_stake_list_balance; + validator_list_balance;
let default_decimals = native_mint::DECIMALS; let default_decimals = native_mint::DECIMALS;
@ -208,9 +208,9 @@ fn command_create_pool(config: &Config, fee: PoolFee, max_validators: u32) -> Co
// Validator stake account list storage // Validator stake account list storage
system_instruction::create_account( system_instruction::create_account(
&config.fee_payer.pubkey(), &config.fee_payer.pubkey(),
&validator_stake_list.pubkey(), &validator_list.pubkey(),
validator_stake_list_balance, validator_list_balance,
validator_stake_list_size as u64, validator_list_size as u64,
&spl_stake_pool::id(), &spl_stake_pool::id(),
), ),
// Initialize pool token mint account // Initialize pool token mint account
@ -233,7 +233,7 @@ fn command_create_pool(config: &Config, fee: PoolFee, max_validators: u32) -> Co
&spl_stake_pool::id(), &spl_stake_pool::id(),
&pool_account.pubkey(), &pool_account.pubkey(),
&config.owner.pubkey(), &config.owner.pubkey(),
&validator_stake_list.pubkey(), &validator_list.pubkey(),
&mint_account.pubkey(), &mint_account.pubkey(),
&pool_fee_account.pubkey(), &pool_fee_account.pubkey(),
&spl_token::id(), &spl_token::id(),
@ -252,7 +252,7 @@ fn command_create_pool(config: &Config, fee: PoolFee, max_validators: u32) -> Co
let mut signers = vec![ let mut signers = vec![
config.fee_payer.as_ref(), config.fee_payer.as_ref(),
&pool_account, &pool_account,
&validator_stake_list, &validator_list,
&mint_account, &mint_account,
&pool_fee_account, &pool_fee_account,
config.owner.as_ref(), config.owner.as_ref(),
@ -367,13 +367,13 @@ fn command_vsa_add(
StakeAuthorize::Staker, StakeAuthorize::Staker,
), ),
// Add validator stake account to the pool // Add validator stake account to the pool
add_validator_stake_account( add_validator_to_pool(
&spl_stake_pool::id(), &spl_stake_pool::id(),
&pool, &pool,
&config.owner.pubkey(), &config.owner.pubkey(),
&pool_deposit_authority, &pool_deposit_authority,
&pool_withdraw_authority, &pool_withdraw_authority,
&pool_data.validator_stake_list, &pool_data.validator_list,
&stake, &stake,
&token_receiver, &token_receiver,
&pool_data.pool_mint, &pool_data.pool_mint,
@ -458,13 +458,13 @@ fn command_vsa_remove(
tokens_to_withdraw, tokens_to_withdraw,
)?, )?,
// Create new validator stake account address // Create new validator stake account address
remove_validator_stake_account( remove_validator_from_pool(
&spl_stake_pool::id(), &spl_stake_pool::id(),
&pool, &pool,
&config.owner.pubkey(), &config.owner.pubkey(),
&pool_withdraw_authority, &pool_withdraw_authority,
&new_authority, &new_authority,
&pool_data.validator_stake_list, &pool_data.validator_list,
&stake, &stake,
&withdraw_from, &withdraw_from,
&pool_data.pool_mint, &pool_data.pool_mint,
@ -559,12 +559,12 @@ fn command_deposit(
}?; }?;
// Check if this vote account has staking account in the pool // Check if this vote account has staking account in the pool
let validator_stake_list_data = config let validator_list_data = config
.rpc_client .rpc_client
.get_account_data(&pool_data.validator_stake_list)?; .get_account_data(&pool_data.validator_list)?;
let validator_stake_list_data = let validator_list_data =
try_from_slice_unchecked::<ValidatorStakeList>(&validator_stake_list_data.as_slice())?; try_from_slice_unchecked::<ValidatorList>(&validator_list_data.as_slice())?;
if !validator_stake_list_data.contains(&vote_account) { if !validator_list_data.contains(&vote_account) {
return Err("Stake account for this validator does not exist in the pool.".into()); return Err("Stake account for this validator does not exist in the pool.".into());
} }
@ -637,7 +637,7 @@ fn command_deposit(
deposit( deposit(
&spl_stake_pool::id(), &spl_stake_pool::id(),
&pool, &pool,
&pool_data.validator_stake_list, &pool_data.validator_list,
&pool_deposit_authority, &pool_deposit_authority,
&pool_withdraw_authority, &pool_withdraw_authority,
&stake, &stake,
@ -672,11 +672,11 @@ fn command_list(config: &Config, pool: &Pubkey) -> CommandResult {
if config.verbose { if config.verbose {
let validator_list = config let validator_list = config
.rpc_client .rpc_client
.get_account_data(&pool_data.validator_stake_list)?; .get_account_data(&pool_data.validator_list)?;
let validator_stake_list_data = let validator_list_data =
try_from_slice_unchecked::<ValidatorStakeList>(&validator_list.as_slice())?; try_from_slice_unchecked::<ValidatorList>(&validator_list.as_slice())?;
println!("Current validator list"); println!("Current validator list");
for validator in validator_stake_list_data.validators { for validator in validator_list_data.validators {
println!( println!(
"Vote Account: {}\tBalance: {}\tEpoch: {}", "Vote Account: {}\tBalance: {}\tEpoch: {}",
validator.validator_account, validator.balance, validator.last_update_epoch validator.validator_account, validator.balance, validator.last_update_epoch
@ -720,15 +720,15 @@ fn command_update(config: &Config, pool: &Pubkey) -> CommandResult {
// Get stake pool state // Get stake pool state
let pool_data = config.rpc_client.get_account_data(&pool)?; let pool_data = config.rpc_client.get_account_data(&pool)?;
let pool_data = StakePool::try_from_slice(pool_data.as_slice()).unwrap(); let pool_data = StakePool::try_from_slice(pool_data.as_slice()).unwrap();
let validator_stake_list_data = config let validator_list_data = config
.rpc_client .rpc_client
.get_account_data(&pool_data.validator_stake_list)?; .get_account_data(&pool_data.validator_list)?;
let validator_stake_list_data = let validator_list_data =
try_from_slice_unchecked::<ValidatorStakeList>(&validator_stake_list_data.as_slice())?; try_from_slice_unchecked::<ValidatorList>(&validator_list_data.as_slice())?;
let epoch_info = config.rpc_client.get_epoch_info()?; let epoch_info = config.rpc_client.get_epoch_info()?;
let accounts_to_update: Vec<Pubkey> = validator_stake_list_data let accounts_to_update: Vec<Pubkey> = validator_list_data
.validators .validators
.iter() .iter()
.filter_map(|item| { .filter_map(|item| {
@ -748,9 +748,9 @@ fn command_update(config: &Config, pool: &Pubkey) -> CommandResult {
let mut instructions: Vec<Instruction> = vec![]; let mut instructions: Vec<Instruction> = vec![];
for chunk in accounts_to_update.chunks(MAX_ACCOUNTS_TO_UPDATE) { for chunk in accounts_to_update.chunks(MAX_ACCOUNTS_TO_UPDATE) {
instructions.push(update_list_balance( instructions.push(update_validator_list_balance(
&spl_stake_pool::id(), &spl_stake_pool::id(),
&pool_data.validator_stake_list, &pool_data.validator_list,
&chunk, &chunk,
)?); )?);
} }
@ -760,10 +760,10 @@ fn command_update(config: &Config, pool: &Pubkey) -> CommandResult {
Ok(()) Ok(())
} else { } else {
println!("Updating stake pool..."); println!("Updating stake pool...");
instructions.push(update_pool_balance( instructions.push(update_stake_pool_balance(
&spl_stake_pool::id(), &spl_stake_pool::id(),
pool, pool,
&pool_data.validator_stake_list, &pool_data.validator_list,
)?); )?);
let mut transaction = let mut transaction =
@ -976,7 +976,7 @@ fn command_withdraw(
instructions.push(withdraw( instructions.push(withdraw(
&spl_stake_pool::id(), &spl_stake_pool::id(),
&pool, &pool,
&pool_data.validator_stake_list, &pool_data.validator_list,
&pool_withdraw_authority, &pool_withdraw_authority,
&withdraw_stake.pubkey, &withdraw_stake.pubkey,
&stake_receiver.unwrap(), // Cannot be none at this point &stake_receiver.unwrap(), // Cannot be none at this point
@ -1183,7 +1183,7 @@ fn main() {
.help("The validator vote account that this stake will be delegated to"), .help("The validator vote account that this stake will be delegated to"),
) )
) )
.subcommand(SubCommand::with_name("add-validator-stake").about("Add validator stake account to the stake pool. Must be signed by the pool owner.") .subcommand(SubCommand::with_name("add-validator").about("Add validator account to the stake pool. Must be signed by the pool owner.")
.arg( .arg(
Arg::with_name("pool") Arg::with_name("pool")
.index(1) .index(1)
@ -1211,7 +1211,7 @@ fn main() {
.help("Account to receive pool token. Must be initialized account of the stake pool token. Defaults to the new pool token account."), .help("Account to receive pool token. Must be initialized account of the stake pool token. Defaults to the new pool token account."),
) )
) )
.subcommand(SubCommand::with_name("remove-validator-stake").about("Add validator stake account to the stake pool. Must be signed by the pool owner.") .subcommand(SubCommand::with_name("remove-validator").about("Remove validator account from the stake pool. Must be signed by the pool owner.")
.arg( .arg(
Arg::with_name("pool") Arg::with_name("pool")
.index(1) .index(1)
@ -1435,13 +1435,13 @@ fn main() {
let vote_account: Pubkey = pubkey_of(arg_matches, "vote_account").unwrap(); let vote_account: Pubkey = pubkey_of(arg_matches, "vote_account").unwrap();
command_vsa_create(&config, &pool_account, &vote_account) command_vsa_create(&config, &pool_account, &vote_account)
} }
("add-validator-stake", Some(arg_matches)) => { ("add-validator", Some(arg_matches)) => {
let pool_account: Pubkey = pubkey_of(arg_matches, "pool").unwrap(); let pool_account: Pubkey = pubkey_of(arg_matches, "pool").unwrap();
let stake_account: Pubkey = pubkey_of(arg_matches, "stake_account").unwrap(); let stake_account: Pubkey = pubkey_of(arg_matches, "stake_account").unwrap();
let token_receiver: Option<Pubkey> = pubkey_of(arg_matches, "token_receiver"); let token_receiver: Option<Pubkey> = pubkey_of(arg_matches, "token_receiver");
command_vsa_add(&config, &pool_account, &stake_account, &token_receiver) command_vsa_add(&config, &pool_account, &stake_account, &token_receiver)
} }
("remove-validator-stake", Some(arg_matches)) => { ("remove-validator", Some(arg_matches)) => {
let pool_account: Pubkey = pubkey_of(arg_matches, "pool").unwrap(); let pool_account: Pubkey = pubkey_of(arg_matches, "pool").unwrap();
let stake_account: Pubkey = pubkey_of(arg_matches, "stake_account").unwrap(); let stake_account: Pubkey = pubkey_of(arg_matches, "stake_account").unwrap();
let withdraw_from: Pubkey = pubkey_of(arg_matches, "withdraw_from").unwrap(); let withdraw_from: Pubkey = pubkey_of(arg_matches, "withdraw_from").unwrap();

View File

@ -0,0 +1 @@
cc 41ce1c46341336993e5e5d5aa94c30865e63f9e00d31d397aef88ec79fc312ca

View File

@ -72,7 +72,7 @@ pub enum StakePoolInstruction {
/// 9. '[]' Sysvar stake history account /// 9. '[]' Sysvar stake history account
/// 10. `[]` Pool token program id, /// 10. `[]` Pool token program id,
/// 11. `[]` Stake program id, /// 11. `[]` Stake program id,
AddValidatorStakeAccount, AddValidatorToPool,
/// Removes validator stake account from the pool /// Removes validator stake account from the pool
/// ///
@ -87,21 +87,21 @@ pub enum StakePoolInstruction {
/// 8. '[]' Sysvar clock account (required) /// 8. '[]' Sysvar clock account (required)
/// 9. `[]` Pool token program id /// 9. `[]` Pool token program id
/// 10. `[]` Stake program id, /// 10. `[]` Stake program id,
RemoveValidatorStakeAccount, RemoveValidatorFromPool,
/// Updates balances of validator stake accounts in the pool /// Updates balances of validator stake accounts in the pool
/// ///
/// 0. `[w]` Validator stake list storage account /// 0. `[w]` Validator stake list storage account
/// 1. `[]` Sysvar clock account /// 1. `[]` Sysvar clock account
/// 2. ..2+N ` [] N validator stake accounts to update balances /// 2. ..2+N ` [] N validator stake accounts to update balances
UpdateListBalance, UpdateValidatorListBalance,
/// Updates total pool balance based on balances in validator stake account list storage /// Updates total pool balance based on balances in validator stake account list storage
/// ///
/// 0. `[w]` Stake pool /// 0. `[w]` Stake pool
/// 1. `[]` Validator stake list storage account /// 1. `[]` Validator stake list storage account
/// 2. `[]` Sysvar clock account /// 2. `[]` Sysvar clock account
UpdatePoolBalance, UpdateStakePoolBalance,
/// Deposit some stake into the pool. The output is a "pool" token representing ownership /// Deposit some stake into the pool. The output is a "pool" token representing ownership
/// into the pool. Inputs are converted to the current ratio. /// into the pool. Inputs are converted to the current ratio.
@ -152,7 +152,7 @@ pub fn initialize(
program_id: &Pubkey, program_id: &Pubkey,
stake_pool: &Pubkey, stake_pool: &Pubkey,
owner: &Pubkey, owner: &Pubkey,
validator_stake_list: &Pubkey, validator_list: &Pubkey,
pool_mint: &Pubkey, pool_mint: &Pubkey,
owner_pool_account: &Pubkey, owner_pool_account: &Pubkey,
token_program_id: &Pubkey, token_program_id: &Pubkey,
@ -167,7 +167,7 @@ pub fn initialize(
let accounts = vec![ let accounts = vec![
AccountMeta::new(*stake_pool, true), AccountMeta::new(*stake_pool, true),
AccountMeta::new_readonly(*owner, true), AccountMeta::new_readonly(*owner, true),
AccountMeta::new(*validator_stake_list, false), AccountMeta::new(*validator_list, false),
AccountMeta::new_readonly(*pool_mint, false), AccountMeta::new_readonly(*pool_mint, false),
AccountMeta::new_readonly(*owner_pool_account, false), AccountMeta::new_readonly(*owner_pool_account, false),
AccountMeta::new_readonly(sysvar::clock::id(), false), AccountMeta::new_readonly(sysvar::clock::id(), false),
@ -211,14 +211,14 @@ pub fn create_validator_stake_account(
}) })
} }
/// Creates `AddValidatorStakeAccount` instruction (add new validator stake account to the pool) /// Creates `AddValidatorToPool` instruction (add new validator stake account to the pool)
pub fn add_validator_stake_account( pub fn add_validator_to_pool(
program_id: &Pubkey, program_id: &Pubkey,
stake_pool: &Pubkey, stake_pool: &Pubkey,
owner: &Pubkey, owner: &Pubkey,
stake_pool_deposit: &Pubkey, stake_pool_deposit: &Pubkey,
stake_pool_withdraw: &Pubkey, stake_pool_withdraw: &Pubkey,
validator_stake_list: &Pubkey, validator_list: &Pubkey,
stake_account: &Pubkey, stake_account: &Pubkey,
pool_tokens_to: &Pubkey, pool_tokens_to: &Pubkey,
pool_mint: &Pubkey, pool_mint: &Pubkey,
@ -230,7 +230,7 @@ pub fn add_validator_stake_account(
AccountMeta::new_readonly(*owner, true), AccountMeta::new_readonly(*owner, true),
AccountMeta::new_readonly(*stake_pool_deposit, false), AccountMeta::new_readonly(*stake_pool_deposit, false),
AccountMeta::new_readonly(*stake_pool_withdraw, false), AccountMeta::new_readonly(*stake_pool_withdraw, false),
AccountMeta::new(*validator_stake_list, false), AccountMeta::new(*validator_list, false),
AccountMeta::new(*stake_account, false), AccountMeta::new(*stake_account, false),
AccountMeta::new(*pool_tokens_to, false), AccountMeta::new(*pool_tokens_to, false),
AccountMeta::new(*pool_mint, false), AccountMeta::new(*pool_mint, false),
@ -242,18 +242,18 @@ pub fn add_validator_stake_account(
Ok(Instruction { Ok(Instruction {
program_id: *program_id, program_id: *program_id,
accounts, accounts,
data: StakePoolInstruction::AddValidatorStakeAccount.try_to_vec()?, data: StakePoolInstruction::AddValidatorToPool.try_to_vec()?,
}) })
} }
/// Creates `RemoveValidatorStakeAccount` instruction (remove validator stake account from the pool) /// Creates `RemoveValidatorFromPool` instruction (remove validator stake account from the pool)
pub fn remove_validator_stake_account( pub fn remove_validator_from_pool(
program_id: &Pubkey, program_id: &Pubkey,
stake_pool: &Pubkey, stake_pool: &Pubkey,
owner: &Pubkey, owner: &Pubkey,
stake_pool_withdraw: &Pubkey, stake_pool_withdraw: &Pubkey,
new_stake_authority: &Pubkey, new_stake_authority: &Pubkey,
validator_stake_list: &Pubkey, validator_list: &Pubkey,
stake_account: &Pubkey, stake_account: &Pubkey,
burn_from: &Pubkey, burn_from: &Pubkey,
pool_mint: &Pubkey, pool_mint: &Pubkey,
@ -265,7 +265,7 @@ pub fn remove_validator_stake_account(
AccountMeta::new_readonly(*owner, true), AccountMeta::new_readonly(*owner, true),
AccountMeta::new_readonly(*stake_pool_withdraw, false), AccountMeta::new_readonly(*stake_pool_withdraw, false),
AccountMeta::new_readonly(*new_stake_authority, false), AccountMeta::new_readonly(*new_stake_authority, false),
AccountMeta::new(*validator_stake_list, false), AccountMeta::new(*validator_list, false),
AccountMeta::new(*stake_account, false), AccountMeta::new(*stake_account, false),
AccountMeta::new(*burn_from, false), AccountMeta::new(*burn_from, false),
AccountMeta::new(*pool_mint, false), AccountMeta::new(*pool_mint, false),
@ -276,44 +276,44 @@ pub fn remove_validator_stake_account(
Ok(Instruction { Ok(Instruction {
program_id: *program_id, program_id: *program_id,
accounts, accounts,
data: StakePoolInstruction::RemoveValidatorStakeAccount.try_to_vec()?, data: StakePoolInstruction::RemoveValidatorFromPool.try_to_vec()?,
}) })
} }
/// Creates `UpdateListBalance` instruction (update validator stake account balances) /// Creates `UpdateValidatorListBalance` instruction (update validator stake account balances)
pub fn update_list_balance( pub fn update_validator_list_balance(
program_id: &Pubkey, program_id: &Pubkey,
validator_stake_list_storage: &Pubkey, validator_list_storage: &Pubkey,
validator_stake_list: &[Pubkey], validator_list: &[Pubkey],
) -> Result<Instruction, ProgramError> { ) -> Result<Instruction, ProgramError> {
let mut accounts: Vec<AccountMeta> = validator_stake_list let mut accounts: Vec<AccountMeta> = validator_list
.iter() .iter()
.map(|pubkey| AccountMeta::new_readonly(*pubkey, false)) .map(|pubkey| AccountMeta::new_readonly(*pubkey, false))
.collect(); .collect();
accounts.insert(0, AccountMeta::new(*validator_stake_list_storage, false)); accounts.insert(0, AccountMeta::new(*validator_list_storage, false));
accounts.insert(1, AccountMeta::new_readonly(sysvar::clock::id(), false)); accounts.insert(1, AccountMeta::new_readonly(sysvar::clock::id(), false));
Ok(Instruction { Ok(Instruction {
program_id: *program_id, program_id: *program_id,
accounts, accounts,
data: StakePoolInstruction::UpdateListBalance.try_to_vec()?, data: StakePoolInstruction::UpdateValidatorListBalance.try_to_vec()?,
}) })
} }
/// Creates `UpdatePoolBalance` instruction (pool balance from the stake account list balances) /// Creates `UpdateStakePoolBalance` instruction (pool balance from the stake account list balances)
pub fn update_pool_balance( pub fn update_stake_pool_balance(
program_id: &Pubkey, program_id: &Pubkey,
stake_pool: &Pubkey, stake_pool: &Pubkey,
validator_stake_list_storage: &Pubkey, validator_list_storage: &Pubkey,
) -> Result<Instruction, ProgramError> { ) -> Result<Instruction, ProgramError> {
let accounts = vec![ let accounts = vec![
AccountMeta::new(*stake_pool, false), AccountMeta::new(*stake_pool, false),
AccountMeta::new(*validator_stake_list_storage, false), AccountMeta::new(*validator_list_storage, false),
AccountMeta::new_readonly(sysvar::clock::id(), false), AccountMeta::new_readonly(sysvar::clock::id(), false),
]; ];
Ok(Instruction { Ok(Instruction {
program_id: *program_id, program_id: *program_id,
accounts, accounts,
data: StakePoolInstruction::UpdatePoolBalance.try_to_vec()?, data: StakePoolInstruction::UpdateStakePoolBalance.try_to_vec()?,
}) })
} }
@ -321,7 +321,7 @@ pub fn update_pool_balance(
pub fn deposit( pub fn deposit(
program_id: &Pubkey, program_id: &Pubkey,
stake_pool: &Pubkey, stake_pool: &Pubkey,
validator_stake_list_storage: &Pubkey, validator_list_storage: &Pubkey,
stake_pool_deposit: &Pubkey, stake_pool_deposit: &Pubkey,
stake_pool_withdraw: &Pubkey, stake_pool_withdraw: &Pubkey,
stake_to_join: &Pubkey, stake_to_join: &Pubkey,
@ -334,7 +334,7 @@ pub fn deposit(
) -> Result<Instruction, ProgramError> { ) -> Result<Instruction, ProgramError> {
let accounts = vec![ let accounts = vec![
AccountMeta::new(*stake_pool, false), AccountMeta::new(*stake_pool, false),
AccountMeta::new(*validator_stake_list_storage, false), AccountMeta::new(*validator_list_storage, false),
AccountMeta::new_readonly(*stake_pool_deposit, false), AccountMeta::new_readonly(*stake_pool_deposit, false),
AccountMeta::new_readonly(*stake_pool_withdraw, false), AccountMeta::new_readonly(*stake_pool_withdraw, false),
AccountMeta::new(*stake_to_join, false), AccountMeta::new(*stake_to_join, false),
@ -358,7 +358,7 @@ pub fn deposit(
pub fn withdraw( pub fn withdraw(
program_id: &Pubkey, program_id: &Pubkey,
stake_pool: &Pubkey, stake_pool: &Pubkey,
validator_stake_list_storage: &Pubkey, validator_list_storage: &Pubkey,
stake_pool_withdraw: &Pubkey, stake_pool_withdraw: &Pubkey,
stake_to_split: &Pubkey, stake_to_split: &Pubkey,
stake_to_receive: &Pubkey, stake_to_receive: &Pubkey,
@ -371,7 +371,7 @@ pub fn withdraw(
) -> Result<Instruction, ProgramError> { ) -> Result<Instruction, ProgramError> {
let accounts = vec![ let accounts = vec![
AccountMeta::new(*stake_pool, false), AccountMeta::new(*stake_pool, false),
AccountMeta::new(*validator_stake_list_storage, false), AccountMeta::new(*validator_list_storage, false),
AccountMeta::new_readonly(*stake_pool_withdraw, false), AccountMeta::new_readonly(*stake_pool_withdraw, false),
AccountMeta::new(*stake_to_split, false), AccountMeta::new(*stake_to_split, false),
AccountMeta::new(*stake_to_receive, false), AccountMeta::new(*stake_to_receive, false),

View File

@ -6,7 +6,7 @@ use {
error::StakePoolError, error::StakePoolError,
instruction::{Fee, StakePoolInstruction}, instruction::{Fee, StakePoolInstruction},
stake, stake,
state::{AccountType, StakePool, ValidatorStakeInfo, ValidatorStakeList}, state::{AccountType, StakePool, ValidatorList, ValidatorStakeInfo},
}, },
bincode::deserialize, bincode::deserialize,
borsh::{BorshDeserialize, BorshSerialize}, borsh::{BorshDeserialize, BorshSerialize},
@ -281,7 +281,7 @@ impl Processor {
let account_info_iter = &mut accounts.iter(); let account_info_iter = &mut accounts.iter();
let stake_pool_info = next_account_info(account_info_iter)?; let stake_pool_info = next_account_info(account_info_iter)?;
let owner_info = next_account_info(account_info_iter)?; let owner_info = next_account_info(account_info_iter)?;
let validator_stake_list_info = next_account_info(account_info_iter)?; let validator_list_info = next_account_info(account_info_iter)?;
let pool_mint_info = next_account_info(account_info_iter)?; let pool_mint_info = next_account_info(account_info_iter)?;
let owner_fee_info = next_account_info(account_info_iter)?; let owner_fee_info = next_account_info(account_info_iter)?;
// Clock sysvar account // Clock sysvar account
@ -305,21 +305,20 @@ impl Processor {
} }
// Check if validator stake list storage is unitialized // Check if validator stake list storage is unitialized
let mut validator_stake_list = try_from_slice_unchecked::<ValidatorStakeList>( let mut validator_list =
&validator_stake_list_info.data.borrow(), try_from_slice_unchecked::<ValidatorList>(&validator_list_info.data.borrow())?;
)?; if !validator_list.is_uninitialized() {
if !validator_stake_list.is_uninitialized() {
return Err(StakePoolError::AlreadyInUse.into()); return Err(StakePoolError::AlreadyInUse.into());
} }
// Check validator list size // Check validator list size
let data_length = validator_stake_list_info.data_len(); let data_length = validator_list_info.data_len();
let expected_max_validators = ValidatorStakeList::calculate_max_validators(data_length); let expected_max_validators = ValidatorList::calculate_max_validators(data_length);
if expected_max_validators != max_validators as usize || max_validators == 0 { if expected_max_validators != max_validators as usize || max_validators == 0 {
return Err(StakePoolError::UnexpectedValidatorListAccountSize.into()); return Err(StakePoolError::UnexpectedValidatorListAccountSize.into());
} }
validator_stake_list.account_type = AccountType::ValidatorStakeList; validator_list.account_type = AccountType::ValidatorList;
validator_stake_list.validators.clear(); validator_list.validators.clear();
validator_stake_list.max_validators = max_validators; validator_list.max_validators = max_validators;
// Check if stake pool account is rent-exempt // Check if stake pool account is rent-exempt
if !rent.is_exempt(stake_pool_info.lamports(), stake_pool_info.data_len()) { if !rent.is_exempt(stake_pool_info.lamports(), stake_pool_info.data_len()) {
@ -329,8 +328,8 @@ impl Processor {
// Check if validator stake list account is rent-exempt // Check if validator stake list account is rent-exempt
if !rent.is_exempt( if !rent.is_exempt(
validator_stake_list_info.lamports(), validator_list_info.lamports(),
validator_stake_list_info.data_len(), validator_list_info.data_len(),
) { ) {
msg!("Validator stake list not rent-exempt"); msg!("Validator stake list not rent-exempt");
return Err(ProgramError::AccountNotRentExempt); return Err(ProgramError::AccountNotRentExempt);
@ -375,7 +374,7 @@ impl Processor {
return Err(StakePoolError::WrongMintingAuthority.into()); return Err(StakePoolError::WrongMintingAuthority.into());
} }
validator_stake_list.serialize(&mut *validator_stake_list_info.data.borrow_mut())?; validator_list.serialize(&mut *validator_list_info.data.borrow_mut())?;
msg!("Clock data: {:?}", clock_info.data.borrow()); msg!("Clock data: {:?}", clock_info.data.borrow());
msg!("Epoch: {}", clock.epoch); msg!("Epoch: {}", clock.epoch);
@ -384,7 +383,7 @@ impl Processor {
stake_pool.owner = *owner_info.key; stake_pool.owner = *owner_info.key;
stake_pool.deposit_bump_seed = deposit_bump_seed; stake_pool.deposit_bump_seed = deposit_bump_seed;
stake_pool.withdraw_bump_seed = withdraw_bump_seed; stake_pool.withdraw_bump_seed = withdraw_bump_seed;
stake_pool.validator_stake_list = *validator_stake_list_info.key; stake_pool.validator_list = *validator_list_info.key;
stake_pool.pool_mint = *pool_mint_info.key; stake_pool.pool_mint = *pool_mint_info.key;
stake_pool.owner_fee_account = *owner_fee_info.key; stake_pool.owner_fee_account = *owner_fee_info.key;
stake_pool.token_program_id = *token_program_info.key; stake_pool.token_program_id = *token_program_info.key;
@ -480,8 +479,8 @@ impl Processor {
) )
} }
/// Processes `AddValidatorStakeAccount` instruction. /// Processes `AddValidatorToPool` instruction.
pub fn process_add_validator_stake_account( pub fn process_add_validator_to_pool(
program_id: &Pubkey, program_id: &Pubkey,
accounts: &[AccountInfo], accounts: &[AccountInfo],
) -> ProgramResult { ) -> ProgramResult {
@ -495,7 +494,7 @@ impl Processor {
// Stake pool withdraw authority // Stake pool withdraw authority
let withdraw_info = next_account_info(account_info_iter)?; let withdraw_info = next_account_info(account_info_iter)?;
// Account storing validator stake list // Account storing validator stake list
let validator_stake_list_info = next_account_info(account_info_iter)?; let validator_list_info = next_account_info(account_info_iter)?;
// Stake account to add to the pool // Stake account to add to the pool
let stake_account_info = next_account_info(account_info_iter)?; let stake_account_info = next_account_info(account_info_iter)?;
// User account to receive pool tokens // User account to receive pool tokens
@ -544,25 +543,24 @@ impl Processor {
} }
// Check validator stake account list storage // Check validator stake account list storage
if *validator_stake_list_info.key != stake_pool.validator_stake_list { if *validator_list_info.key != stake_pool.validator_list {
return Err(StakePoolError::InvalidValidatorStakeList.into()); return Err(StakePoolError::InvalidValidatorStakeList.into());
} }
// Read validator stake list account and check if it is valid // Read validator stake list account and check if it is valid
let mut validator_stake_list = try_from_slice_unchecked::<ValidatorStakeList>( let mut validator_list =
&validator_stake_list_info.data.borrow(), try_from_slice_unchecked::<ValidatorList>(&validator_list_info.data.borrow())?;
)?; if !validator_list.is_valid() {
if !validator_stake_list.is_valid() {
return Err(StakePoolError::InvalidState.into()); return Err(StakePoolError::InvalidState.into());
} }
if validator_stake_list.max_validators as usize == validator_stake_list.validators.len() { if validator_list.max_validators as usize == validator_list.validators.len() {
return Err(ProgramError::AccountDataTooSmall); return Err(ProgramError::AccountDataTooSmall);
} }
let validator_account = let validator_account =
Self::get_validator_checked(program_id, stake_pool_info, stake_account_info)?; Self::get_validator_checked(program_id, stake_pool_info, stake_account_info)?;
if validator_stake_list.contains(&validator_account) { if validator_list.contains(&validator_account) {
return Err(StakePoolError::ValidatorAlreadyAdded.into()); return Err(StakePoolError::ValidatorAlreadyAdded.into());
} }
@ -604,12 +602,12 @@ impl Processor {
Self::check_stake_activation(stake_account_info, clock, stake_history)?; Self::check_stake_activation(stake_account_info, clock, stake_history)?;
// Add validator to the list and save // Add validator to the list and save
validator_stake_list.validators.push(ValidatorStakeInfo { validator_list.validators.push(ValidatorStakeInfo {
validator_account, validator_account,
balance: stake_lamports, balance: stake_lamports,
last_update_epoch: clock.epoch, last_update_epoch: clock.epoch,
}); });
validator_stake_list.serialize(&mut *validator_stake_list_info.data.borrow_mut())?; validator_list.serialize(&mut *validator_list_info.data.borrow_mut())?;
// Save amounts to the stake pool state // Save amounts to the stake pool state
stake_pool.pool_total += token_amount; stake_pool.pool_total += token_amount;
@ -620,8 +618,8 @@ impl Processor {
Ok(()) Ok(())
} }
/// Processes `RemoveValidatorStakeAccount` instruction. /// Processes `RemoveValidatorFromPool` instruction.
pub fn process_remove_validator_stake_account( pub fn process_remove_validator_from_pool(
program_id: &Pubkey, program_id: &Pubkey,
accounts: &[AccountInfo], accounts: &[AccountInfo],
) -> ProgramResult { ) -> ProgramResult {
@ -635,7 +633,7 @@ impl Processor {
// New stake authority // New stake authority
let new_stake_authority_info = next_account_info(account_info_iter)?; let new_stake_authority_info = next_account_info(account_info_iter)?;
// Account storing validator stake list // Account storing validator stake list
let validator_stake_list_info = next_account_info(account_info_iter)?; let validator_list_info = next_account_info(account_info_iter)?;
// Stake account to remove from the pool // Stake account to remove from the pool
let stake_account_info = next_account_info(account_info_iter)?; let stake_account_info = next_account_info(account_info_iter)?;
// User account with pool tokens to burn from // User account with pool tokens to burn from
@ -680,22 +678,21 @@ impl Processor {
} }
// Check validator stake account list storage // Check validator stake account list storage
if *validator_stake_list_info.key != stake_pool.validator_stake_list { if *validator_list_info.key != stake_pool.validator_list {
return Err(StakePoolError::InvalidValidatorStakeList.into()); return Err(StakePoolError::InvalidValidatorStakeList.into());
} }
// Read validator stake list account and check if it is valid // Read validator stake list account and check if it is valid
let mut validator_stake_list = try_from_slice_unchecked::<ValidatorStakeList>( let mut validator_list =
&validator_stake_list_info.data.borrow(), try_from_slice_unchecked::<ValidatorList>(&validator_list_info.data.borrow())?;
)?; if !validator_list.is_valid() {
if !validator_stake_list.is_valid() {
return Err(StakePoolError::InvalidState.into()); return Err(StakePoolError::InvalidState.into());
} }
let validator_account = let validator_account =
Self::get_validator_checked(program_id, stake_pool_info, stake_account_info)?; Self::get_validator_checked(program_id, stake_pool_info, stake_account_info)?;
if !validator_stake_list.contains(&validator_account) { if !validator_list.contains(&validator_account) {
return Err(StakePoolError::ValidatorNotFound.into()); return Err(StakePoolError::ValidatorNotFound.into());
} }
@ -734,10 +731,10 @@ impl Processor {
)?; )?;
// Remove validator from the list and save // Remove validator from the list and save
validator_stake_list validator_list
.validators .validators
.retain(|item| item.validator_account != validator_account); .retain(|item| item.validator_account != validator_account);
validator_stake_list.serialize(&mut *validator_stake_list_info.data.borrow_mut())?; validator_list.serialize(&mut *validator_list_info.data.borrow_mut())?;
// Save amounts to the stake pool state // Save amounts to the stake pool state
stake_pool.pool_total -= token_amount; stake_pool.pool_total -= token_amount;
@ -748,14 +745,14 @@ impl Processor {
Ok(()) Ok(())
} }
/// Processes `UpdateListBalance` instruction. /// Processes `UpdateValidatorListBalance` instruction.
pub fn process_update_list_balance( pub fn process_update_validator_list_balance(
_program_id: &Pubkey, _program_id: &Pubkey,
accounts: &[AccountInfo], accounts: &[AccountInfo],
) -> ProgramResult { ) -> ProgramResult {
let account_info_iter = &mut accounts.iter(); let account_info_iter = &mut accounts.iter();
// Account storing validator stake list // Account storing validator stake list
let validator_stake_list_info = next_account_info(account_info_iter)?; let validator_list_info = next_account_info(account_info_iter)?;
// Clock sysvar account // Clock sysvar account
let clock_info = next_account_info(account_info_iter)?; let clock_info = next_account_info(account_info_iter)?;
let clock = &Clock::from_account_info(clock_info)?; let clock = &Clock::from_account_info(clock_info)?;
@ -763,10 +760,9 @@ impl Processor {
let validator_stake_accounts = account_info_iter.as_slice(); let validator_stake_accounts = account_info_iter.as_slice();
// Read validator stake list account and check if it is valid // Read validator stake list account and check if it is valid
let mut validator_stake_list = try_from_slice_unchecked::<ValidatorStakeList>( let mut validator_list =
&validator_stake_list_info.data.borrow(), try_from_slice_unchecked::<ValidatorList>(&validator_list_info.data.borrow())?;
)?; if !validator_list.is_valid() {
if !validator_stake_list.is_valid() {
return Err(StakePoolError::InvalidState.into()); return Err(StakePoolError::InvalidState.into());
} }
@ -777,7 +773,7 @@ impl Processor {
let mut changes = false; let mut changes = false;
// Do a brute iteration through the list, optimize if necessary // Do a brute iteration through the list, optimize if necessary
for validator_stake_record in &mut validator_stake_list.validators { for validator_stake_record in &mut validator_list.validators {
if validator_stake_record.last_update_epoch >= clock.epoch { if validator_stake_record.last_update_epoch >= clock.epoch {
continue; continue;
} }
@ -797,14 +793,14 @@ impl Processor {
} }
if changes { if changes {
validator_stake_list.serialize(&mut *validator_stake_list_info.data.borrow_mut())?; validator_list.serialize(&mut *validator_list_info.data.borrow_mut())?;
} }
Ok(()) Ok(())
} }
/// Processes `UpdatePoolBalance` instruction. /// Processes `UpdateStakePoolBalance` instruction.
pub fn process_update_pool_balance( pub fn process_update_stake_pool_balance(
_program_id: &Pubkey, _program_id: &Pubkey,
accounts: &[AccountInfo], accounts: &[AccountInfo],
) -> ProgramResult { ) -> ProgramResult {
@ -812,7 +808,7 @@ impl Processor {
// Stake pool account // Stake pool account
let stake_pool_info = next_account_info(account_info_iter)?; let stake_pool_info = next_account_info(account_info_iter)?;
// Account storing validator stake list // Account storing validator stake list
let validator_stake_list_info = next_account_info(account_info_iter)?; let validator_list_info = next_account_info(account_info_iter)?;
// Clock sysvar account // Clock sysvar account
let clock_info = next_account_info(account_info_iter)?; let clock_info = next_account_info(account_info_iter)?;
let clock = &Clock::from_account_info(clock_info)?; let clock = &Clock::from_account_info(clock_info)?;
@ -824,20 +820,19 @@ impl Processor {
} }
// Check validator stake account list storage // Check validator stake account list storage
if *validator_stake_list_info.key != stake_pool.validator_stake_list { if *validator_list_info.key != stake_pool.validator_list {
return Err(StakePoolError::InvalidValidatorStakeList.into()); return Err(StakePoolError::InvalidValidatorStakeList.into());
} }
// Read validator stake list account and check if it is valid // Read validator stake list account and check if it is valid
let validator_stake_list = try_from_slice_unchecked::<ValidatorStakeList>( let validator_list =
&validator_stake_list_info.data.borrow(), try_from_slice_unchecked::<ValidatorList>(&validator_list_info.data.borrow())?;
)?; if !validator_list.is_valid() {
if !validator_stake_list.is_valid() {
return Err(StakePoolError::InvalidState.into()); return Err(StakePoolError::InvalidState.into());
} }
let mut total_balance: u64 = 0; let mut total_balance: u64 = 0;
for validator_stake_record in validator_stake_list.validators { for validator_stake_record in validator_list.validators {
if validator_stake_record.last_update_epoch < clock.epoch { if validator_stake_record.last_update_epoch < clock.epoch {
return Err(StakePoolError::StakeListOutOfDate.into()); return Err(StakePoolError::StakeListOutOfDate.into());
} }
@ -886,7 +881,7 @@ impl Processor {
// Stake pool // Stake pool
let stake_pool_info = next_account_info(account_info_iter)?; let stake_pool_info = next_account_info(account_info_iter)?;
// Account storing validator stake list // Account storing validator stake list
let validator_stake_list_info = next_account_info(account_info_iter)?; let validator_list_info = next_account_info(account_info_iter)?;
// Stake pool deposit authority // Stake pool deposit authority
let deposit_info = next_account_info(account_info_iter)?; let deposit_info = next_account_info(account_info_iter)?;
// Stake pool withdraw authority // Stake pool withdraw authority
@ -937,7 +932,7 @@ impl Processor {
} }
// Check validator stake account list storage // Check validator stake account list storage
if *validator_stake_list_info.key != stake_pool.validator_stake_list { if *validator_list_info.key != stake_pool.validator_list {
return Err(StakePoolError::InvalidValidatorStakeList.into()); return Err(StakePoolError::InvalidValidatorStakeList.into());
} }
@ -947,17 +942,16 @@ impl Processor {
} }
// Read validator stake list account and check if it is valid // Read validator stake list account and check if it is valid
let mut validator_stake_list = try_from_slice_unchecked::<ValidatorStakeList>( let mut validator_list =
&validator_stake_list_info.data.borrow(), try_from_slice_unchecked::<ValidatorList>(&validator_list_info.data.borrow())?;
)?; if !validator_list.is_valid() {
if !validator_stake_list.is_valid() {
return Err(StakePoolError::InvalidState.into()); return Err(StakePoolError::InvalidState.into());
} }
let validator_account = let validator_account =
Self::get_validator_checked(program_id, stake_pool_info, validator_stake_account_info)?; Self::get_validator_checked(program_id, stake_pool_info, validator_stake_account_info)?;
let validator_list_item = validator_stake_list let validator_list_item = validator_list
.find_mut(&validator_account) .find_mut(&validator_account)
.ok_or(StakePoolError::ValidatorNotFound)?; .ok_or(StakePoolError::ValidatorNotFound)?;
@ -1036,7 +1030,7 @@ impl Processor {
stake_pool.serialize(&mut *stake_pool_info.data.borrow_mut())?; stake_pool.serialize(&mut *stake_pool_info.data.borrow_mut())?;
validator_list_item.balance = **validator_stake_account_info.lamports.borrow(); validator_list_item.balance = **validator_stake_account_info.lamports.borrow();
validator_stake_list.serialize(&mut *validator_stake_list_info.data.borrow_mut())?; validator_list.serialize(&mut *validator_list_info.data.borrow_mut())?;
Ok(()) Ok(())
} }
@ -1051,7 +1045,7 @@ impl Processor {
// Stake pool // Stake pool
let stake_pool_info = next_account_info(account_info_iter)?; let stake_pool_info = next_account_info(account_info_iter)?;
// Account storing validator stake list // Account storing validator stake list
let validator_stake_list_info = next_account_info(account_info_iter)?; let validator_list_info = next_account_info(account_info_iter)?;
// Stake pool withdraw authority // Stake pool withdraw authority
let withdraw_info = next_account_info(account_info_iter)?; let withdraw_info = next_account_info(account_info_iter)?;
// Stake account to split // Stake account to split
@ -1090,7 +1084,7 @@ impl Processor {
} }
// Check validator stake account list storage // Check validator stake account list storage
if *validator_stake_list_info.key != stake_pool.validator_stake_list { if *validator_list_info.key != stake_pool.validator_list {
return Err(StakePoolError::InvalidValidatorStakeList.into()); return Err(StakePoolError::InvalidValidatorStakeList.into());
} }
@ -1100,17 +1094,16 @@ impl Processor {
} }
// Read validator stake list account and check if it is valid // Read validator stake list account and check if it is valid
let mut validator_stake_list = try_from_slice_unchecked::<ValidatorStakeList>( let mut validator_list =
&validator_stake_list_info.data.borrow(), try_from_slice_unchecked::<ValidatorList>(&validator_list_info.data.borrow())?;
)?; if !validator_list.is_valid() {
if !validator_stake_list.is_valid() {
return Err(StakePoolError::InvalidState.into()); return Err(StakePoolError::InvalidState.into());
} }
let validator_account = let validator_account =
Self::get_validator_checked(program_id, stake_pool_info, stake_split_from)?; Self::get_validator_checked(program_id, stake_pool_info, stake_split_from)?;
let validator_list_item = validator_stake_list let validator_list_item = validator_list
.find_mut(&validator_account) .find_mut(&validator_account)
.ok_or(StakePoolError::ValidatorNotFound)?; .ok_or(StakePoolError::ValidatorNotFound)?;
@ -1168,7 +1161,7 @@ impl Processor {
stake_pool.serialize(&mut *stake_pool_info.data.borrow_mut())?; stake_pool.serialize(&mut *stake_pool_info.data.borrow_mut())?;
validator_list_item.balance = **stake_split_from.lamports.borrow(); validator_list_item.balance = **stake_split_from.lamports.borrow();
validator_stake_list.serialize(&mut *validator_stake_list_info.data.borrow_mut())?; validator_list.serialize(&mut *validator_list_info.data.borrow_mut())?;
Ok(()) Ok(())
} }
@ -1216,21 +1209,21 @@ impl Processor {
msg!("Instruction: CreateValidatorStakeAccount"); msg!("Instruction: CreateValidatorStakeAccount");
Self::process_create_validator_stake_account(program_id, accounts) Self::process_create_validator_stake_account(program_id, accounts)
} }
StakePoolInstruction::AddValidatorStakeAccount => { StakePoolInstruction::AddValidatorToPool => {
msg!("Instruction: AddValidatorStakeAccount"); msg!("Instruction: AddValidatorToPool");
Self::process_add_validator_stake_account(program_id, accounts) Self::process_add_validator_to_pool(program_id, accounts)
} }
StakePoolInstruction::RemoveValidatorStakeAccount => { StakePoolInstruction::RemoveValidatorFromPool => {
msg!("Instruction: RemoveValidatorStakeAccount"); msg!("Instruction: RemoveValidatorFromPool");
Self::process_remove_validator_stake_account(program_id, accounts) Self::process_remove_validator_from_pool(program_id, accounts)
} }
StakePoolInstruction::UpdateListBalance => { StakePoolInstruction::UpdateValidatorListBalance => {
msg!("Instruction: UpdateListBalance"); msg!("Instruction: UpdateValidatorListBalance");
Self::process_update_list_balance(program_id, accounts) Self::process_update_validator_list_balance(program_id, accounts)
} }
StakePoolInstruction::UpdatePoolBalance => { StakePoolInstruction::UpdateStakePoolBalance => {
msg!("Instruction: UpdatePoolBalance"); msg!("Instruction: UpdateStakePoolBalance");
Self::process_update_pool_balance(program_id, accounts) Self::process_update_stake_pool_balance(program_id, accounts)
} }
StakePoolInstruction::Deposit => { StakePoolInstruction::Deposit => {
msg!("Instruction: Deposit"); msg!("Instruction: Deposit");

View File

@ -16,7 +16,7 @@ pub enum AccountType {
/// Stake pool /// Stake pool
StakePool, StakePool,
/// Validator stake list /// Validator stake list
ValidatorStakeList, ValidatorList,
} }
impl Default for AccountType { impl Default for AccountType {
@ -41,7 +41,7 @@ pub struct StakePool {
/// for `create_program_address(&[state::StakePool account, "withdrawal"])` /// for `create_program_address(&[state::StakePool account, "withdrawal"])`
pub withdraw_bump_seed: u8, pub withdraw_bump_seed: u8,
/// Validator stake list storage account /// Validator stake list storage account
pub validator_stake_list: Pubkey, pub validator_list: Pubkey,
/// Pool Mint /// Pool Mint
pub pool_mint: Pubkey, pub pool_mint: Pubkey,
/// Owner fee account /// Owner fee account
@ -155,8 +155,8 @@ impl StakePool {
/// Storage list for all validator stake accounts in the pool. /// Storage list for all validator stake accounts in the pool.
#[repr(C)] #[repr(C)]
#[derive(Clone, Debug, Default, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)] #[derive(Clone, Debug, Default, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)]
pub struct ValidatorStakeList { pub struct ValidatorList {
/// Account type, must be ValidatorStakeList currently /// Account type, must be ValidatorList currently
pub account_type: AccountType, pub account_type: AccountType,
/// Maximum allowable number of validators /// Maximum allowable number of validators
@ -180,11 +180,11 @@ pub struct ValidatorStakeInfo {
pub last_update_epoch: u64, pub last_update_epoch: u64,
} }
impl ValidatorStakeList { impl ValidatorList {
/// Create an empty instance containing space for `max_validators` /// Create an empty instance containing space for `max_validators`
pub fn new_with_max_validators(max_validators: u32) -> Self { pub fn new_with_max_validators(max_validators: u32) -> Self {
Self { Self {
account_type: AccountType::ValidatorStakeList, account_type: AccountType::ValidatorList,
max_validators, max_validators,
validators: vec![ValidatorStakeInfo::default(); max_validators as usize], validators: vec![ValidatorStakeInfo::default(); max_validators as usize],
} }
@ -192,7 +192,8 @@ impl ValidatorStakeList {
/// Calculate the number of validator entries that fit in the provided length /// Calculate the number of validator entries that fit in the provided length
pub fn calculate_max_validators(buffer_length: usize) -> usize { pub fn calculate_max_validators(buffer_length: usize) -> usize {
(buffer_length - 1 - 4 - 4) / 48 let header_size = 1 + 4 + 4;
buffer_length.saturating_sub(header_size) / 48
} }
/// Check if contains validator with particular pubkey /// Check if contains validator with particular pubkey
@ -217,7 +218,7 @@ impl ValidatorStakeList {
/// Check if validator stake list is actually initialized as a validator stake list /// Check if validator stake list is actually initialized as a validator stake list
pub fn is_valid(&self) -> bool { pub fn is_valid(&self) -> bool {
self.account_type == AccountType::ValidatorStakeList self.account_type == AccountType::ValidatorList
} }
/// Check if the validator stake list is uninitialized /// Check if the validator stake list is uninitialized
@ -238,11 +239,10 @@ mod test {
#[test] #[test]
fn test_state_packing() { fn test_state_packing() {
let max_validators = 10_000; let max_validators = 10_000;
let size = let size = get_instance_packed_len(&ValidatorList::new_with_max_validators(max_validators))
get_instance_packed_len(&ValidatorStakeList::new_with_max_validators(max_validators)) .unwrap();
.unwrap();
// Not initialized // Not initialized
let stake_list = ValidatorStakeList { let stake_list = ValidatorList {
account_type: AccountType::Uninitialized, account_type: AccountType::Uninitialized,
max_validators: 0, max_validators: 0,
validators: vec![], validators: vec![],
@ -250,26 +250,24 @@ mod test {
let mut byte_vec = vec![0u8; size]; let mut byte_vec = vec![0u8; size];
let mut bytes = byte_vec.as_mut_slice(); let mut bytes = byte_vec.as_mut_slice();
stake_list.serialize(&mut bytes).unwrap(); stake_list.serialize(&mut bytes).unwrap();
let stake_list_unpacked = let stake_list_unpacked = try_from_slice_unchecked::<ValidatorList>(&byte_vec).unwrap();
try_from_slice_unchecked::<ValidatorStakeList>(&byte_vec).unwrap();
assert_eq!(stake_list_unpacked, stake_list); assert_eq!(stake_list_unpacked, stake_list);
// Empty // Empty
let stake_list = ValidatorStakeList { let stake_list = ValidatorList {
account_type: AccountType::ValidatorStakeList, account_type: AccountType::ValidatorList,
max_validators: 0, max_validators: 0,
validators: vec![], validators: vec![],
}; };
let mut byte_vec = vec![0u8; size]; let mut byte_vec = vec![0u8; size];
let mut bytes = byte_vec.as_mut_slice(); let mut bytes = byte_vec.as_mut_slice();
stake_list.serialize(&mut bytes).unwrap(); stake_list.serialize(&mut bytes).unwrap();
let stake_list_unpacked = let stake_list_unpacked = try_from_slice_unchecked::<ValidatorList>(&byte_vec).unwrap();
try_from_slice_unchecked::<ValidatorStakeList>(&byte_vec).unwrap();
assert_eq!(stake_list_unpacked, stake_list); assert_eq!(stake_list_unpacked, stake_list);
// With several accounts // With several accounts
let stake_list = ValidatorStakeList { let stake_list = ValidatorList {
account_type: AccountType::ValidatorStakeList, account_type: AccountType::ValidatorList,
max_validators, max_validators,
validators: vec![ validators: vec![
ValidatorStakeInfo { ValidatorStakeInfo {
@ -292,20 +290,19 @@ mod test {
let mut byte_vec = vec![0u8; size]; let mut byte_vec = vec![0u8; size];
let mut bytes = byte_vec.as_mut_slice(); let mut bytes = byte_vec.as_mut_slice();
stake_list.serialize(&mut bytes).unwrap(); stake_list.serialize(&mut bytes).unwrap();
let stake_list_unpacked = let stake_list_unpacked = try_from_slice_unchecked::<ValidatorList>(&byte_vec).unwrap();
try_from_slice_unchecked::<ValidatorStakeList>(&byte_vec).unwrap();
assert_eq!(stake_list_unpacked, stake_list); assert_eq!(stake_list_unpacked, stake_list);
} }
proptest! { proptest! {
#[test] #[test]
fn stake_list_size_calculation(test_amount in 0..=100_000_u32) { fn stake_list_size_calculation(test_amount in 0..=100_000_u32) {
let validators = ValidatorStakeList::new_with_max_validators(test_amount); let validators = ValidatorList::new_with_max_validators(test_amount);
let size = get_instance_packed_len(&validators).unwrap(); let size = get_instance_packed_len(&validators).unwrap();
assert_eq!(ValidatorStakeList::calculate_max_validators(size), test_amount as usize); assert_eq!(ValidatorList::calculate_max_validators(size), test_amount as usize);
assert_eq!(ValidatorStakeList::calculate_max_validators(size + 1), test_amount as usize); assert_eq!(ValidatorList::calculate_max_validators(size.saturating_add(1)), test_amount as usize);
assert_eq!(ValidatorStakeList::calculate_max_validators(size + get_packed_len::<ValidatorStakeInfo>()), (test_amount + 1)as usize); assert_eq!(ValidatorList::calculate_max_validators(size.saturating_add(get_packed_len::<ValidatorStakeInfo>())), (test_amount + 1)as usize);
assert_eq!(ValidatorStakeList::calculate_max_validators(size - 1), (test_amount - 1) as usize); assert_eq!(ValidatorList::calculate_max_validators(size.saturating_sub(1)), (test_amount.saturating_sub(1)) as usize);
} }
} }
} }

View File

@ -32,7 +32,7 @@ async fn setup() -> (
.await .await
.unwrap(); .unwrap();
let validator_stake_account: ValidatorStakeAccount = simple_add_validator_stake_account( let validator_stake_account: ValidatorStakeAccount = simple_add_validator_to_pool(
&mut banks_client, &mut banks_client,
&payer, &payer,
&recent_blockhash, &recent_blockhash,
@ -134,15 +134,14 @@ async fn test_stake_pool_deposit() {
state::StakePool::try_from_slice(&stake_pool_before.data.as_slice()).unwrap(); state::StakePool::try_from_slice(&stake_pool_before.data.as_slice()).unwrap();
// Save validator stake account record before depositing // Save validator stake account record before depositing
let validator_stake_list = get_account( let validator_list = get_account(
&mut banks_client, &mut banks_client,
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
) )
.await; .await;
let validator_stake_list = let validator_list =
try_from_slice_unchecked::<state::ValidatorStakeList>(validator_stake_list.data.as_slice()) try_from_slice_unchecked::<state::ValidatorList>(validator_list.data.as_slice()).unwrap();
.unwrap(); let validator_stake_item_before = validator_list
let validator_stake_item_before = validator_stake_list
.find(&validator_stake_account.vote.pubkey()) .find(&validator_stake_account.vote.pubkey())
.unwrap(); .unwrap();
@ -192,15 +191,14 @@ async fn test_stake_pool_deposit() {
assert_eq!(pool_fee_token_balance, fee); assert_eq!(pool_fee_token_balance, fee);
// Check balances in validator stake account list storage // Check balances in validator stake account list storage
let validator_stake_list = get_account( let validator_list = get_account(
&mut banks_client, &mut banks_client,
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
) )
.await; .await;
let validator_stake_list = let validator_list =
try_from_slice_unchecked::<state::ValidatorStakeList>(validator_stake_list.data.as_slice()) try_from_slice_unchecked::<state::ValidatorList>(validator_list.data.as_slice()).unwrap();
.unwrap(); let validator_stake_item = validator_list
let validator_stake_item = validator_stake_list
.find(&validator_stake_account.vote.pubkey()) .find(&validator_stake_account.vote.pubkey())
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
@ -245,7 +243,7 @@ async fn test_stake_pool_deposit_with_wrong_stake_program_id() {
&[instruction::deposit( &[instruction::deposit(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
&stake_pool_accounts.deposit_authority, &stake_pool_accounts.deposit_authority,
&stake_pool_accounts.withdraw_authority, &stake_pool_accounts.withdraw_authority,
&user_stake.pubkey(), &user_stake.pubkey(),
@ -385,7 +383,7 @@ async fn test_stake_pool_deposit_with_wrong_token_program_id() {
&[instruction::deposit( &[instruction::deposit(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
&stake_pool_accounts.deposit_authority, &stake_pool_accounts.deposit_authority,
&stake_pool_accounts.withdraw_authority, &stake_pool_accounts.withdraw_authority,
&user_stake.pubkey(), &user_stake.pubkey(),
@ -415,7 +413,7 @@ async fn test_stake_pool_deposit_with_wrong_token_program_id() {
} }
#[tokio::test] #[tokio::test]
async fn test_stake_pool_deposit_with_wrong_validator_stake_list_account() { async fn test_stake_pool_deposit_with_wrong_validator_list_account() {
let ( let (
mut banks_client, mut banks_client,
payer, payer,
@ -455,8 +453,8 @@ async fn test_stake_pool_deposit_with_wrong_validator_stake_list_account() {
.await .await
.unwrap(); .unwrap();
let wrong_validator_stake_list = Keypair::new(); let wrong_validator_list = Keypair::new();
stake_pool_accounts.validator_stake_list = wrong_validator_stake_list; stake_pool_accounts.validator_list = wrong_validator_list;
let transaction_error = stake_pool_accounts let transaction_error = stake_pool_accounts
.deposit_stake( .deposit_stake(
@ -907,7 +905,7 @@ async fn test_stake_pool_deposit_with_wrong_mint_for_receiver_acc() {
} }
#[tokio::test] #[tokio::test]
async fn test_deposit_with_uninitialized_validator_stake_list() {} // TODO async fn test_deposit_with_uninitialized_validator_list() {} // TODO
#[tokio::test] #[tokio::test]
async fn test_deposit_with_out_of_dated_pool_balances() {} // TODO async fn test_deposit_with_out_of_dated_pool_balances() {} // TODO

View File

@ -165,7 +165,7 @@ pub async fn create_stake_pool(
payer: &Keypair, payer: &Keypair,
recent_blockhash: &Hash, recent_blockhash: &Hash,
stake_pool: &Keypair, stake_pool: &Keypair,
validator_stake_list: &Keypair, validator_list: &Keypair,
pool_mint: &Pubkey, pool_mint: &Pubkey,
pool_token_account: &Pubkey, pool_token_account: &Pubkey,
owner: &Keypair, owner: &Keypair,
@ -174,11 +174,11 @@ pub async fn create_stake_pool(
) -> Result<(), TransportError> { ) -> Result<(), TransportError> {
let rent = banks_client.get_rent().await.unwrap(); let rent = banks_client.get_rent().await.unwrap();
let rent_stake_pool = rent.minimum_balance(get_packed_len::<state::StakePool>()); let rent_stake_pool = rent.minimum_balance(get_packed_len::<state::StakePool>());
let validator_stake_list_size = get_instance_packed_len( let validator_list_size = get_instance_packed_len(
&state::ValidatorStakeList::new_with_max_validators(max_validators), &state::ValidatorList::new_with_max_validators(max_validators),
) )
.unwrap(); .unwrap();
let rent_validator_stake_list = rent.minimum_balance(validator_stake_list_size); let rent_validator_list = rent.minimum_balance(validator_list_size);
let mut transaction = Transaction::new_with_payer( let mut transaction = Transaction::new_with_payer(
&[ &[
@ -191,16 +191,16 @@ pub async fn create_stake_pool(
), ),
system_instruction::create_account( system_instruction::create_account(
&payer.pubkey(), &payer.pubkey(),
&validator_stake_list.pubkey(), &validator_list.pubkey(),
rent_validator_stake_list, rent_validator_list,
validator_stake_list_size as u64, validator_list_size as u64,
&id(), &id(),
), ),
instruction::initialize( instruction::initialize(
&id(), &id(),
&stake_pool.pubkey(), &stake_pool.pubkey(),
&owner.pubkey(), &owner.pubkey(),
&validator_stake_list.pubkey(), &validator_list.pubkey(),
pool_mint, pool_mint,
pool_token_account, pool_token_account,
&spl_token::id(), &spl_token::id(),
@ -212,7 +212,7 @@ pub async fn create_stake_pool(
Some(&payer.pubkey()), Some(&payer.pubkey()),
); );
transaction.sign( transaction.sign(
&[payer, stake_pool, validator_stake_list, owner], &[payer, stake_pool, validator_list, owner],
*recent_blockhash, *recent_blockhash,
); );
banks_client.process_transaction(transaction).await?; banks_client.process_transaction(transaction).await?;
@ -434,7 +434,7 @@ impl ValidatorStakeAccount {
pub struct StakePoolAccounts { pub struct StakePoolAccounts {
pub stake_pool: Keypair, pub stake_pool: Keypair,
pub validator_stake_list: Keypair, pub validator_list: Keypair,
pub pool_mint: Keypair, pub pool_mint: Keypair,
pub pool_fee_account: Keypair, pub pool_fee_account: Keypair,
pub owner: Keypair, pub owner: Keypair,
@ -447,7 +447,7 @@ pub struct StakePoolAccounts {
impl StakePoolAccounts { impl StakePoolAccounts {
pub fn new() -> Self { pub fn new() -> Self {
let stake_pool = Keypair::new(); let stake_pool = Keypair::new();
let validator_stake_list = Keypair::new(); let validator_list = Keypair::new();
let stake_pool_address = &stake_pool.pubkey(); let stake_pool_address = &stake_pool.pubkey();
let (withdraw_authority, _) = Pubkey::find_program_address( let (withdraw_authority, _) = Pubkey::find_program_address(
&[&stake_pool_address.to_bytes()[..32], b"withdraw"], &[&stake_pool_address.to_bytes()[..32], b"withdraw"],
@ -463,7 +463,7 @@ impl StakePoolAccounts {
Self { Self {
stake_pool, stake_pool,
validator_stake_list, validator_list,
pool_mint, pool_mint,
pool_fee_account, pool_fee_account,
owner, owner,
@ -509,7 +509,7 @@ impl StakePoolAccounts {
&payer, &payer,
&recent_blockhash, &recent_blockhash,
&self.stake_pool, &self.stake_pool,
&self.validator_stake_list, &self.validator_list,
&self.pool_mint.pubkey(), &self.pool_mint.pubkey(),
&self.pool_fee_account.pubkey(), &self.pool_fee_account.pubkey(),
&self.owner, &self.owner,
@ -533,7 +533,7 @@ impl StakePoolAccounts {
&[instruction::deposit( &[instruction::deposit(
&id(), &id(),
&self.stake_pool.pubkey(), &self.stake_pool.pubkey(),
&self.validator_stake_list.pubkey(), &self.validator_list.pubkey(),
&self.deposit_authority, &self.deposit_authority,
&self.withdraw_authority, &self.withdraw_authority,
stake, stake,
@ -567,7 +567,7 @@ impl StakePoolAccounts {
&[instruction::withdraw( &[instruction::withdraw(
&id(), &id(),
&self.stake_pool.pubkey(), &self.stake_pool.pubkey(),
&self.validator_stake_list.pubkey(), &self.validator_list.pubkey(),
&self.withdraw_authority, &self.withdraw_authority,
validator_stake_account, validator_stake_account,
stake_recipient, stake_recipient,
@ -586,7 +586,7 @@ impl StakePoolAccounts {
Ok(()) Ok(())
} }
pub async fn add_validator_stake_account( pub async fn add_validator_to_pool(
&self, &self,
banks_client: &mut BanksClient, banks_client: &mut BanksClient,
payer: &Keypair, payer: &Keypair,
@ -595,13 +595,13 @@ impl StakePoolAccounts {
pool_account: &Pubkey, pool_account: &Pubkey,
) -> Option<TransportError> { ) -> Option<TransportError> {
let mut transaction = Transaction::new_with_payer( let mut transaction = Transaction::new_with_payer(
&[instruction::add_validator_stake_account( &[instruction::add_validator_to_pool(
&id(), &id(),
&self.stake_pool.pubkey(), &self.stake_pool.pubkey(),
&self.owner.pubkey(), &self.owner.pubkey(),
&self.deposit_authority, &self.deposit_authority,
&self.withdraw_authority, &self.withdraw_authority,
&self.validator_stake_list.pubkey(), &self.validator_list.pubkey(),
stake, stake,
pool_account, pool_account,
&self.pool_mint.pubkey(), &self.pool_mint.pubkey(),
@ -615,7 +615,7 @@ impl StakePoolAccounts {
banks_client.process_transaction(transaction).await.err() banks_client.process_transaction(transaction).await.err()
} }
pub async fn remove_validator_stake_account( pub async fn remove_validator_from_pool(
&self, &self,
banks_client: &mut BanksClient, banks_client: &mut BanksClient,
payer: &Keypair, payer: &Keypair,
@ -625,13 +625,13 @@ impl StakePoolAccounts {
new_authority: &Pubkey, new_authority: &Pubkey,
) -> Option<TransportError> { ) -> Option<TransportError> {
let mut transaction = Transaction::new_with_payer( let mut transaction = Transaction::new_with_payer(
&[instruction::remove_validator_stake_account( &[instruction::remove_validator_from_pool(
&id(), &id(),
&self.stake_pool.pubkey(), &self.stake_pool.pubkey(),
&self.owner.pubkey(), &self.owner.pubkey(),
&self.withdraw_authority, &self.withdraw_authority,
&new_authority, &new_authority,
&self.validator_stake_list.pubkey(), &self.validator_list.pubkey(),
stake, stake,
pool_account, pool_account,
&self.pool_mint.pubkey(), &self.pool_mint.pubkey(),
@ -646,7 +646,7 @@ impl StakePoolAccounts {
} }
} }
pub async fn simple_add_validator_stake_account( pub async fn simple_add_validator_to_pool(
banks_client: &mut BanksClient, banks_client: &mut BanksClient,
payer: &Keypair, payer: &Keypair,
recent_blockhash: &Hash, recent_blockhash: &Hash,
@ -673,7 +673,7 @@ pub async fn simple_add_validator_stake_account(
.await .await
.unwrap(); .unwrap();
let error = stake_pool_accounts let error = stake_pool_accounts
.add_validator_stake_account( .add_validator_to_pool(
banks_client, banks_client,
&payer, &payer,
&recent_blockhash, &recent_blockhash,

View File

@ -66,15 +66,14 @@ async fn test_stake_pool_initialize() {
assert_eq!(stake_pool.owner, id()); assert_eq!(stake_pool.owner, id());
// Validator stake list storage initialized // Validator stake list storage initialized
let validator_stake_list = get_account( let validator_list = get_account(
&mut banks_client, &mut banks_client,
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
) )
.await; .await;
let validator_stake_list = let validator_list =
try_from_slice_unchecked::<state::ValidatorStakeList>(validator_stake_list.data.as_slice()) try_from_slice_unchecked::<state::ValidatorList>(validator_list.data.as_slice()).unwrap();
.unwrap(); assert_eq!(validator_list.is_valid(), true);
assert_eq!(validator_stake_list.is_valid(), true);
} }
#[tokio::test] #[tokio::test]
@ -120,7 +119,7 @@ async fn test_initialize_stake_pool_with_already_initialized_stake_list_storage(
let latest_blockhash = banks_client.get_recent_blockhash().await.unwrap(); let latest_blockhash = banks_client.get_recent_blockhash().await.unwrap();
let mut second_stake_pool_accounts = StakePoolAccounts::new(); let mut second_stake_pool_accounts = StakePoolAccounts::new();
second_stake_pool_accounts.validator_stake_list = stake_pool_accounts.validator_stake_list; second_stake_pool_accounts.validator_list = stake_pool_accounts.validator_list;
let transaction_error = second_stake_pool_accounts let transaction_error = second_stake_pool_accounts
.initialize_stake_pool(&mut banks_client, &payer, &latest_blockhash) .initialize_stake_pool(&mut banks_client, &payer, &latest_blockhash)
@ -180,11 +179,11 @@ async fn test_initialize_stake_pool_with_wrong_max_validators() {
let rent = banks_client.get_rent().await.unwrap(); let rent = banks_client.get_rent().await.unwrap();
let rent_stake_pool = rent.minimum_balance(get_packed_len::<state::StakePool>()); let rent_stake_pool = rent.minimum_balance(get_packed_len::<state::StakePool>());
let validator_stake_list_size = get_instance_packed_len( let validator_list_size = get_instance_packed_len(
&state::ValidatorStakeList::new_with_max_validators(stake_pool_accounts.max_validators - 1), &state::ValidatorList::new_with_max_validators(stake_pool_accounts.max_validators - 1),
) )
.unwrap(); .unwrap();
let rent_validator_stake_list = rent.minimum_balance(validator_stake_list_size); let rent_validator_list = rent.minimum_balance(validator_list_size);
let mut transaction = Transaction::new_with_payer( let mut transaction = Transaction::new_with_payer(
&[ &[
@ -197,16 +196,16 @@ async fn test_initialize_stake_pool_with_wrong_max_validators() {
), ),
system_instruction::create_account( system_instruction::create_account(
&payer.pubkey(), &payer.pubkey(),
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
rent_validator_stake_list, rent_validator_list,
validator_stake_list_size as u64, validator_list_size as u64,
&id(), &id(),
), ),
instruction::initialize( instruction::initialize(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.owner.pubkey(),
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
&stake_pool_accounts.pool_mint.pubkey(), &stake_pool_accounts.pool_mint.pubkey(),
&stake_pool_accounts.pool_fee_account.pubkey(), &stake_pool_accounts.pool_fee_account.pubkey(),
&spl_token::id(), &spl_token::id(),
@ -221,7 +220,7 @@ async fn test_initialize_stake_pool_with_wrong_max_validators() {
&[ &[
&payer, &payer,
&stake_pool_accounts.stake_pool, &stake_pool_accounts.stake_pool,
&stake_pool_accounts.validator_stake_list, &stake_pool_accounts.validator_list,
&stake_pool_accounts.owner, &stake_pool_accounts.owner,
], ],
recent_blockhash, recent_blockhash,
@ -274,7 +273,7 @@ async fn test_initialize_stake_pool_with_wrong_mint_authority() {
&payer, &payer,
&recent_blockhash, &recent_blockhash,
&stake_pool_accounts.stake_pool, &stake_pool_accounts.stake_pool,
&stake_pool_accounts.validator_stake_list, &stake_pool_accounts.validator_list,
&wrong_mint.pubkey(), &wrong_mint.pubkey(),
&stake_pool_accounts.pool_fee_account.pubkey(), &stake_pool_accounts.pool_fee_account.pubkey(),
&stake_pool_accounts.owner, &stake_pool_accounts.owner,
@ -334,11 +333,11 @@ async fn test_initialize_stake_pool_with_wrong_token_program_id() {
banks_client.process_transaction(transaction).await.unwrap(); banks_client.process_transaction(transaction).await.unwrap();
let rent_stake_pool = rent.minimum_balance(get_packed_len::<state::StakePool>()); let rent_stake_pool = rent.minimum_balance(get_packed_len::<state::StakePool>());
let validator_stake_list_size = get_instance_packed_len( let validator_list_size = get_instance_packed_len(
&state::ValidatorStakeList::new_with_max_validators(stake_pool_accounts.max_validators), &state::ValidatorList::new_with_max_validators(stake_pool_accounts.max_validators),
) )
.unwrap(); .unwrap();
let rent_validator_stake_list = rent.minimum_balance(validator_stake_list_size); let rent_validator_list = rent.minimum_balance(validator_list_size);
let mut transaction = Transaction::new_with_payer( let mut transaction = Transaction::new_with_payer(
&[ &[
@ -351,16 +350,16 @@ async fn test_initialize_stake_pool_with_wrong_token_program_id() {
), ),
system_instruction::create_account( system_instruction::create_account(
&payer.pubkey(), &payer.pubkey(),
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
rent_validator_stake_list, rent_validator_list,
validator_stake_list_size as u64, validator_list_size as u64,
&id(), &id(),
), ),
instruction::initialize( instruction::initialize(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.owner.pubkey(),
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
&stake_pool_accounts.pool_mint.pubkey(), &stake_pool_accounts.pool_mint.pubkey(),
&stake_pool_accounts.pool_fee_account.pubkey(), &stake_pool_accounts.pool_fee_account.pubkey(),
&wrong_token_program.pubkey(), &wrong_token_program.pubkey(),
@ -375,7 +374,7 @@ async fn test_initialize_stake_pool_with_wrong_token_program_id() {
&[ &[
&payer, &payer,
&stake_pool_accounts.stake_pool, &stake_pool_accounts.stake_pool,
&stake_pool_accounts.validator_stake_list, &stake_pool_accounts.validator_list,
&stake_pool_accounts.owner, &stake_pool_accounts.owner,
], ],
recent_blockhash, recent_blockhash,
@ -434,7 +433,7 @@ async fn test_initialize_stake_pool_with_wrong_fee_accounts_owner() {
&payer, &payer,
&recent_blockhash, &recent_blockhash,
&stake_pool_accounts.stake_pool, &stake_pool_accounts.stake_pool,
&stake_pool_accounts.validator_stake_list, &stake_pool_accounts.validator_list,
&stake_pool_accounts.pool_mint.pubkey(), &stake_pool_accounts.pool_mint.pubkey(),
&stake_pool_accounts.pool_fee_account.pubkey(), &stake_pool_accounts.pool_fee_account.pubkey(),
&stake_pool_accounts.owner, &stake_pool_accounts.owner,
@ -500,11 +499,11 @@ async fn test_initialize_stake_pool_with_not_rent_exempt_pool() {
.await; .await;
let rent = banks_client.get_rent().await.unwrap(); let rent = banks_client.get_rent().await.unwrap();
let validator_stake_list_size = get_instance_packed_len( let validator_list_size = get_instance_packed_len(
&state::ValidatorStakeList::new_with_max_validators(stake_pool_accounts.max_validators), &state::ValidatorList::new_with_max_validators(stake_pool_accounts.max_validators),
) )
.unwrap(); .unwrap();
let rent_validator_stake_list = rent.minimum_balance(validator_stake_list_size); let rent_validator_list = rent.minimum_balance(validator_list_size);
let mut transaction = Transaction::new_with_payer( let mut transaction = Transaction::new_with_payer(
&[ &[
@ -517,16 +516,16 @@ async fn test_initialize_stake_pool_with_not_rent_exempt_pool() {
), ),
system_instruction::create_account( system_instruction::create_account(
&payer.pubkey(), &payer.pubkey(),
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
rent_validator_stake_list, rent_validator_list,
validator_stake_list_size as u64, validator_list_size as u64,
&id(), &id(),
), ),
instruction::initialize( instruction::initialize(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.owner.pubkey(),
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
&stake_pool_accounts.pool_mint.pubkey(), &stake_pool_accounts.pool_mint.pubkey(),
&stake_pool_accounts.pool_fee_account.pubkey(), &stake_pool_accounts.pool_fee_account.pubkey(),
&spl_token::id(), &spl_token::id(),
@ -541,7 +540,7 @@ async fn test_initialize_stake_pool_with_not_rent_exempt_pool() {
&[ &[
&payer, &payer,
&stake_pool_accounts.stake_pool, &stake_pool_accounts.stake_pool,
&stake_pool_accounts.validator_stake_list, &stake_pool_accounts.validator_list,
&stake_pool_accounts.owner, &stake_pool_accounts.owner,
], ],
recent_blockhash, recent_blockhash,
@ -562,7 +561,7 @@ async fn test_initialize_stake_pool_with_not_rent_exempt_pool() {
} }
#[tokio::test] #[tokio::test]
async fn test_initialize_stake_pool_with_not_rent_exempt_validator_stake_list() { async fn test_initialize_stake_pool_with_not_rent_exempt_validator_list() {
let (mut banks_client, payer, recent_blockhash) = program_test().start().await; let (mut banks_client, payer, recent_blockhash) = program_test().start().await;
let stake_pool_accounts = StakePoolAccounts::new(); let stake_pool_accounts = StakePoolAccounts::new();
@ -576,8 +575,8 @@ async fn test_initialize_stake_pool_with_not_rent_exempt_validator_stake_list()
let rent = banks_client.get_rent().await.unwrap(); let rent = banks_client.get_rent().await.unwrap();
let rent_stake_pool = rent.minimum_balance(get_packed_len::<state::StakePool>()); let rent_stake_pool = rent.minimum_balance(get_packed_len::<state::StakePool>());
let validator_stake_list_size = get_instance_packed_len( let validator_list_size = get_instance_packed_len(
&state::ValidatorStakeList::new_with_max_validators(stake_pool_accounts.max_validators), &state::ValidatorList::new_with_max_validators(stake_pool_accounts.max_validators),
) )
.unwrap(); .unwrap();
@ -592,16 +591,16 @@ async fn test_initialize_stake_pool_with_not_rent_exempt_validator_stake_list()
), ),
system_instruction::create_account( system_instruction::create_account(
&payer.pubkey(), &payer.pubkey(),
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
1, 1,
validator_stake_list_size as u64, validator_list_size as u64,
&id(), &id(),
), ),
instruction::initialize( instruction::initialize(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.owner.pubkey(),
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
&stake_pool_accounts.pool_mint.pubkey(), &stake_pool_accounts.pool_mint.pubkey(),
&stake_pool_accounts.pool_fee_account.pubkey(), &stake_pool_accounts.pool_fee_account.pubkey(),
&spl_token::id(), &spl_token::id(),
@ -616,7 +615,7 @@ async fn test_initialize_stake_pool_with_not_rent_exempt_validator_stake_list()
&[ &[
&payer, &payer,
&stake_pool_accounts.stake_pool, &stake_pool_accounts.stake_pool,
&stake_pool_accounts.validator_stake_list, &stake_pool_accounts.validator_list,
&stake_pool_accounts.owner, &stake_pool_accounts.owner,
], ],
recent_blockhash, recent_blockhash,
@ -652,11 +651,11 @@ async fn test_initialize_stake_pool_without_owner_signature() {
let rent = banks_client.get_rent().await.unwrap(); let rent = banks_client.get_rent().await.unwrap();
let rent_stake_pool = rent.minimum_balance(get_packed_len::<state::StakePool>()); let rent_stake_pool = rent.minimum_balance(get_packed_len::<state::StakePool>());
let validator_stake_list_size = get_instance_packed_len( let validator_list_size = get_instance_packed_len(
&state::ValidatorStakeList::new_with_max_validators(stake_pool_accounts.max_validators), &state::ValidatorList::new_with_max_validators(stake_pool_accounts.max_validators),
) )
.unwrap(); .unwrap();
let rent_validator_stake_list = rent.minimum_balance(validator_stake_list_size); let rent_validator_list = rent.minimum_balance(validator_list_size);
let init_data = instruction::StakePoolInstruction::Initialize { let init_data = instruction::StakePoolInstruction::Initialize {
fee: stake_pool_accounts.fee.clone(), fee: stake_pool_accounts.fee.clone(),
@ -666,7 +665,7 @@ async fn test_initialize_stake_pool_without_owner_signature() {
let accounts = vec![ let accounts = vec![
AccountMeta::new(stake_pool_accounts.stake_pool.pubkey(), true), AccountMeta::new(stake_pool_accounts.stake_pool.pubkey(), true),
AccountMeta::new_readonly(stake_pool_accounts.owner.pubkey(), false), AccountMeta::new_readonly(stake_pool_accounts.owner.pubkey(), false),
AccountMeta::new(stake_pool_accounts.validator_stake_list.pubkey(), false), AccountMeta::new(stake_pool_accounts.validator_list.pubkey(), false),
AccountMeta::new_readonly(stake_pool_accounts.pool_mint.pubkey(), false), AccountMeta::new_readonly(stake_pool_accounts.pool_mint.pubkey(), false),
AccountMeta::new_readonly(stake_pool_accounts.pool_fee_account.pubkey(), false), AccountMeta::new_readonly(stake_pool_accounts.pool_fee_account.pubkey(), false),
AccountMeta::new_readonly(sysvar::clock::id(), false), AccountMeta::new_readonly(sysvar::clock::id(), false),
@ -690,9 +689,9 @@ async fn test_initialize_stake_pool_without_owner_signature() {
), ),
system_instruction::create_account( system_instruction::create_account(
&payer.pubkey(), &payer.pubkey(),
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
rent_validator_stake_list, rent_validator_list,
validator_stake_list_size as u64, validator_list_size as u64,
&id(), &id(),
), ),
stake_pool_init_instruction, stake_pool_init_instruction,
@ -703,7 +702,7 @@ async fn test_initialize_stake_pool_without_owner_signature() {
&[ &[
&payer, &payer,
&stake_pool_accounts.stake_pool, &stake_pool_accounts.stake_pool,
&stake_pool_accounts.validator_stake_list, &stake_pool_accounts.validator_list,
], ],
recent_blockhash, recent_blockhash,
); );

View File

@ -13,7 +13,7 @@ use {
}; };
#[tokio::test] #[tokio::test]
async fn test_update_pool_balance() { async fn test_update_stake_pool_balance() {
let (mut banks_client, payer, recent_blockhash) = program_test().start().await; let (mut banks_client, payer, recent_blockhash) = program_test().start().await;
let stake_pool_accounts = StakePoolAccounts::new(); let stake_pool_accounts = StakePoolAccounts::new();
stake_pool_accounts stake_pool_accounts
@ -25,7 +25,7 @@ async fn test_update_pool_balance() {
} }
#[tokio::test] #[tokio::test]
async fn test_update_pool_balance_with_wrong_validator_stake_list() { async fn test_update_stake_pool_balance_with_wrong_validator_list() {
let (mut banks_client, payer, recent_blockhash) = program_test().start().await; let (mut banks_client, payer, recent_blockhash) = program_test().start().await;
let stake_pool_accounts = StakePoolAccounts::new(); let stake_pool_accounts = StakePoolAccounts::new();
stake_pool_accounts stake_pool_accounts
@ -35,7 +35,7 @@ async fn test_update_pool_balance_with_wrong_validator_stake_list() {
let wrong_stake_list_storage = Keypair::new(); let wrong_stake_list_storage = Keypair::new();
let mut transaction = Transaction::new_with_payer( let mut transaction = Transaction::new_with_payer(
&[instruction::update_pool_balance( &[instruction::update_stake_pool_balance(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&wrong_stake_list_storage.pubkey(), &wrong_stake_list_storage.pubkey(),
@ -64,7 +64,7 @@ async fn test_update_pool_balance_with_wrong_validator_stake_list() {
} }
#[tokio::test] #[tokio::test]
async fn test_update_pool_balance_with_uninitialized_validator_stake_list() {} // TODO async fn test_update_stake_pool_balance_with_uninitialized_validator_list() {} // TODO
#[tokio::test] #[tokio::test]
async fn test_update_pool_balance_with_out_of_dated_validators_balances() {} // TODO async fn test_update_stake_pool_balance_with_out_of_dated_validators_balances() {} // TODO

View File

@ -11,17 +11,16 @@ use {
spl_stake_pool::{borsh::try_from_slice_unchecked, stake, state}, spl_stake_pool::{borsh::try_from_slice_unchecked, stake, state},
}; };
async fn get_list_sum(banks_client: &mut BanksClient, validator_stake_list_key: &Pubkey) -> u64 { async fn get_list_sum(banks_client: &mut BanksClient, validator_list_key: &Pubkey) -> u64 {
let validator_stake_list = banks_client let validator_list = banks_client
.get_account(*validator_stake_list_key) .get_account(*validator_list_key)
.await .await
.expect("get_account") .expect("get_account")
.expect("validator stake list not none"); .expect("validator stake list not none");
let validator_stake_list = let validator_list =
try_from_slice_unchecked::<state::ValidatorStakeList>(validator_stake_list.data.as_slice()) try_from_slice_unchecked::<state::ValidatorList>(validator_list.data.as_slice()).unwrap();
.unwrap();
validator_stake_list validator_list
.validators .validators
.iter() .iter()
.map(|info| info.balance) .map(|info| info.balance)
@ -29,7 +28,7 @@ async fn get_list_sum(banks_client: &mut BanksClient, validator_stake_list_key:
} }
#[tokio::test] #[tokio::test]
async fn test_update_list_balance() { async fn test_update_validator_list_balance() {
let (mut banks_client, payer, recent_blockhash) = program_test().start().await; let (mut banks_client, payer, recent_blockhash) = program_test().start().await;
let stake_pool_accounts = StakePoolAccounts::new(); let stake_pool_accounts = StakePoolAccounts::new();
stake_pool_accounts stake_pool_accounts
@ -42,7 +41,7 @@ async fn test_update_list_balance() {
const STAKE_ACCOUNTS: u64 = 3; const STAKE_ACCOUNTS: u64 = 3;
for _ in 0..STAKE_ACCOUNTS { for _ in 0..STAKE_ACCOUNTS {
stake_accounts.push( stake_accounts.push(
simple_add_validator_stake_account( simple_add_validator_to_pool(
&mut banks_client, &mut banks_client,
&payer, &payer,
&recent_blockhash, &recent_blockhash,
@ -74,7 +73,7 @@ async fn test_update_list_balance() {
assert_eq!( assert_eq!(
get_list_sum( get_list_sum(
&mut banks_client, &mut banks_client,
&stake_pool_accounts.validator_stake_list.pubkey() &stake_pool_accounts.validator_list.pubkey()
) )
.await, .await,
STAKE_ACCOUNTS * (stake_rent + TEST_STAKE_AMOUNT) STAKE_ACCOUNTS * (stake_rent + TEST_STAKE_AMOUNT)
@ -84,7 +83,7 @@ async fn test_update_list_balance() {
} }
#[tokio::test] #[tokio::test]
async fn test_update_list_balance_with_uninitialized_validator_stake_list() {} // TODO async fn test_update_validator_list_balance_with_uninitialized_validator_list() {} // TODO
#[tokio::test] #[tokio::test]
async fn test_update_list_balance_with_wrong_stake_state() {} // TODO async fn test_update_validator_list_balance_with_wrong_stake_state() {} // TODO

View File

@ -70,7 +70,7 @@ async fn setup() -> (
} }
#[tokio::test] #[tokio::test]
async fn test_add_validator_stake_account() { async fn test_add_validator_to_pool() {
let ( let (
mut banks_client, mut banks_client,
payer, payer,
@ -81,7 +81,7 @@ async fn test_add_validator_stake_account() {
) = setup().await; ) = setup().await;
let error = stake_pool_accounts let error = stake_pool_accounts
.add_validator_stake_account( .add_validator_to_pool(
&mut banks_client, &mut banks_client,
&payer, &payer,
&recent_blockhash, &recent_blockhash,
@ -109,18 +109,17 @@ async fn test_add_validator_stake_account() {
assert_eq!(pool_fee_token_balance, 0); // No fee when adding validator stake accounts assert_eq!(pool_fee_token_balance, 0); // No fee when adding validator stake accounts
// Check if validator account was added to the list // Check if validator account was added to the list
let validator_stake_list = get_account( let validator_list = get_account(
&mut banks_client, &mut banks_client,
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
) )
.await; .await;
let validator_stake_list = let validator_list =
try_from_slice_unchecked::<state::ValidatorStakeList>(validator_stake_list.data.as_slice()) try_from_slice_unchecked::<state::ValidatorList>(validator_list.data.as_slice()).unwrap();
.unwrap();
assert_eq!( assert_eq!(
validator_stake_list, validator_list,
state::ValidatorStakeList { state::ValidatorList {
account_type: state::AccountType::ValidatorStakeList, account_type: state::AccountType::ValidatorList,
max_validators: stake_pool_accounts.max_validators, max_validators: stake_pool_accounts.max_validators,
validators: vec![state::ValidatorStakeInfo { validators: vec![state::ValidatorStakeInfo {
validator_account: user_stake.vote.pubkey(), validator_account: user_stake.vote.pubkey(),
@ -149,7 +148,7 @@ async fn test_add_validator_stake_account() {
} }
#[tokio::test] #[tokio::test]
async fn test_add_validator_stake_account_with_wrong_token_program_id() { async fn test_add_validator_to_pool_with_wrong_token_program_id() {
let ( let (
mut banks_client, mut banks_client,
payer, payer,
@ -160,13 +159,13 @@ async fn test_add_validator_stake_account_with_wrong_token_program_id() {
) = setup().await; ) = setup().await;
let mut transaction = Transaction::new_with_payer( let mut transaction = Transaction::new_with_payer(
&[instruction::add_validator_stake_account( &[instruction::add_validator_to_pool(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.owner.pubkey(),
&stake_pool_accounts.deposit_authority, &stake_pool_accounts.deposit_authority,
&stake_pool_accounts.withdraw_authority, &stake_pool_accounts.withdraw_authority,
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
&user_stake.stake_account, &user_stake.stake_account,
&user_pool_account.pubkey(), &user_pool_account.pubkey(),
&stake_pool_accounts.pool_mint.pubkey(), &stake_pool_accounts.pool_mint.pubkey(),
@ -192,7 +191,7 @@ async fn test_add_validator_stake_account_with_wrong_token_program_id() {
} }
#[tokio::test] #[tokio::test]
async fn test_add_validator_stake_account_with_wrong_pool_mint_account() { async fn test_add_validator_to_pool_with_wrong_pool_mint_account() {
let ( let (
mut banks_client, mut banks_client,
payer, payer,
@ -205,13 +204,13 @@ async fn test_add_validator_stake_account_with_wrong_pool_mint_account() {
let wrong_pool_mint = Keypair::new(); let wrong_pool_mint = Keypair::new();
let mut transaction = Transaction::new_with_payer( let mut transaction = Transaction::new_with_payer(
&[instruction::add_validator_stake_account( &[instruction::add_validator_to_pool(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.owner.pubkey(),
&stake_pool_accounts.deposit_authority, &stake_pool_accounts.deposit_authority,
&stake_pool_accounts.withdraw_authority, &stake_pool_accounts.withdraw_authority,
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
&user_stake.stake_account, &user_stake.stake_account,
&user_pool_account.pubkey(), &user_pool_account.pubkey(),
&wrong_pool_mint.pubkey(), &wrong_pool_mint.pubkey(),
@ -241,7 +240,7 @@ async fn test_add_validator_stake_account_with_wrong_pool_mint_account() {
} }
#[tokio::test] #[tokio::test]
async fn test_add_validator_stake_account_with_wrong_validator_stake_list_account() { async fn test_add_validator_to_pool_with_wrong_validator_list_account() {
let ( let (
mut banks_client, mut banks_client,
payer, payer,
@ -251,16 +250,16 @@ async fn test_add_validator_stake_account_with_wrong_validator_stake_list_accoun
user_pool_account, user_pool_account,
) = setup().await; ) = setup().await;
let wrong_validator_stake_list = Keypair::new(); let wrong_validator_list = Keypair::new();
let mut transaction = Transaction::new_with_payer( let mut transaction = Transaction::new_with_payer(
&[instruction::add_validator_stake_account( &[instruction::add_validator_to_pool(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.owner.pubkey(),
&stake_pool_accounts.deposit_authority, &stake_pool_accounts.deposit_authority,
&stake_pool_accounts.withdraw_authority, &stake_pool_accounts.withdraw_authority,
&wrong_validator_stake_list.pubkey(), &wrong_validator_list.pubkey(),
&user_stake.stake_account, &user_stake.stake_account,
&user_pool_account.pubkey(), &user_pool_account.pubkey(),
&stake_pool_accounts.pool_mint.pubkey(), &stake_pool_accounts.pool_mint.pubkey(),
@ -301,7 +300,7 @@ async fn test_try_to_add_already_added_validator_stake_account() {
) = setup().await; ) = setup().await;
stake_pool_accounts stake_pool_accounts
.add_validator_stake_account( .add_validator_to_pool(
&mut banks_client, &mut banks_client,
&payer, &payer,
&recent_blockhash, &recent_blockhash,
@ -313,7 +312,7 @@ async fn test_try_to_add_already_added_validator_stake_account() {
let latest_blockhash = banks_client.get_recent_blockhash().await.unwrap(); let latest_blockhash = banks_client.get_recent_blockhash().await.unwrap();
let transaction_error = stake_pool_accounts let transaction_error = stake_pool_accounts
.add_validator_stake_account( .add_validator_to_pool(
&mut banks_client, &mut banks_client,
&payer, &payer,
&latest_blockhash, &latest_blockhash,
@ -336,7 +335,7 @@ async fn test_try_to_add_already_added_validator_stake_account() {
} }
#[tokio::test] #[tokio::test]
async fn test_not_owner_try_to_add_validator_stake_account() { async fn test_not_owner_try_to_add_validator_to_pool() {
let ( let (
mut banks_client, mut banks_client,
payer, payer,
@ -349,13 +348,13 @@ async fn test_not_owner_try_to_add_validator_stake_account() {
let malicious = Keypair::new(); let malicious = Keypair::new();
let mut transaction = Transaction::new_with_payer( let mut transaction = Transaction::new_with_payer(
&[instruction::add_validator_stake_account( &[instruction::add_validator_to_pool(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&malicious.pubkey(), &malicious.pubkey(),
&stake_pool_accounts.deposit_authority, &stake_pool_accounts.deposit_authority,
&stake_pool_accounts.withdraw_authority, &stake_pool_accounts.withdraw_authority,
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
&user_stake.stake_account, &user_stake.stake_account,
&user_pool_account.pubkey(), &user_pool_account.pubkey(),
&stake_pool_accounts.pool_mint.pubkey(), &stake_pool_accounts.pool_mint.pubkey(),
@ -385,7 +384,7 @@ async fn test_not_owner_try_to_add_validator_stake_account() {
} }
#[tokio::test] #[tokio::test]
async fn test_not_owner_try_to_add_validator_stake_account_without_signature() { async fn test_not_owner_try_to_add_validator_to_pool_without_signature() {
let ( let (
mut banks_client, mut banks_client,
payer, payer,
@ -400,7 +399,7 @@ async fn test_not_owner_try_to_add_validator_stake_account_without_signature() {
AccountMeta::new_readonly(stake_pool_accounts.owner.pubkey(), false), AccountMeta::new_readonly(stake_pool_accounts.owner.pubkey(), false),
AccountMeta::new_readonly(stake_pool_accounts.deposit_authority, false), AccountMeta::new_readonly(stake_pool_accounts.deposit_authority, false),
AccountMeta::new_readonly(stake_pool_accounts.withdraw_authority, false), AccountMeta::new_readonly(stake_pool_accounts.withdraw_authority, false),
AccountMeta::new(stake_pool_accounts.validator_stake_list.pubkey(), false), AccountMeta::new(stake_pool_accounts.validator_list.pubkey(), false),
AccountMeta::new(user_stake.stake_account, false), AccountMeta::new(user_stake.stake_account, false),
AccountMeta::new(user_pool_account.pubkey(), false), AccountMeta::new(user_pool_account.pubkey(), false),
AccountMeta::new(stake_pool_accounts.pool_mint.pubkey(), false), AccountMeta::new(stake_pool_accounts.pool_mint.pubkey(), false),
@ -412,7 +411,7 @@ async fn test_not_owner_try_to_add_validator_stake_account_without_signature() {
let instruction = Instruction { let instruction = Instruction {
program_id: id(), program_id: id(),
accounts, accounts,
data: instruction::StakePoolInstruction::AddValidatorStakeAccount data: instruction::StakePoolInstruction::AddValidatorToPool
.try_to_vec() .try_to_vec()
.unwrap(), .unwrap(),
}; };
@ -438,7 +437,7 @@ async fn test_not_owner_try_to_add_validator_stake_account_without_signature() {
} }
#[tokio::test] #[tokio::test]
async fn test_add_validator_stake_account_when_stake_acc_not_in_stake_state() { async fn test_add_validator_to_pool_when_stake_acc_not_in_stake_state() {
let (mut banks_client, payer, recent_blockhash) = program_test().start().await; let (mut banks_client, payer, recent_blockhash) = program_test().start().await;
let stake_pool_accounts = StakePoolAccounts::new(); let stake_pool_accounts = StakePoolAccounts::new();
stake_pool_accounts stake_pool_accounts
@ -478,7 +477,7 @@ async fn test_add_validator_stake_account_when_stake_acc_not_in_stake_state() {
.unwrap(); .unwrap();
let transaction_error = stake_pool_accounts let transaction_error = stake_pool_accounts
.add_validator_stake_account( .add_validator_to_pool(
&mut banks_client, &mut banks_client,
&payer, &payer,
&recent_blockhash, &recent_blockhash,
@ -501,7 +500,7 @@ async fn test_add_validator_stake_account_when_stake_acc_not_in_stake_state() {
} }
#[tokio::test] #[tokio::test]
async fn test_add_validator_stake_account_with_wrong_stake_program_id() { async fn test_add_validator_to_pool_with_wrong_stake_program_id() {
let ( let (
mut banks_client, mut banks_client,
payer, payer,
@ -514,13 +513,13 @@ async fn test_add_validator_stake_account_with_wrong_stake_program_id() {
let wrong_stake_program = Keypair::new(); let wrong_stake_program = Keypair::new();
let mut transaction = Transaction::new_with_payer( let mut transaction = Transaction::new_with_payer(
&[instruction::add_validator_stake_account( &[instruction::add_validator_to_pool(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.owner.pubkey(),
&stake_pool_accounts.deposit_authority, &stake_pool_accounts.deposit_authority,
&stake_pool_accounts.withdraw_authority, &stake_pool_accounts.withdraw_authority,
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
&user_stake.stake_account, &user_stake.stake_account,
&user_pool_account.pubkey(), &user_pool_account.pubkey(),
&stake_pool_accounts.pool_mint.pubkey(), &stake_pool_accounts.pool_mint.pubkey(),
@ -581,7 +580,7 @@ async fn test_add_too_many_validator_stake_accounts() {
.unwrap(); .unwrap();
let error = stake_pool_accounts let error = stake_pool_accounts
.add_validator_stake_account( .add_validator_to_pool(
&mut banks_client, &mut banks_client,
&payer, &payer,
&recent_blockhash, &recent_blockhash,
@ -599,7 +598,7 @@ async fn test_add_too_many_validator_stake_accounts() {
.create_and_delegate(&mut banks_client, &payer, &recent_blockhash) .create_and_delegate(&mut banks_client, &payer, &recent_blockhash)
.await; .await;
let error = stake_pool_accounts let error = stake_pool_accounts
.add_validator_stake_account( .add_validator_to_pool(
&mut banks_client, &mut banks_client,
&payer, &payer,
&recent_blockhash, &recent_blockhash,
@ -616,7 +615,7 @@ async fn test_add_too_many_validator_stake_accounts() {
} }
#[tokio::test] #[tokio::test]
async fn test_add_validator_stake_account_to_unupdated_stake_pool() {} // TODO async fn test_add_validator_to_pool_to_unupdated_stake_pool() {} // TODO
#[tokio::test] #[tokio::test]
async fn test_add_validator_stake_account_with_uninitialized_validator_stake_list_account() {} // TODO async fn test_add_validator_to_pool_with_uninitialized_validator_list_account() {} // TODO

View File

@ -62,7 +62,7 @@ async fn setup() -> (
.unwrap(); .unwrap();
let error = stake_pool_accounts let error = stake_pool_accounts
.add_validator_stake_account( .add_validator_to_pool(
&mut banks_client, &mut banks_client,
&payer, &payer,
&recent_blockhash, &recent_blockhash,
@ -84,7 +84,7 @@ async fn setup() -> (
} }
#[tokio::test] #[tokio::test]
async fn test_remove_validator_stake_account() { async fn test_remove_validator_from_pool() {
let ( let (
mut banks_client, mut banks_client,
payer, payer,
@ -109,7 +109,7 @@ async fn test_remove_validator_stake_account() {
let new_authority = Pubkey::new_unique(); let new_authority = Pubkey::new_unique();
let error = stake_pool_accounts let error = stake_pool_accounts
.remove_validator_stake_account( .remove_validator_from_pool(
&mut banks_client, &mut banks_client,
&payer, &payer,
&recent_blockhash, &recent_blockhash,
@ -125,18 +125,17 @@ async fn test_remove_validator_stake_account() {
assert_eq!(tokens_left, 0); assert_eq!(tokens_left, 0);
// Check if account was removed from the list of stake accounts // Check if account was removed from the list of stake accounts
let validator_stake_list = get_account( let validator_list = get_account(
&mut banks_client, &mut banks_client,
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
) )
.await; .await;
let validator_stake_list = let validator_list =
try_from_slice_unchecked::<state::ValidatorStakeList>(validator_stake_list.data.as_slice()) try_from_slice_unchecked::<state::ValidatorList>(validator_list.data.as_slice()).unwrap();
.unwrap();
assert_eq!( assert_eq!(
validator_stake_list, validator_list,
state::ValidatorStakeList { state::ValidatorList {
account_type: state::AccountType::ValidatorStakeList, account_type: state::AccountType::ValidatorList,
max_validators: stake_pool_accounts.max_validators, max_validators: stake_pool_accounts.max_validators,
validators: vec![] validators: vec![]
} }
@ -155,7 +154,7 @@ async fn test_remove_validator_stake_account() {
} }
#[tokio::test] #[tokio::test]
async fn test_remove_validator_stake_account_with_wrong_stake_program_id() { async fn test_remove_validator_from_pool_with_wrong_stake_program_id() {
let ( let (
mut banks_client, mut banks_client,
payer, payer,
@ -170,13 +169,13 @@ async fn test_remove_validator_stake_account_with_wrong_stake_program_id() {
let new_authority = Pubkey::new_unique(); let new_authority = Pubkey::new_unique();
let mut transaction = Transaction::new_with_payer( let mut transaction = Transaction::new_with_payer(
&[instruction::remove_validator_stake_account( &[instruction::remove_validator_from_pool(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.owner.pubkey(),
&stake_pool_accounts.withdraw_authority, &stake_pool_accounts.withdraw_authority,
&new_authority, &new_authority,
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
&user_stake.stake_account, &user_stake.stake_account,
&user_pool_account.pubkey(), &user_pool_account.pubkey(),
&stake_pool_accounts.pool_mint.pubkey(), &stake_pool_accounts.pool_mint.pubkey(),
@ -205,7 +204,7 @@ async fn test_remove_validator_stake_account_with_wrong_stake_program_id() {
} }
#[tokio::test] #[tokio::test]
async fn test_remove_validator_stake_account_with_wrong_token_program_id() { async fn test_remove_validator_from_pool_with_wrong_token_program_id() {
let ( let (
mut banks_client, mut banks_client,
payer, payer,
@ -220,13 +219,13 @@ async fn test_remove_validator_stake_account_with_wrong_token_program_id() {
let new_authority = Pubkey::new_unique(); let new_authority = Pubkey::new_unique();
let mut transaction = Transaction::new_with_payer( let mut transaction = Transaction::new_with_payer(
&[instruction::remove_validator_stake_account( &[instruction::remove_validator_from_pool(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.owner.pubkey(),
&stake_pool_accounts.withdraw_authority, &stake_pool_accounts.withdraw_authority,
&new_authority, &new_authority,
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
&user_stake.stake_account, &user_stake.stake_account,
&user_pool_account.pubkey(), &user_pool_account.pubkey(),
&stake_pool_accounts.pool_mint.pubkey(), &stake_pool_accounts.pool_mint.pubkey(),
@ -252,7 +251,7 @@ async fn test_remove_validator_stake_account_with_wrong_token_program_id() {
} }
#[tokio::test] #[tokio::test]
async fn test_remove_validator_stake_account_with_wrong_pool_mint_account() { async fn test_remove_validator_from_pool_with_wrong_pool_mint_account() {
let ( let (
mut banks_client, mut banks_client,
payer, payer,
@ -267,13 +266,13 @@ async fn test_remove_validator_stake_account_with_wrong_pool_mint_account() {
let new_authority = Pubkey::new_unique(); let new_authority = Pubkey::new_unique();
let mut transaction = Transaction::new_with_payer( let mut transaction = Transaction::new_with_payer(
&[instruction::remove_validator_stake_account( &[instruction::remove_validator_from_pool(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.owner.pubkey(),
&stake_pool_accounts.withdraw_authority, &stake_pool_accounts.withdraw_authority,
&new_authority, &new_authority,
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
&user_stake.stake_account, &user_stake.stake_account,
&user_pool_account.pubkey(), &user_pool_account.pubkey(),
&wrong_pool_mint.pubkey(), &wrong_pool_mint.pubkey(),
@ -303,7 +302,7 @@ async fn test_remove_validator_stake_account_with_wrong_pool_mint_account() {
} }
#[tokio::test] #[tokio::test]
async fn test_remove_validator_stake_account_with_wrong_validator_stake_list_account() { async fn test_remove_validator_from_pool_with_wrong_validator_list_account() {
let ( let (
mut banks_client, mut banks_client,
payer, payer,
@ -314,17 +313,17 @@ async fn test_remove_validator_stake_account_with_wrong_validator_stake_list_acc
_, _,
) = setup().await; ) = setup().await;
let wrong_validator_stake_list = Keypair::new(); let wrong_validator_list = Keypair::new();
let new_authority = Pubkey::new_unique(); let new_authority = Pubkey::new_unique();
let mut transaction = Transaction::new_with_payer( let mut transaction = Transaction::new_with_payer(
&[instruction::remove_validator_stake_account( &[instruction::remove_validator_from_pool(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.owner.pubkey(),
&stake_pool_accounts.withdraw_authority, &stake_pool_accounts.withdraw_authority,
&new_authority, &new_authority,
&wrong_validator_stake_list.pubkey(), &wrong_validator_list.pubkey(),
&user_stake.stake_account, &user_stake.stake_account,
&user_pool_account.pubkey(), &user_pool_account.pubkey(),
&stake_pool_accounts.pool_mint.pubkey(), &stake_pool_accounts.pool_mint.pubkey(),
@ -379,7 +378,7 @@ async fn test_remove_already_removed_validator_stake_account() {
let new_authority = Pubkey::new_unique(); let new_authority = Pubkey::new_unique();
let error = stake_pool_accounts let error = stake_pool_accounts
.remove_validator_stake_account( .remove_validator_from_pool(
&mut banks_client, &mut banks_client,
&payer, &payer,
&recent_blockhash, &recent_blockhash,
@ -393,7 +392,7 @@ async fn test_remove_already_removed_validator_stake_account() {
let latest_blockhash = banks_client.get_recent_blockhash().await.unwrap(); let latest_blockhash = banks_client.get_recent_blockhash().await.unwrap();
let transaction_error = stake_pool_accounts let transaction_error = stake_pool_accounts
.remove_validator_stake_account( .remove_validator_from_pool(
&mut banks_client, &mut banks_client,
&payer, &payer,
&latest_blockhash, &latest_blockhash,
@ -419,7 +418,7 @@ async fn test_remove_already_removed_validator_stake_account() {
} }
#[tokio::test] #[tokio::test]
async fn test_not_owner_try_to_remove_validator_stake_account() { async fn test_not_owner_try_to_remove_validator_from_pool() {
let ( let (
mut banks_client, mut banks_client,
payer, payer,
@ -434,13 +433,13 @@ async fn test_not_owner_try_to_remove_validator_stake_account() {
let new_authority = Pubkey::new_unique(); let new_authority = Pubkey::new_unique();
let mut transaction = Transaction::new_with_payer( let mut transaction = Transaction::new_with_payer(
&[instruction::remove_validator_stake_account( &[instruction::remove_validator_from_pool(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&malicious.pubkey(), &malicious.pubkey(),
&stake_pool_accounts.withdraw_authority, &stake_pool_accounts.withdraw_authority,
&new_authority, &new_authority,
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
&user_stake.stake_account, &user_stake.stake_account,
&user_pool_account.pubkey(), &user_pool_account.pubkey(),
&stake_pool_accounts.pool_mint.pubkey(), &stake_pool_accounts.pool_mint.pubkey(),
@ -470,7 +469,7 @@ async fn test_not_owner_try_to_remove_validator_stake_account() {
} }
#[tokio::test] #[tokio::test]
async fn test_not_owner_try_to_remove_validator_stake_account_without_signature() { async fn test_not_owner_try_to_remove_validator_from_pool_without_signature() {
let ( let (
mut banks_client, mut banks_client,
payer, payer,
@ -488,7 +487,7 @@ async fn test_not_owner_try_to_remove_validator_stake_account_without_signature(
AccountMeta::new_readonly(stake_pool_accounts.owner.pubkey(), false), AccountMeta::new_readonly(stake_pool_accounts.owner.pubkey(), false),
AccountMeta::new_readonly(stake_pool_accounts.withdraw_authority, false), AccountMeta::new_readonly(stake_pool_accounts.withdraw_authority, false),
AccountMeta::new_readonly(new_authority, false), AccountMeta::new_readonly(new_authority, false),
AccountMeta::new(stake_pool_accounts.validator_stake_list.pubkey(), false), AccountMeta::new(stake_pool_accounts.validator_list.pubkey(), false),
AccountMeta::new(user_stake.stake_account, false), AccountMeta::new(user_stake.stake_account, false),
AccountMeta::new(user_pool_account.pubkey(), false), AccountMeta::new(user_pool_account.pubkey(), false),
AccountMeta::new(stake_pool_accounts.pool_mint.pubkey(), false), AccountMeta::new(stake_pool_accounts.pool_mint.pubkey(), false),
@ -499,7 +498,7 @@ async fn test_not_owner_try_to_remove_validator_stake_account_without_signature(
let instruction = Instruction { let instruction = Instruction {
program_id: id(), program_id: id(),
accounts, accounts,
data: instruction::StakePoolInstruction::RemoveValidatorStakeAccount data: instruction::StakePoolInstruction::RemoveValidatorFromPool
.try_to_vec() .try_to_vec()
.unwrap(), .unwrap(),
}; };
@ -525,7 +524,7 @@ async fn test_not_owner_try_to_remove_validator_stake_account_without_signature(
} }
#[tokio::test] #[tokio::test]
async fn test_remove_validator_stake_account_when_stake_acc_not_in_stake_state() { async fn test_remove_validator_from_pool_when_stake_acc_not_in_stake_state() {
let (mut banks_client, payer, recent_blockhash) = program_test().start().await; let (mut banks_client, payer, recent_blockhash) = program_test().start().await;
let stake_pool_accounts = StakePoolAccounts::new(); let stake_pool_accounts = StakePoolAccounts::new();
stake_pool_accounts stake_pool_accounts
@ -567,7 +566,7 @@ async fn test_remove_validator_stake_account_when_stake_acc_not_in_stake_state()
let new_authority = Pubkey::new_unique(); let new_authority = Pubkey::new_unique();
let transaction_error = stake_pool_accounts let transaction_error = stake_pool_accounts
.remove_validator_stake_account( .remove_validator_from_pool(
&mut banks_client, &mut banks_client,
&payer, &payer,
&recent_blockhash, &recent_blockhash,
@ -591,7 +590,7 @@ async fn test_remove_validator_stake_account_when_stake_acc_not_in_stake_state()
} }
#[tokio::test] #[tokio::test]
async fn test_remove_validator_stake_account_from_unupdated_stake_pool() {} // TODO async fn test_remove_validator_from_pool_from_unupdated_stake_pool() {} // TODO
#[tokio::test] #[tokio::test]
async fn test_remove_validator_stake_account_with_uninitialized_validator_stake_list_account() {} // TODO async fn test_remove_validator_from_pool_with_uninitialized_validator_list_account() {} // TODO

View File

@ -34,7 +34,7 @@ async fn setup() -> (
.await .await
.unwrap(); .unwrap();
let validator_stake_account: ValidatorStakeAccount = simple_add_validator_stake_account( let validator_stake_account: ValidatorStakeAccount = simple_add_validator_to_pool(
&mut banks_client, &mut banks_client,
&payer, &payer,
&recent_blockhash, &recent_blockhash,
@ -105,15 +105,14 @@ async fn test_stake_pool_withdraw() {
state::StakePool::try_from_slice(&stake_pool_before.data.as_slice()).unwrap(); state::StakePool::try_from_slice(&stake_pool_before.data.as_slice()).unwrap();
// Save validator stake account record before withdrawal // Save validator stake account record before withdrawal
let validator_stake_list = get_account( let validator_list = get_account(
&mut banks_client, &mut banks_client,
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
) )
.await; .await;
let validator_stake_list = let validator_list =
try_from_slice_unchecked::<state::ValidatorStakeList>(validator_stake_list.data.as_slice()) try_from_slice_unchecked::<state::ValidatorList>(validator_list.data.as_slice()).unwrap();
.unwrap(); let validator_stake_item_before = validator_list
let validator_stake_item_before = validator_stake_list
.find(&validator_stake_account.vote.pubkey()) .find(&validator_stake_account.vote.pubkey())
.unwrap(); .unwrap();
@ -149,15 +148,14 @@ async fn test_stake_pool_withdraw() {
); );
// Check validator stake list storage // Check validator stake list storage
let validator_stake_list = get_account( let validator_list = get_account(
&mut banks_client, &mut banks_client,
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
) )
.await; .await;
let validator_stake_list = let validator_list =
try_from_slice_unchecked::<state::ValidatorStakeList>(validator_stake_list.data.as_slice()) try_from_slice_unchecked::<state::ValidatorList>(validator_list.data.as_slice()).unwrap();
.unwrap(); let validator_stake_item = validator_list
let validator_stake_item = validator_stake_list
.find(&validator_stake_account.vote.pubkey()) .find(&validator_stake_account.vote.pubkey())
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
@ -212,7 +210,7 @@ async fn test_stake_pool_withdraw_with_wrong_stake_program() {
&[instruction::withdraw( &[instruction::withdraw(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
&stake_pool_accounts.withdraw_authority, &stake_pool_accounts.withdraw_authority,
&validator_stake_account.stake_account, &validator_stake_account.stake_account,
&user_stake_recipient.pubkey(), &user_stake_recipient.pubkey(),
@ -308,7 +306,7 @@ async fn test_stake_pool_withdraw_with_wrong_token_program_id() {
&[instruction::withdraw( &[instruction::withdraw(
&id(), &id(),
&stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.stake_pool.pubkey(),
&stake_pool_accounts.validator_stake_list.pubkey(), &stake_pool_accounts.validator_list.pubkey(),
&stake_pool_accounts.withdraw_authority, &stake_pool_accounts.withdraw_authority,
&validator_stake_account.stake_account, &validator_stake_account.stake_account,
&user_stake_recipient.pubkey(), &user_stake_recipient.pubkey(),
@ -338,7 +336,7 @@ async fn test_stake_pool_withdraw_with_wrong_token_program_id() {
} }
#[tokio::test] #[tokio::test]
async fn test_stake_pool_withdraw_with_wrong_validator_stake_list() { async fn test_stake_pool_withdraw_with_wrong_validator_list() {
let ( let (
mut banks_client, mut banks_client,
payer, payer,
@ -353,7 +351,7 @@ async fn test_stake_pool_withdraw_with_wrong_validator_stake_list() {
let user_stake_recipient = Keypair::new(); let user_stake_recipient = Keypair::new();
let new_authority = Pubkey::new_unique(); let new_authority = Pubkey::new_unique();
stake_pool_accounts.validator_stake_list = Keypair::new(); stake_pool_accounts.validator_list = Keypair::new();
let transaction_error = stake_pool_accounts let transaction_error = stake_pool_accounts
.withdraw_stake( .withdraw_stake(
@ -678,7 +676,7 @@ async fn test_stake_pool_withdraw_token_delegate_was_not_setup() {
.await .await
.unwrap(); .unwrap();
let validator_stake_account: ValidatorStakeAccount = simple_add_validator_stake_account( let validator_stake_account: ValidatorStakeAccount = simple_add_validator_to_pool(
&mut banks_client, &mut banks_client,
&payer, &payer,
&recent_blockhash, &recent_blockhash,
@ -746,7 +744,7 @@ async fn test_stake_pool_withdraw_with_low_delegation() {
.await .await
.unwrap(); .unwrap();
let validator_stake_account: ValidatorStakeAccount = simple_add_validator_stake_account( let validator_stake_account: ValidatorStakeAccount = simple_add_validator_to_pool(
&mut banks_client, &mut banks_client,
&payer, &payer,
&recent_blockhash, &recent_blockhash,