From e4b66a5913c040408612027a62832495ae2446ba Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 9 Aug 2021 12:45:00 -0500 Subject: [PATCH] Fix deserialization of RPC errors in HttpSender (#19110) Fixes #15576 --- client/src/http_sender.rs | 1 - core/tests/rpc.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/client/src/http_sender.rs b/client/src/http_sender.rs index 76c31895ac..79d5c4ed85 100644 --- a/client/src/http_sender.rs +++ b/client/src/http_sender.rs @@ -67,7 +67,6 @@ impl HttpSender { struct RpcErrorObject { code: i64, message: String, - data: serde_json::Value, } impl RpcSender for HttpSender { diff --git a/core/tests/rpc.rs b/core/tests/rpc.rs index 6efefdf28c..45d5f9f5a4 100644 --- a/core/tests/rpc.rs +++ b/core/tests/rpc.rs @@ -6,8 +6,10 @@ use reqwest::{self, header::CONTENT_TYPE}; use serde_json::{json, Value}; use solana_account_decoder::UiAccount; use solana_client::{ + client_error::{ClientErrorKind, Result as ClientResult}, rpc_client::RpcClient, rpc_config::{RpcAccountInfoConfig, RpcSignatureSubscribeConfig}, + rpc_request::RpcError, rpc_response::{Response, RpcSignatureResult, SlotUpdate}, tpu_client::{TpuClient, TpuClientConfig}, }; @@ -420,3 +422,34 @@ fn test_tpu_send_transaction() { } } } + +#[test] +fn deserialize_rpc_error() -> ClientResult<()> { + solana_logger::setup(); + + let alice = Keypair::new(); + let validator = TestValidator::with_no_fees(alice.pubkey(), None, SocketAddrSpace::Unspecified); + let rpc_client = RpcClient::new(validator.rpc_url()); + + let bob = Keypair::new(); + let lamports = 50; + let (recent_blockhash, _) = rpc_client.get_recent_blockhash()?; + let mut tx = system_transaction::transfer(&alice, &bob.pubkey(), lamports, recent_blockhash); + + // This will cause an error + tx.signatures.clear(); + + let err = rpc_client.send_transaction(&tx); + let err = err.unwrap_err(); + + match err.kind { + ClientErrorKind::RpcError(RpcError::RpcRequestError { .. }) => { + // This is what used to happen + panic!() + } + ClientErrorKind::RpcError(RpcError::RpcResponseError { .. }) => Ok(()), + _ => { + panic!() + } + } +}