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

Function test_call_enum_remote_error

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

Source from the content-addressed store, hash-verified

86
87#[tokio::test]
88async fn test_call_enum_remote_error() {
89 // Set up the rpc-connection
90 // The frame represents a Mock rpc-server
91 let (uds1, uds2) = UnixStream::pair().unwrap();
92 let mut cln = ClnRpc::from_stream(uds1).unwrap();
93 let mut frame = Framed::new(uds2, JsonCodec::default());
94
95 // Construct the request and response
96 let req = Request::Ping(requests::PingRequest {
97 id: PublicKey::from_str(
98 "0364aeb75519be29d1af7b8cc6232dbda9fdabb79b66e4e1f6a223750954db210b",
99 )
100 .unwrap(),
101 len: None,
102 pongbytes: None,
103 });
104
105 let mock_resp = json!({
106 "id" : 1,
107 "jsonrpc" : "2.0",
108 "error" : {
109 "code" : 666,
110 "message" : "MOCK_ERROR"
111 }
112 });
113
114 // Spawn the task which calls the rpc
115 let handle = tokio::task::spawn(async move { cln.call(req).await });
116
117 // Ensure the mock receives the request and returns a response
118 let _ = dbg!(frame.next().await.unwrap().unwrap());
119 frame.send(mock_resp).await.unwrap();
120
121 let rpc_response: Result<_, RpcError> = handle.await.unwrap();
122 let rpc_error: RpcError = rpc_response.unwrap_err();
123
124 println!("RPC_ERROR : {:?}", rpc_error);
125 assert_eq!(rpc_error.code.unwrap(), 666);
126 assert_eq!(rpc_error.message, "MOCK_ERROR");
127}
128
129#[tokio::test]
130async fn test_call_enum() {

Callers

nothing calls this directly

Calls 4

unwrap_errMethod · 0.80
unwrapMethod · 0.45
callMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected