camelcase structs returned over RPC (#1507)

This commit is contained in:
Tomasz Drwięga
2019-01-21 19:25:58 +01:00
committed by Gav Wood
parent 8ec759d32e
commit e48291acd0
7 changed files with 81 additions and 2 deletions
+5
View File
@@ -220,6 +220,11 @@ fn should_return_runtime_version() {
api.runtime_version(None.into()),
Ok(ref ver) if ver == &runtime::VERSION
);
assert_eq!(
::serde_json::to_string(&api.runtime_version(None.into()).unwrap()).unwrap(),
r#"{"specName":"test","implName":"parity-test","authoringVersion":1,"specVersion":1,"implVersion":1,"apis":[["0xdf6acb689907609b",1],["0x37e397fc7c91f5e4",1],["0xd2bc9897eed08f15",1],["0x40fe3ad401f8959a",1],["0xc6e9a76309f39b09",1],["0xdd718d5cc53262d4",1]]}"#
);
}
#[test]
+36
View File
@@ -38,17 +38,21 @@ pub struct SystemInfo {
/// Health struct returned by the RPC
#[derive(Debug, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Health {
/// Number of connected peers
pub peers: usize,
/// Is the node syncing
pub is_syncing: bool,
/// Should this node have any peers
///
/// Might be false for local chains or when running without discovery.
pub should_have_peers: bool,
}
/// Network Peer information
#[derive(Debug, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PeerInfo<Hash, Number> {
/// Peer Node Index
pub index: usize,
@@ -71,3 +75,35 @@ impl fmt::Display for Health {
} else { "idle" })
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn should_serialize_health() {
assert_eq!(
::serde_json::to_string(&Health {
peers: 1,
is_syncing: false,
should_have_peers: true,
}).unwrap(),
r#"{"peers":1,"isSyncing":false,"shouldHavePeers":true}"#,
);
}
#[test]
fn should_serialize_peer_info() {
assert_eq!(
::serde_json::to_string(&PeerInfo {
index: 1,
peer_id: "2".into(),
roles: "a".into(),
protocol_version: 2,
best_hash: 5u32,
best_number: 6u32,
}).unwrap(),
r#"{"index":1,"peerId":"2","roles":"a","protocolVersion":2,"bestHash":5,"bestNumber":6}"#,
);
}
}
-1
View File
@@ -19,7 +19,6 @@ use super::*;
use network::{self, SyncState, SyncStatus, ProtocolStatus, NodeIndex, PeerId, PeerInfo as NetworkPeerInfo, PublicKey};
use network::config::Roles;
use test_client::runtime::Block;
use primitives::H256;
#[derive(Default)]
struct Status {