From 14339dec0a960e8161d1165b6a8e5cfb73e78f23 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Tue, 4 Aug 2020 21:49:37 -0600 Subject: [PATCH] Harden RPC preflight test inputs --- core/src/rpc.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/src/rpc.rs b/core/src/rpc.rs index 677d684bcb..f4d1dc2ebb 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -3458,7 +3458,7 @@ pub mod tests { let ledger_path = get_tmp_ledger_path!(); let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::default())); - let bank_forks = new_bank_forks().0; + let (bank_forks, mint_keypair, ..) = new_bank_forks(); let health = RpcHealth::stub(); // Freeze bank 0 to prevent a panic in `run_transaction_simulation()` @@ -3483,9 +3483,8 @@ pub mod tests { ); SendTransactionService::new(tpu_address, &bank_forks, &exit, receiver); - let keypair = Keypair::new(); let mut bad_transaction = - system_transaction::transfer(&keypair, &Pubkey::default(), 42, Hash::default()); + system_transaction::transfer(&mint_keypair, &Pubkey::new_rand(), 42, Hash::default()); // sendTransaction will fail because the blockhash is invalid let req = format!( @@ -3503,7 +3502,7 @@ pub mod tests { // sendTransaction will fail due to insanity bad_transaction.message.instructions[0].program_id_index = 255u8; let recent_blockhash = bank_forks.read().unwrap().root_bank().last_blockhash(); - bad_transaction.sign(&[&keypair], recent_blockhash); + bad_transaction.sign(&[&mint_keypair], recent_blockhash); let req = format!( r#"{{"jsonrpc":"2.0","id":1,"method":"sendTransaction","params":["{}"]}}"#, bs58::encode(serialize(&bad_transaction).unwrap()).into_string() @@ -3516,7 +3515,7 @@ pub mod tests { ) ); let mut bad_transaction = - system_transaction::transfer(&Keypair::new(), &Pubkey::default(), 42, recent_blockhash); + system_transaction::transfer(&mint_keypair, &Pubkey::new_rand(), 42, recent_blockhash); // sendTransaction will fail due to poor node health health.stub_set_health_status(Some(RpcHealthStatus::Behind));