()
| 28 | |
| 29 | #[tokio::test] |
| 30 | async fn call_raw_request() { |
| 31 | // Set up a pair of unix-streams |
| 32 | // The frame is a mock rpc-server |
| 33 | let (uds1, uds2) = UnixStream::pair().unwrap(); |
| 34 | let mut cln = ClnRpc::from_stream(uds1).unwrap(); |
| 35 | let mut frame = Framed::new(uds2, JsonCodec::default()); |
| 36 | |
| 37 | // Define the request and response send in the RPC-message |
| 38 | let rpc_request = serde_json::json!({ |
| 39 | "id" : 1, |
| 40 | "jsonrpc" : "2.0", |
| 41 | "params" : {}, |
| 42 | "method" : "some_method" |
| 43 | }); |
| 44 | let rpc_request2 = rpc_request.clone(); |
| 45 | |
| 46 | let rpc_response = serde_json::json!({ |
| 47 | "jsonrpc" : "2.0", |
| 48 | "id" : "1", |
| 49 | "result" : {"field_6" : 6} |
| 50 | }); |
| 51 | |
| 52 | // Spawn the task that performs the RPC-call |
| 53 | // Check that it reads the response correctly |
| 54 | let handle = tokio::task::spawn(async move { cln.call_raw_request(rpc_request2).await }); |
| 55 | |
| 56 | // Verify that our emulated server received a request |
| 57 | // and sendt the response |
| 58 | let read_req = dbg!(frame.next().await.unwrap().unwrap()); |
| 59 | assert_eq!(&rpc_request, &read_req); |
| 60 | frame.send(rpc_response).await.unwrap(); |
| 61 | |
| 62 | // Get the result from `call_raw_request` and verify |
| 63 | let actual_response: Result<serde_json::Value, RpcError> = handle.await.unwrap(); |
| 64 | let actual_response = actual_response.unwrap(); |
| 65 | assert_eq!(actual_response, json!({"field_6" : 6})); |
| 66 | } |
| 67 | |
| 68 | #[tokio::test] |
| 69 | async fn call_raw() { |
nothing calls this directly
no test coverage detected