From 753cfefed9b8eb345b2f49a7b1b2512da3aa004c Mon Sep 17 00:00:00 2001 From: Paulo Martins Date: Mon, 10 Jan 2022 14:15:12 +0000 Subject: [PATCH] fetch system chain, name and version (#385) * fetch system chain, name and version * add fetch system tests * fix fetch system test * fix cargo fmt * fix cargo clippy --- src/rpc.rs | 15 +++++++++++++++ tests/integration/client.rs | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/src/rpc.rs b/src/rpc.rs index 206aabbed2..470a4166c0 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -391,6 +391,21 @@ impl Rpc { Ok(self.client.request("system_properties", &[]).await?) } + /// Fetch system chain + pub async fn system_chain(&self) -> Result { + Ok(self.client.request("system_chain", &[]).await?) + } + + /// Fetch system name + pub async fn system_name(&self) -> Result { + Ok(self.client.request("system_name", &[]).await?) + } + + /// Fetch system version + pub async fn system_version(&self) -> Result { + Ok(self.client.request("system_version", &[]).await?) + } + /// Get a header pub async fn header( &self, diff --git a/tests/integration/client.rs b/tests/integration/client.rs index a3c0dd085a..47676fb6ee 100644 --- a/tests/integration/client.rs +++ b/tests/integration/client.rs @@ -122,3 +122,12 @@ async fn test_iter() { } assert_eq!(i, 13); } + +#[async_std::test] +async fn fetch_system_info() { + let node_process = test_node_process().await; + let client = node_process.client(); + assert_eq!(client.rpc().system_chain().await.unwrap(), "Development"); + assert_eq!(client.rpc().system_name().await.unwrap(), "Substrate Node"); + assert!(!client.rpc().system_version().await.unwrap().is_empty()); +}