Skip to content

Commit 63d3c89

Browse files
committed
Merge branch 'feat/pyth-lazer/agent/jrpc-impl-3' of github.com:pyth-network/pyth-crosschain into feat/pyth-lazer/agent/jrpc-notifications-1
2 parents 53f67d9 + 1e01ca0 commit 63d3c89

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

lazer/sdk/rust/protocol/src/jrpc.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub enum JsonRpcVersion {
5959
}
6060

6161
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
62+
#[serde(untagged)]
6263
pub enum JrpcResponse<T> {
6364
Success(JrpcSuccessResponse<T>),
6465
Error(JrpcErrorResponse),
@@ -442,4 +443,52 @@ mod tests {
442443
}
443444
);
444445
}
446+
447+
#[test]
448+
pub fn test_parse_response() {
449+
let success_response = serde_json::from_str::<JrpcResponse<String>>(
450+
r#"
451+
{
452+
"jsonrpc": "2.0",
453+
"id": 2,
454+
"result": "success"
455+
}"#,
456+
)
457+
.unwrap();
458+
459+
assert_eq!(
460+
success_response,
461+
JrpcResponse::Success(JrpcSuccessResponse::<String> {
462+
jsonrpc: JsonRpcVersion::V2,
463+
result: "success".to_string(),
464+
id: 2,
465+
})
466+
);
467+
468+
let error_response = serde_json::from_str::<JrpcResponse<String>>(
469+
r#"
470+
{
471+
"jsonrpc": "2.0",
472+
"id": 3,
473+
"error": {
474+
"code": -32603,
475+
"message": "Internal error"
476+
}
477+
}"#,
478+
)
479+
.unwrap();
480+
481+
assert_eq!(
482+
error_response,
483+
JrpcResponse::Error(JrpcErrorResponse {
484+
jsonrpc: JsonRpcVersion::V2,
485+
error: JrpcErrorObject {
486+
code: -32603,
487+
message: "Internal error".to_string(),
488+
data: None,
489+
},
490+
id: Some(3),
491+
})
492+
);
493+
}
445494
}

0 commit comments

Comments
 (0)