Add failing test for TX sent via RPC with no signatures

(cherry picked from commit b962b2ce2d)
This commit is contained in:
Trent Nelson
2020-07-29 20:03:30 -06:00
committed by Trent Nelson
parent 227a13f2d2
commit e8e74ee009

View File

@ -3008,7 +3008,7 @@ pub mod tests {
)), )),
); );
let mut bad_transaction = let bad_transaction =
system_transaction::transfer(&Keypair::new(), &Pubkey::default(), 42, Hash::default()); system_transaction::transfer(&Keypair::new(), &Pubkey::default(), 42, Hash::default());
// sendTransaction will fail because the blockhash is invalid // 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 // sendTransaction will fail due to poor node health
health.stub_set_health_status(Some(RpcHealthStatus::Behind)); health.stub_set_health_status(Some(RpcHealthStatus::Behind));
let req = format!( let req = format!(
@ -3060,13 +3064,28 @@ pub mod tests {
r#"{{"jsonrpc":"2.0","id":1,"method":"sendTransaction","params":["{}", {{"skipPreflight": true}}]}}"#, r#"{{"jsonrpc":"2.0","id":1,"method":"sendTransaction","params":["{}", {{"skipPreflight": true}}]}}"#,
bs58::encode(serialize(&bad_transaction).unwrap()).into_string() 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!( assert_eq!(
res, res,
Some( Some(
r#"{"jsonrpc":"2.0","result":"1111111111111111111111111111111111111111111111111111111111111111","id":1}"#.to_string(), 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] #[test]