Refactor RPC tests (#23483)

This commit is contained in:
Justin Starry 2022-03-04 18:20:11 +08:00 committed by GitHub
parent 36ad59673c
commit 38db1dead4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1012 additions and 1433 deletions

View File

@ -33,7 +33,7 @@ pub type StringDecimals = String;
pub const MAX_BASE58_BYTES: usize = 128;
/// A duplicate representation of an Account for pretty JSON serialization
#[derive(Serialize, Deserialize, Clone, Debug)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct UiAccount {
pub lamports: u64,

View File

@ -117,7 +117,7 @@ pub struct RpcInflationRate {
pub epoch: Epoch,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct RpcKeyedAccount {
pub pubkey: String,
@ -246,7 +246,7 @@ pub struct RpcBlockProductionRange {
pub last_slot: Slot,
}
#[derive(Serialize, Deserialize, Clone)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct RpcBlockProduction {
/// Map of leader base58 identity pubkeys to a tuple of `(number of leader slots, number of blocks produced)`
@ -363,7 +363,7 @@ pub struct RpcAccountBalance {
pub lamports: u64,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct RpcSupply {
pub total: u64,

File diff suppressed because it is too large Load Diff

View File

@ -808,7 +808,7 @@ mod tests {
let expected: Response = serde_json::from_str(expected).unwrap();
let result: Response = serde_json::from_str(&res.unwrap()).unwrap();
assert_eq!(expected, result);
assert_eq!(result, expected);
// Test bad parameter
let req = r#"{"jsonrpc":"2.0","id":1,"method":"signatureUnsubscribe","params":[1]}"#;
@ -817,7 +817,7 @@ mod tests {
let expected: Response = serde_json::from_str(expected).unwrap();
let result: Response = serde_json::from_str(&res.unwrap()).unwrap();
assert_eq!(expected, result);
assert_eq!(result, expected);
}
#[test]
@ -1071,7 +1071,7 @@ mod tests {
let expected: Response = serde_json::from_str(expected).unwrap();
let result: Response = serde_json::from_str(&res.unwrap()).unwrap();
assert_eq!(expected, result);
assert_eq!(result, expected);
// Test bad parameter
let req = r#"{"jsonrpc":"2.0","id":1,"method":"accountUnsubscribe","params":[1]}"#;
@ -1080,7 +1080,7 @@ mod tests {
let expected: Response = serde_json::from_str(expected).unwrap();
let result: Response = serde_json::from_str(&res.unwrap()).unwrap();
assert_eq!(expected, result);
assert_eq!(result, expected);
}
#[test]

View File

@ -1,4 +1,4 @@
use super::Bank;
use {super::Bank, solana_program_runtime::sysvar_cache::SysvarCache};
impl Bank {
pub(crate) fn fill_missing_sysvar_cache_entries(&self) {
@ -10,6 +10,10 @@ impl Bank {
let mut sysvar_cache = self.sysvar_cache.write().unwrap();
sysvar_cache.reset();
}
pub fn get_sysvar_cache_for_tests(&self) -> SysvarCache {
self.sysvar_cache.read().unwrap().clone()
}
}
#[cfg(test)]