Skip to content

Commit 42c02a2

Browse files
committed
f - Add call_method_returning_malformed_result test
1 parent 7cef9c5 commit 42c02a2

File tree

1 file changed

+15
-0
lines changed
  • lightning-block-sync/src

1 file changed

+15
-0
lines changed

lightning-block-sync/src/rpc.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,21 @@ mod tests {
140140
}
141141
}
142142

143+
#[tokio::test]
144+
async fn call_method_returning_malformed_result() {
145+
let response = serde_json::json!({ "result": "foo" });
146+
let server = HttpServer::responding_with_ok(MessageBody::Content(response));
147+
let mut client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
148+
149+
match client.call_method::<u64>("getblockcount", &[]).await {
150+
Err(e) => {
151+
assert_eq!(e.kind(), std::io::ErrorKind::InvalidData);
152+
assert_eq!(e.get_ref().unwrap().to_string(), "not a number");
153+
},
154+
Ok(_) => panic!("Expected error"),
155+
}
156+
}
157+
143158
#[tokio::test]
144159
async fn call_method_returning_valid_result() {
145160
let response = serde_json::json!({ "result": 654470 });

0 commit comments

Comments
 (0)