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

Commit 24d54db

Browse files
authored
associated-token-account: Refresh blockhash more on flakey tests (#4216)
1 parent 68217f3 commit 24d54db

File tree

2 files changed

+62
-9
lines changed

2 files changed

+62
-9
lines changed

associated-token-account/program-test/tests/extended_mint.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ use {
2828
async fn test_associated_token_account_with_transfer_fees() {
2929
let wallet_sender = Keypair::new();
3030
let wallet_address_sender = wallet_sender.pubkey();
31-
let wallet_receiver = Keypair::new();
32-
let wallet_address_receiver = wallet_receiver.pubkey();
31+
let wallet_address_receiver = Pubkey::new_unique();
3332
let (mut banks_client, payer, recent_blockhash) =
3433
program_test_2022(Pubkey::new_unique(), true).start().await;
3534
let rent = banks_client.get_rent().await.unwrap();
@@ -86,6 +85,11 @@ async fn test_associated_token_account_with_transfer_fees() {
8685
transaction.sign(&[&payer], recent_blockhash);
8786
banks_client.process_transaction(transaction).await.unwrap();
8887

88+
let recent_blockhash = banks_client
89+
.get_new_latest_blockhash(&recent_blockhash)
90+
.await
91+
.unwrap();
92+
8993
let mut transaction = Transaction::new_with_payer(
9094
&[create_associated_token_account(
9195
&payer.pubkey(),
@@ -156,6 +160,11 @@ async fn test_associated_token_account_with_transfer_fees() {
156160
)
157161
);
158162

163+
let recent_blockhash = banks_client
164+
.get_new_latest_blockhash(&recent_blockhash)
165+
.await
166+
.unwrap();
167+
159168
// success
160169
let transfer_amount = 500;
161170
let fee = 50;

associated-token-account/program-test/tests/recover_nested.rs

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ async fn check_same_mint(context: &mut ProgramTestContext, program_id: &Pubkey)
175175
)
176176
.await;
177177

178+
context.last_blockhash = context
179+
.banks_client
180+
.get_new_latest_blockhash(&context.last_blockhash)
181+
.await
182+
.unwrap();
178183
let transaction = Transaction::new_signed_with_payer(
179184
&[instruction::recover_nested(
180185
&wallet.pubkey(),
@@ -233,6 +238,11 @@ async fn check_different_mints(context: &mut ProgramTestContext, program_id: &Pu
233238
let destination_token_address =
234239
create_associated_token_account(context, &wallet.pubkey(), &nested_mint, program_id).await;
235240

241+
context.last_blockhash = context
242+
.banks_client
243+
.get_new_latest_blockhash(&context.last_blockhash)
244+
.await
245+
.unwrap();
236246
let transaction = Transaction::new_signed_with_payer(
237247
&[instruction::recover_nested(
238248
&wallet.pubkey(),
@@ -291,6 +301,11 @@ async fn check_missing_wallet_signature(context: &mut ProgramTestContext, progra
291301

292302
let mut recover = instruction::recover_nested(&wallet.pubkey(), &mint, &mint, program_id);
293303
recover.accounts[5] = AccountMeta::new(wallet.pubkey(), false);
304+
context.last_blockhash = context
305+
.banks_client
306+
.get_new_latest_blockhash(&context.last_blockhash)
307+
.await
308+
.unwrap();
294309
let transaction = Transaction::new_signed_with_payer(
295310
&[recover],
296311
Some(&context.payer.pubkey()),
@@ -342,6 +357,11 @@ async fn check_wrong_signer(context: &mut ProgramTestContext, program_id: &Pubke
342357
)
343358
.await;
344359

360+
context.last_blockhash = context
361+
.banks_client
362+
.get_new_latest_blockhash(&context.last_blockhash)
363+
.await
364+
.unwrap();
345365
let transaction = Transaction::new_signed_with_payer(
346366
&[instruction::recover_nested(
347367
&wrong_wallet.pubkey(),
@@ -385,14 +405,19 @@ async fn fail_wrong_signer() {
385405

386406
async fn check_not_nested(context: &mut ProgramTestContext, program_id: &Pubkey) {
387407
let wallet = Keypair::new();
388-
let wrong_wallet = Keypair::new();
408+
let wrong_wallet = Pubkey::new_unique();
389409
let (mint, mint_authority) = create_mint(context, program_id).await;
390410

391411
let owner_associated_token_address =
392412
create_associated_token_account(context, &wallet.pubkey(), &mint, program_id).await;
393413
let nested_associated_token_address =
394-
create_associated_token_account(context, &wrong_wallet.pubkey(), &mint, program_id).await;
414+
create_associated_token_account(context, &wrong_wallet, &mint, program_id).await;
395415

416+
context.last_blockhash = context
417+
.banks_client
418+
.get_new_latest_blockhash(&context.last_blockhash)
419+
.await
420+
.unwrap();
396421
let transaction = Transaction::new_signed_with_payer(
397422
&[instruction::recover_nested(
398423
&wallet.pubkey(),
@@ -439,7 +464,7 @@ async fn check_wrong_address_derivation_owner(
439464
program_id: &Pubkey,
440465
) {
441466
let wallet = Keypair::new();
442-
let wrong_wallet = Keypair::new();
467+
let wrong_wallet = Pubkey::new_unique();
443468
let (mint, mint_authority) = create_mint(context, program_id).await;
444469

445470
let owner_associated_token_address =
@@ -453,9 +478,14 @@ async fn check_wrong_address_derivation_owner(
453478
.await;
454479

455480
let wrong_owner_associated_token_address =
456-
get_associated_token_address_with_program_id(&mint, &wrong_wallet.pubkey(), program_id);
481+
get_associated_token_address_with_program_id(&mint, &wrong_wallet, program_id);
457482
let mut recover = instruction::recover_nested(&wallet.pubkey(), &mint, &mint, program_id);
458483
recover.accounts[3] = AccountMeta::new(wrong_owner_associated_token_address, false);
484+
context.last_blockhash = context
485+
.banks_client
486+
.get_new_latest_blockhash(&context.last_blockhash)
487+
.await
488+
.unwrap();
459489
let transaction = Transaction::new_signed_with_payer(
460490
&[recover],
461491
Some(&context.payer.pubkey()),
@@ -506,6 +536,11 @@ async fn check_owner_account_does_not_exist(context: &mut ProgramTestContext, pr
506536
)
507537
.await;
508538

539+
context.last_blockhash = context
540+
.banks_client
541+
.get_new_latest_blockhash(&context.last_blockhash)
542+
.await
543+
.unwrap();
509544
let transaction = Transaction::new_signed_with_payer(
510545
&[instruction::recover_nested(
511546
&wallet.pubkey(),
@@ -559,6 +594,11 @@ async fn fail_wrong_spl_token_program() {
559594
)
560595
.await;
561596

597+
context.last_blockhash = context
598+
.banks_client
599+
.get_new_latest_blockhash(&context.last_blockhash)
600+
.await
601+
.unwrap();
562602
let transaction = Transaction::new_signed_with_payer(
563603
&[instruction::recover_nested(
564604
&wallet.pubkey(),
@@ -587,7 +627,7 @@ async fn fail_wrong_spl_token_program() {
587627
#[tokio::test]
588628
async fn fail_destination_not_wallet_ata() {
589629
let wallet = Keypair::new();
590-
let wrong_wallet = Keypair::new();
630+
let wrong_wallet = Pubkey::new_unique();
591631
let dummy_mint = Pubkey::new_unique();
592632
let pt = program_test_2022(dummy_mint, true);
593633
let program_id = spl_token_2022::id();
@@ -604,13 +644,17 @@ async fn fail_destination_not_wallet_ata() {
604644
)
605645
.await;
606646
let wrong_destination_associated_token_account_address =
607-
create_associated_token_account(&mut context, &wrong_wallet.pubkey(), &mint, &program_id)
608-
.await;
647+
create_associated_token_account(&mut context, &wrong_wallet, &mint, &program_id).await;
609648

610649
let mut recover = instruction::recover_nested(&wallet.pubkey(), &mint, &mint, &program_id);
611650
recover.accounts[2] =
612651
AccountMeta::new(wrong_destination_associated_token_account_address, false);
613652

653+
context.last_blockhash = context
654+
.banks_client
655+
.get_new_latest_blockhash(&context.last_blockhash)
656+
.await
657+
.unwrap();
614658
let transaction = Transaction::new_signed_with_payer(
615659
&[recover],
616660
Some(&context.payer.pubkey()),

0 commit comments

Comments
 (0)