Skip to content

Commit

Permalink
Merge pull request #43 from ethcore/fix-jsonrpc-omitted
Browse files Browse the repository at this point in the history
Don't serialize version field if it is not set explicitly
  • Loading branch information
NikVolf committed Feb 13, 2017
2 parents d54efce + 2ecfb97 commit 86d7a89
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion core/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ fn write_response(response: Response) -> String {
mod tests {
use futures::{self, Future};
use types::{Value};
use super::{IoHandler};
use super::{IoHandler, Compatibility};

#[test]
fn test_io_handler() {
Expand All @@ -303,6 +303,20 @@ mod tests {
assert_eq!(io.handle_request_sync(request), Some(response.to_string()));
}

#[test]
fn test_io_handler_1dot0() {
let mut io = IoHandler::with_compatibility(Compatibility::Both);

io.add_method("say_hello", |_| {
Ok(Value::String("hello".to_string()))
});

let request = r#"{"method": "say_hello", "params": [42, 23], "id": 1}"#;
let response = r#"{"result":"hello","id":1}"#;

assert_eq!(io.handle_request_sync(request), Some(response.to_string()));
}

#[test]
fn test_async_io_handler() {
let mut io = IoHandler::new();
Expand Down
1 change: 1 addition & 0 deletions core/src/types/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::{Id, Value, Error, ErrorCode, Version};
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Success {
/// Protocol version
#[serde(skip_serializing_if = "Option::is_none")]
pub jsonrpc: Option<Version>,
/// Result
pub result: Value,
Expand Down

0 comments on commit 86d7a89

Please sign in to comment.