Skip to content

Commit

Permalink
stake-pool: Also set the sol deposit authority on init (solana-labs#2532
Browse files Browse the repository at this point in the history
)
  • Loading branch information
joncinque authored Oct 19, 2021
1 parent 675d65b commit 4ab60e6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
17 changes: 12 additions & 5 deletions stake-pool/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,17 @@ impl Processor {
return Err(StakePoolError::WrongAccountMint.into());
}

let stake_deposit_authority = match next_account_info(account_info_iter) {
Ok(stake_deposit_authority_info) => *stake_deposit_authority_info.key,
Err(_) => find_deposit_authority_program_address(program_id, stake_pool_info.key).0,
};
let (stake_deposit_authority, sol_deposit_authority) =
match next_account_info(account_info_iter) {
Ok(deposit_authority_info) => (
*deposit_authority_info.key,
Some(*deposit_authority_info.key),
),
Err(_) => (
find_deposit_authority_program_address(program_id, stake_pool_info.key).0,
None,
),
};
let (withdraw_authority_key, stake_withdraw_bump_seed) =
crate::find_withdraw_authority_program_address(program_id, stake_pool_info.key);

Expand Down Expand Up @@ -676,7 +683,7 @@ impl Processor {
stake_pool.stake_withdrawal_fee = withdrawal_fee;
stake_pool.next_stake_withdrawal_fee = None;
stake_pool.stake_referral_fee = referral_fee;
stake_pool.sol_deposit_authority = None;
stake_pool.sol_deposit_authority = sol_deposit_authority;
stake_pool.sol_deposit_fee = deposit_fee;
stake_pool.sol_referral_fee = referral_fee;
stake_pool.sol_withdraw_authority = None;
Expand Down
8 changes: 4 additions & 4 deletions stake-pool/program/tests/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,11 +794,11 @@ async fn fail_with_uninitialized_validator_list() {} // TODO
async fn fail_with_out_of_dated_pool_balances() {} // TODO

#[tokio::test]
async fn success_with_stake_deposit_authority() {
async fn success_with_deposit_authority() {
let (mut banks_client, payer, recent_blockhash) = program_test().start().await;
let stake_deposit_authority = Keypair::new();
let stake_pool_accounts =
StakePoolAccounts::new_with_stake_deposit_authority(stake_deposit_authority);
StakePoolAccounts::new_with_deposit_authority(stake_deposit_authority);
stake_pool_accounts
.initialize_stake_pool(&mut banks_client, &payer, &recent_blockhash, 1)
.await
Expand Down Expand Up @@ -876,11 +876,11 @@ async fn success_with_stake_deposit_authority() {
}

#[tokio::test]
async fn fail_without_stake_deposit_authority_signature() {
async fn fail_without_deposit_authority_signature() {
let (mut banks_client, payer, recent_blockhash) = program_test().start().await;
let stake_deposit_authority = Keypair::new();
let mut stake_pool_accounts =
StakePoolAccounts::new_with_stake_deposit_authority(stake_deposit_authority);
StakePoolAccounts::new_with_deposit_authority(stake_deposit_authority);
stake_pool_accounts
.initialize_stake_pool(&mut banks_client, &payer, &recent_blockhash, 1)
.await
Expand Down
2 changes: 1 addition & 1 deletion stake-pool/program/tests/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ impl StakePoolAccounts {
}
}

pub fn new_with_stake_deposit_authority(stake_deposit_authority: Keypair) -> Self {
pub fn new_with_deposit_authority(stake_deposit_authority: Keypair) -> Self {
let mut stake_pool_accounts = Self::new();
stake_pool_accounts.stake_deposit_authority = stake_deposit_authority.pubkey();
stake_pool_accounts.stake_deposit_authority_keypair = Some(stake_deposit_authority);
Expand Down
14 changes: 6 additions & 8 deletions stake-pool/program/tests/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1275,11 +1275,11 @@ async fn fail_with_bad_reserve() {
}

#[tokio::test]
async fn success_with_required_stake_deposit_authority() {
async fn success_with_deposit_authority() {
let (mut banks_client, payer, recent_blockhash) = program_test().start().await;
let stake_deposit_authority = Keypair::new();
let stake_pool_accounts =
StakePoolAccounts::new_with_stake_deposit_authority(stake_deposit_authority);
let deposit_authority = Keypair::new();
let stake_pool_accounts = StakePoolAccounts::new_with_deposit_authority(deposit_authority);
let deposit_authority = stake_pool_accounts.stake_deposit_authority;
stake_pool_accounts
.initialize_stake_pool(&mut banks_client, &payer, &recent_blockhash, 1)
.await
Expand All @@ -1290,8 +1290,6 @@ async fn success_with_required_stake_deposit_authority() {
get_account(&mut banks_client, &stake_pool_accounts.stake_pool.pubkey()).await;
let stake_pool =
try_from_slice_unchecked::<state::StakePool>(stake_pool_account.data.as_slice()).unwrap();
assert_eq!(
stake_pool.stake_deposit_authority,
stake_pool_accounts.stake_deposit_authority
);
assert_eq!(stake_pool.stake_deposit_authority, deposit_authority);
assert_eq!(stake_pool.sol_deposit_authority.unwrap(), deposit_authority);
}

0 comments on commit 4ab60e6

Please sign in to comment.