Quellcode durchsuchen

chore: ported tests to new rpc impl

aggstam vor 3 Jahren
Ursprung
Commit
6c08581c8e
2 geänderte Dateien mit 9 neuen und 17 gelöschten Zeilen
  1. 4 5
      bin/darkfid2/src/tests/harness.rs
  2. 5 12
      tests/jsonrpc.rs

+ 4 - 5
bin/darkfid2/src/tests/harness.rs

@@ -22,7 +22,7 @@ use async_std::sync::Arc;
 use darkfi::{
     blockchain::{BlockInfo, Header},
     net::Settings,
-    rpc::jsonrpc::MethodSubscriber,
+    rpc::jsonrpc::JsonSubscriber,
     util::time::TimeKeeper,
     validator::{
         consensus::{next_block_reward, pid::slot_pid_output},
@@ -225,11 +225,10 @@ pub async fn generate_node(
     let validator = Validator::new(&sled_db, config.clone()).await?;
 
     let mut subscribers = HashMap::new();
-    subscribers.insert("blocks", MethodSubscriber::new("blockchain.subscribe_blocks".into()));
-    subscribers.insert("txs", MethodSubscriber::new("blockchain.subscribe_txs".into()));
+    subscribers.insert("blocks", JsonSubscriber::new("blockchain.subscribe_blocks"));
+    subscribers.insert("txs", JsonSubscriber::new("blockchain.subscribe_txs"));
     if consensus_settings.is_some() {
-        subscribers
-            .insert("proposals", MethodSubscriber::new("blockchain.subscribe_proposals".into()));
+        subscribers.insert("proposals", JsonSubscriber::new("blockchain.subscribe_proposals"));
     }
 
     let sync_p2p = spawn_sync_p2p(&sync_settings, &validator, &subscribers).await;

+ 5 - 12
tests/jsonrpc.rs

@@ -37,11 +37,11 @@ struct RpcSrv {
 }
 
 impl RpcSrv {
-    async fn pong(&self, id: JsonValue, _params: JsonValue) -> JsonResult {
+    async fn pong(&self, id: u16, _params: JsonValue) -> JsonResult {
         JsonResponse::new(JsonValue::String("pong".to_string()), id).into()
     }
 
-    async fn kill(&self, id: JsonValue, _params: JsonValue) -> JsonResult {
+    async fn kill(&self, id: u16, _params: JsonValue) -> JsonResult {
         self.stop_sub.0.send(()).await.unwrap();
         JsonResponse::new(JsonValue::String("bye".to_string()), id).into()
     }
@@ -57,14 +57,7 @@ impl RequestHandler for RpcSrv {
         match method.as_str() {
             "ping" => return self.pong(req.id, params).await,
             "kill" => return self.kill(req.id, params).await,
-            _ => {
-                return JsonError::new(
-                    ErrorCode::MethodNotFound,
-                    None,
-                    *req.id.get::<f64>().unwrap() as u16,
-                )
-                .into()
-            }
+            _ => return JsonError::new(ErrorCode::MethodNotFound, None, req.id).into(),
         }
     }
 }
@@ -90,13 +83,13 @@ async fn jsonrpc_reqrep() -> Result<()> {
     });
 
     let client = RpcClient::new(endpoint, None).await?;
-    let req = JsonRequest::new("ping", JsonValue::from(vec![]));
+    let req = JsonRequest::new("ping", vec![]);
     let rep = client.request(req).await?;
 
     let rep = String::try_from(rep).unwrap();
     assert_eq!(&rep, "pong");
 
-    let req = JsonRequest::new("kill", JsonValue::from(vec![]));
+    let req = JsonRequest::new("kill", vec![]);
     let rep = client.request(req).await?;
 
     let rep = String::try_from(rep).unwrap();