mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 19:21:13 +00:00
Updates for CC's recent upgrade (#1381)
* Updates for CC's recent upgrade - Version bump to 0.9.2 - Runtime version bump to v14 - Avoid misuse of error return type for system_health RPC * Fix tests
This commit is contained in:
@@ -43,6 +43,8 @@ pub struct Health {
|
||||
pub peers: usize,
|
||||
/// Is the node syncing
|
||||
pub is_syncing: bool,
|
||||
/// Should this node have any peers
|
||||
pub should_have_peers: bool,
|
||||
}
|
||||
|
||||
/// Network Peer information
|
||||
|
||||
@@ -103,21 +103,11 @@ impl<B: traits::Block> SystemApi<B::Hash, <B::Header as HeaderT>::Number> for Sy
|
||||
|
||||
fn system_health(&self) -> Result<Health> {
|
||||
let status = self.sync.status();
|
||||
|
||||
let is_syncing = status.sync.is_major_syncing();
|
||||
let peers = status.num_peers;
|
||||
|
||||
let health = Health {
|
||||
peers,
|
||||
is_syncing,
|
||||
};
|
||||
|
||||
let has_no_peers = peers == 0 && self.should_have_peers;
|
||||
if has_no_peers || is_syncing {
|
||||
Err(error::ErrorKind::NotHealthy(health))?
|
||||
} else {
|
||||
Ok(health)
|
||||
}
|
||||
Ok(Health {
|
||||
peers: status.num_peers,
|
||||
is_syncing: status.sync.is_major_syncing(),
|
||||
should_have_peers: self.should_have_peers,
|
||||
})
|
||||
}
|
||||
|
||||
fn system_peers(&self) -> Result<Vec<PeerInfo<B::Hash, <B::Header as HeaderT>::Number>>> {
|
||||
|
||||
@@ -97,11 +97,12 @@ fn system_properties_works() {
|
||||
#[test]
|
||||
fn system_health() {
|
||||
assert_matches!(
|
||||
api(None).system_health().unwrap_err().kind(),
|
||||
error::ErrorKind::NotHealthy(Health {
|
||||
api(None).system_health().unwrap(),
|
||||
Health {
|
||||
peers: 0,
|
||||
is_syncing: false,
|
||||
})
|
||||
should_have_peers: true,
|
||||
}
|
||||
);
|
||||
|
||||
assert_matches!(
|
||||
@@ -109,11 +110,12 @@ fn system_health() {
|
||||
peers: 5,
|
||||
is_syncing: true,
|
||||
is_dev: true,
|
||||
}).system_health().unwrap_err().kind(),
|
||||
error::ErrorKind::NotHealthy(Health {
|
||||
}).system_health().unwrap(),
|
||||
Health {
|
||||
peers: 5,
|
||||
is_syncing: true,
|
||||
})
|
||||
should_have_peers: false,
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
@@ -125,6 +127,7 @@ fn system_health() {
|
||||
Health {
|
||||
peers: 5,
|
||||
is_syncing: false,
|
||||
should_have_peers: true,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -137,6 +140,7 @@ fn system_health() {
|
||||
Health {
|
||||
peers: 0,
|
||||
is_syncing: false,
|
||||
should_have_peers: false,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user