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

Function test_call_enum

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

Source from the content-addressed store, hash-verified

128
129#[tokio::test]
130async fn test_call_enum() {
131 // Set up the rpc-connection
132 // The frame represents a Mock rpc-server
133 let (uds1, uds2) = UnixStream::pair().unwrap();
134 let mut cln = ClnRpc::from_stream(uds1).unwrap();
135 let mut frame = Framed::new(uds2, JsonCodec::default());
136
137 // We'll use the Ping request here because both the request
138 // and response have few arguments
139 let req = Request::Ping(requests::PingRequest {
140 id: PublicKey::from_str(
141 "0364aeb75519be29d1af7b8cc6232dbda9fdabb79b66e4e1f6a223750954db210b",
142 )
143 .unwrap(),
144 len: None,
145 pongbytes: None,
146 });
147 let mock_resp = json!({
148 "id" : 1,
149 "jsonrpc" : "2.0",
150 "result" : { "totlen" : 123 }
151 });
152
153 // we create a task that sends the response and returns the response
154 let handle = tokio::task::spawn(async move { cln.call(req).await });
155
156 // Ensure our mock receives the request and sends the response
157 let read_req = dbg!(frame.next().await.unwrap().unwrap());
158 assert_eq!(
159 read_req,
160 json!({"id" : 1, "jsonrpc" : "2.0", "method" : "ping", "params" : {"id" : "0364aeb75519be29d1af7b8cc6232dbda9fdabb79b66e4e1f6a223750954db210b"}})
161 );
162 frame.send(mock_resp).await.unwrap();
163
164 // Verify that the error response is correct
165 let rpc_response: Result<_, RpcError> = handle.await.unwrap();
166 match rpc_response.unwrap() {
167 Response::Ping(ping) => {
168 assert_eq!(ping.totlen, 123);
169 }
170 _ => panic!("A Request::Getinfo should return Response::Getinfo"),
171 }
172}
173
174#[tokio::test]
175async fn test_call_typed() {

Callers

nothing calls this directly

Calls 3

unwrapMethod · 0.45
callMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected