Fix deserialization of RPC errors in HttpSender (#19110)

Fixes #15576
This commit is contained in:
Brian Anderson 2021-08-09 12:45:00 -05:00 committed by GitHub
parent f5ce2c2d63
commit e4b66a5913
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -67,7 +67,6 @@ impl HttpSender {
struct RpcErrorObject {
code: i64,
message: String,
data: serde_json::Value,
}
impl RpcSender for HttpSender {

View File

@ -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!()
}
}
}