Skip to content

Commit

Permalink
Harden RPC preflight test inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
t-nelson authored and mergify[bot] committed Aug 5, 2020
1 parent 29b3265 commit 14339de
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions core/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()`
Expand All @@ -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!(
Expand All @@ -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()
Expand All @@ -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));
Expand Down

0 comments on commit 14339de

Please sign in to comment.