Repository: solana-labs/solana-program-library
Pull request #6836 (2024-06-11 19:39:54)

test: ensure confidential_transfer using the latest blockhash
fix downstream project tests for: https://github.com/anza-xyz/agave/pull/1693


Patch:
diff --git a/stake-pool/cli/scripts/setup-stake-pool.sh b/stake-pool/cli/scripts/setup-stake-pool.sh
index d196a93fe..9bcb5b8b9 100755
--- a/stake-pool/cli/scripts/setup-stake-pool.sh
+++ b/stake-pool/cli/scripts/setup-stake-pool.sh
@@ -71,7 +71,16 @@ $spl_stake_pool \
   --reserve-keypair "$reserve_keyfile"
 
 set +ex
-echo "Depositing SOL into stake pool"
 stake_pool_pubkey=$(solana-keygen pubkey "$stake_pool_keyfile")
 set -ex
+
+echo "Creating token metadata"
+$spl_stake_pool \
+  create-token-metadata \
+  "$stake_pool_pubkey" \
+  NAME \
+  SYMBOL \
+  URI
+
+echo "Depositing SOL into stake pool"
 $spl_stake_pool deposit-sol "$stake_pool_pubkey" "$sol_amount"


Test patch:
diff --git a/stake-pool/cli/scripts/setup-test-validator.sh b/stake-pool/cli/scripts/setup-test-validator.sh
index c0414c6e8..073e9f018 100755
--- a/stake-pool/cli/scripts/setup-test-validator.sh
+++ b/stake-pool/cli/scripts/setup-test-validator.sh
@@ -16,14 +16,23 @@ create_keypair () {
 }
 
 setup_test_validator() {
-  solana-test-validator -c SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy -c EmiU8AQkB2sswTxVB6aCmsAJftoowZGGDXuytm6X65R3 --url devnet --slots-per-epoch 32 --quiet --reset &
+  solana-test-validator \
+    --clone-upgradeable-program SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy \
+    --clone-upgradeable-program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s \
+    --url mainnet-beta \
+    --slots-per-epoch 32 \
+    --quiet --reset &
   # Uncomment to use a locally built stake program
-  #solana-test-validator --bpf-program SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy ../../../target/deploy/spl_stake_pool.so --slots-per-epoch 32 --quiet --reset &
+  #solana-test-validator \
+  #  --bpf-program SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy ../../../target/deploy/spl_stake_pool.so \
+  #  --bpf-program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s ../../program/tests/fixtures/mpl_token_metadata.so \
+  #  --slots-per-epoch 32 \
+  #  --quiet --reset &
   pid=$!
   solana config set --url http://127.0.0.1:8899
   solana config set --commitment confirmed
   echo "waiting for solana-test-validator, pid: $pid"
-  sleep 5
+  sleep 15
 }
 
 create_vote_accounts () {
diff --git a/token/program-2022-test/tests/confidential_transfer_fee.rs b/token/program-2022-test/tests/confidential_transfer_fee.rs
index f2eb4086e..f45a4f259 100644
--- a/token/program-2022-test/tests/confidential_transfer_fee.rs
+++ b/token/program-2022-test/tests/confidential_transfer_fee.rs
@@ -867,11 +867,12 @@ async fn confidential_transfer_withdraw_withheld_tokens_from_mint_with_proof_con
             instruction_type.encode_verify_proof(Some(context_state_info), &proof_data),
         ];
 
+        let recent_blockhash = ctx.get_new_latest_blockhash().await.unwrap();
         let tx = Transaction::new_signed_with_payer(
             &instructions,
             Some(&ctx.payer.pubkey()),
             &[&ctx.payer, &context_state_account],
-            ctx.last_blockhash,
+            recent_blockhash,
         );
         ctx.banks_client.process_transaction(tx).await.unwrap();
     }
@@ -1034,11 +1035,12 @@ async fn confidential_transfer_withdraw_withheld_tokens_from_accounts_with_proof
             instruction_type.encode_verify_proof(Some(context_state_info), &proof_data),
         ];
 
+        let recent_blockhash = ctx.get_new_latest_blockhash().await.unwrap();
         let tx = Transaction::new_signed_with_payer(
             &instructions,
             Some(&ctx.payer.pubkey()),
             &[&ctx.payer, &context_state_account],
-            ctx.last_blockhash,
+            recent_blockhash,
         );
         ctx.banks_client.process_transaction(tx).await.unwrap();
     }