MCPcopy Create free account
hub / github.com/ElementsProject/lightning / call_raw_request

Function call_raw_request

cln-rpc/src/test.rs:30–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28
29#[tokio::test]
30async 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]
69async fn call_raw() {

Callers

nothing calls this directly

Calls 3

call_raw_requestMethod · 0.80
unwrapMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected