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

Commit 4bbfdab

Browse files
authored
stake-pool: Refresh blockhash more in another test (#3982)
1 parent fad5d58 commit 4bbfdab

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

stake-pool/program/tests/withdraw_with_fee.rs

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ async fn success_withdraw_all_fee_tokens() {
2424
tokens_to_withdraw,
2525
) = setup_for_withdraw(spl_token::id()).await;
2626

27+
let last_blockhash = context
28+
.banks_client
29+
.get_new_latest_blockhash(&context.last_blockhash)
30+
.await
31+
.unwrap();
32+
2733
// move tokens to fee account
2834
transfer_spl_tokens(
2935
&mut context.banks_client,
3036
&context.payer,
31-
&context.last_blockhash,
37+
&last_blockhash,
3238
&stake_pool_accounts.token_program_id,
3339
&deposit_info.pool_account.pubkey(),
3440
&stake_pool_accounts.pool_mint.pubkey(),
@@ -49,7 +55,7 @@ async fn success_withdraw_all_fee_tokens() {
4955
delegate_tokens(
5056
&mut context.banks_client,
5157
&context.payer,
52-
&context.last_blockhash,
58+
&last_blockhash,
5359
&stake_pool_accounts.token_program_id,
5460
&stake_pool_accounts.pool_fee_account.pubkey(),
5561
&stake_pool_accounts.manager,
@@ -63,7 +69,7 @@ async fn success_withdraw_all_fee_tokens() {
6369
.withdraw_stake(
6470
&mut context.banks_client,
6571
&context.payer,
66-
&context.last_blockhash,
72+
&last_blockhash,
6773
&user_stake_recipient.pubkey(),
6874
&user_transfer_authority,
6975
&stake_pool_accounts.pool_fee_account.pubkey(),
@@ -95,11 +101,17 @@ async fn success_empty_out_stake_with_fee() {
95101
tokens_to_withdraw,
96102
) = setup_for_withdraw(spl_token::id()).await;
97103

104+
let last_blockhash = context
105+
.banks_client
106+
.get_new_latest_blockhash(&context.last_blockhash)
107+
.await
108+
.unwrap();
109+
98110
// add another validator and deposit into it
99111
let other_validator_stake_account = simple_add_validator_to_pool(
100112
&mut context.banks_client,
101113
&context.payer,
102-
&context.last_blockhash,
114+
&last_blockhash,
103115
&stake_pool_accounts,
104116
None,
105117
)
@@ -108,7 +120,7 @@ async fn success_empty_out_stake_with_fee() {
108120
let other_deposit_info = simple_deposit_stake(
109121
&mut context.banks_client,
110122
&context.payer,
111-
&context.last_blockhash,
123+
&last_blockhash,
112124
&stake_pool_accounts,
113125
&other_validator_stake_account,
114126
TEST_STAKE_AMOUNT,
@@ -120,7 +132,7 @@ async fn success_empty_out_stake_with_fee() {
120132
transfer_spl_tokens(
121133
&mut context.banks_client,
122134
&context.payer,
123-
&context.last_blockhash,
135+
&last_blockhash,
124136
&stake_pool_accounts.token_program_id,
125137
&deposit_info.pool_account.pubkey(),
126138
&stake_pool_accounts.pool_mint.pubkey(),
@@ -137,11 +149,17 @@ async fn success_empty_out_stake_with_fee() {
137149
)
138150
.await;
139151

152+
let last_blockhash = context
153+
.banks_client
154+
.get_new_latest_blockhash(&last_blockhash)
155+
.await
156+
.unwrap();
157+
140158
let user_transfer_authority = Keypair::new();
141159
delegate_tokens(
142160
&mut context.banks_client,
143161
&context.payer,
144-
&context.last_blockhash,
162+
&last_blockhash,
145163
&stake_pool_accounts.token_program_id,
146164
&other_deposit_info.pool_account.pubkey(),
147165
&other_deposit_info.authority,
@@ -160,12 +178,9 @@ async fn success_empty_out_stake_with_fee() {
160178
let stake_state =
161179
deserialize::<stake::state::StakeState>(&validator_stake_account.data).unwrap();
162180
let meta = stake_state.meta().unwrap();
163-
let stake_minimum_delegation = stake_get_minimum_delegation(
164-
&mut context.banks_client,
165-
&context.payer,
166-
&context.last_blockhash,
167-
)
168-
.await;
181+
let stake_minimum_delegation =
182+
stake_get_minimum_delegation(&mut context.banks_client, &context.payer, &last_blockhash)
183+
.await;
169184
let lamports_to_withdraw =
170185
validator_stake_account.lamports - minimum_stake_lamports(&meta, stake_minimum_delegation);
171186
let stake_pool_account = get_account(
@@ -183,12 +198,17 @@ async fn success_empty_out_stake_with_fee() {
183198
let pool_tokens_to_withdraw =
184199
lamports_to_withdraw * inverse_fee.denominator / inverse_fee.numerator;
185200

201+
let last_blockhash = context
202+
.banks_client
203+
.get_new_latest_blockhash(&last_blockhash)
204+
.await
205+
.unwrap();
186206
let new_authority = Pubkey::new_unique();
187207
let error = stake_pool_accounts
188208
.withdraw_stake(
189209
&mut context.banks_client,
190210
&context.payer,
191-
&context.last_blockhash,
211+
&last_blockhash,
192212
&user_stake_recipient.pubkey(),
193213
&user_transfer_authority,
194214
&other_deposit_info.pool_account.pubkey(),

0 commit comments

Comments
 (0)