From 4ab60e6794c80f617b9f4fb1dd9b56822ade53ab Mon Sep 17 00:00:00 2001 From: Jon Cinque Date: Wed, 20 Oct 2021 01:45:00 +0200 Subject: [PATCH] stake-pool: Also set the sol deposit authority on init (#2532) --- stake-pool/program/src/processor.rs | 17 ++++++++++++----- stake-pool/program/tests/deposit.rs | 8 ++++---- stake-pool/program/tests/helpers/mod.rs | 2 +- stake-pool/program/tests/initialize.rs | 14 ++++++-------- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/stake-pool/program/src/processor.rs b/stake-pool/program/src/processor.rs index 4f6b6079f2e..948d2450427 100644 --- a/stake-pool/program/src/processor.rs +++ b/stake-pool/program/src/processor.rs @@ -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); @@ -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; diff --git a/stake-pool/program/tests/deposit.rs b/stake-pool/program/tests/deposit.rs index 754a2a8d216..0d84b64d6fd 100644 --- a/stake-pool/program/tests/deposit.rs +++ b/stake-pool/program/tests/deposit.rs @@ -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 @@ -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 diff --git a/stake-pool/program/tests/helpers/mod.rs b/stake-pool/program/tests/helpers/mod.rs index 54a0a82b8d5..37bc091639c 100644 --- a/stake-pool/program/tests/helpers/mod.rs +++ b/stake-pool/program/tests/helpers/mod.rs @@ -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); diff --git a/stake-pool/program/tests/initialize.rs b/stake-pool/program/tests/initialize.rs index 7aa03f52894..6fd44848c92 100644 --- a/stake-pool/program/tests/initialize.rs +++ b/stake-pool/program/tests/initialize.rs @@ -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 @@ -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::(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); }