Skip to content

Commit

Permalink
Add failing test for unsane tx in RPC preflight
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 d4df2ac commit e25846e
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions core/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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);

Expand Down

0 comments on commit e25846e

Please sign in to comment.