From e8e74ee009c0f22f122128c7daf677d0f26f09c0 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Wed, 29 Jul 2020 20:03:30 -0600 Subject: [PATCH] Add failing test for TX sent via RPC with no signatures (cherry picked from commit b962b2ce2d74bfb2e111253c5d1cbb28722770c1) --- core/src/rpc.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/core/src/rpc.rs b/core/src/rpc.rs index d4026562b9..80071ea7d2 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -3008,7 +3008,7 @@ pub mod tests { )), ); - let mut bad_transaction = + let bad_transaction = system_transaction::transfer(&Keypair::new(), &Pubkey::default(), 42, Hash::default()); // sendTransaction will fail because the blockhash is invalid @@ -3024,6 +3024,10 @@ pub mod tests { ) ); + let recent_blockhash = bank_forks.read().unwrap().root_bank().last_blockhash(); + let mut bad_transaction = + system_transaction::transfer(&Keypair::new(), &Pubkey::default(), 42, recent_blockhash); + // sendTransaction will fail due to poor node health health.stub_set_health_status(Some(RpcHealthStatus::Behind)); let req = format!( @@ -3060,13 +3064,28 @@ pub mod tests { r#"{{"jsonrpc":"2.0","id":1,"method":"sendTransaction","params":["{}", {{"skipPreflight": true}}]}}"#, bs58::encode(serialize(&bad_transaction).unwrap()).into_string() ); - let res = io.handle_request_sync(&req, meta); + let res = io.handle_request_sync(&req, meta.clone()); assert_eq!( res, Some( r#"{"jsonrpc":"2.0","result":"1111111111111111111111111111111111111111111111111111111111111111","id":1}"#.to_string(), ) ); + + // sendTransaction will fail due to no signer. Skip preflight so signature verification + // doesn't catch it + bad_transaction.signatures.clear(); + let req = format!( + r#"{{"jsonrpc":"2.0","id":1,"method":"sendTransaction","params":["{}", {{"skipPreflight": true}}]}}"#, + bs58::encode(serialize(&bad_transaction).unwrap()).into_string() + ); + let res = io.handle_request_sync(&req, meta); + assert_eq!( + res, + Some( + r#"{"jsonrpc":"2.0","error":{"code":-32003,"message":"Transaction is not signed"},"id":1}"#.to_string(), + ) + ); } #[test]