From e25846e1adfeb33cce79ed48ed7b274091dc26e7 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Tue, 4 Aug 2020 20:46:25 -0600 Subject: [PATCH] Add failing test for unsane tx in RPC preflight --- core/src/rpc.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/core/src/rpc.rs b/core/src/rpc.rs index 5af7f348bf..677d684bcb 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -3483,8 +3483,9 @@ pub mod tests { ); SendTransactionService::new(tpu_address, &bank_forks, &exit, receiver); - let bad_transaction = - system_transaction::transfer(&Keypair::new(), &Pubkey::default(), 42, Hash::default()); + let keypair = Keypair::new(); + let mut bad_transaction = + system_transaction::transfer(&keypair, &Pubkey::default(), 42, Hash::default()); // sendTransaction will fail because the blockhash is invalid let req = format!( @@ -3499,7 +3500,21 @@ 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); + let req = format!( + r#"{{"jsonrpc":"2.0","id":1,"method":"sendTransaction","params":["{}"]}}"#, + bs58::encode(serialize(&bad_transaction).unwrap()).into_string() + ); + let res = io.handle_request_sync(&req, meta.clone()); + assert_eq!( + res, + Some( + r#"{"jsonrpc":"2.0","error":{"code":-32002,"message":"Transaction simulation failed: Transaction failed to sanitize accounts offsets correctly"},"id":1}"#.to_string(), + ) + ); let mut bad_transaction = system_transaction::transfer(&Keypair::new(), &Pubkey::default(), 42, recent_blockhash);