()
| 86 | |
| 87 | #[tokio::test] |
| 88 | async 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] |
| 130 | async fn test_call_enum() { |
nothing calls this directly
no test coverage detected