-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add matching serializer for
app_hash
field of block::Header
struct (
#188) * Add matching serializer for `app_hash` field of `block::Header` struct Closes #187 * Add serialization roundtrip test for `block::Header`
- Loading branch information
Showing
4 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use serde::{de::DeserializeOwned, Serialize}; | ||
use std::fmt::Debug; | ||
|
||
/// Test that a struct `T` can be: | ||
/// | ||
/// - parsed out of the provided JSON data | ||
/// - serialized back to JSON | ||
/// - parsed back from the serialized JSON of the previous step | ||
/// - that the two parsed structs are equal according to their `PartialEq` impl | ||
pub fn test_serialization_roundtrip<T>(json_data: &str) | ||
where | ||
T: Debug + PartialEq + Serialize + DeserializeOwned, | ||
{ | ||
let parsed0 = serde_json::from_str::<T>(json_data); | ||
assert!(parsed0.is_ok()); | ||
let parsed0 = parsed0.unwrap(); | ||
|
||
let serialized = serde_json::to_string(&parsed0); | ||
assert!(serialized.is_ok()); | ||
let serialized = serialized.unwrap(); | ||
|
||
let parsed1 = serde_json::from_str::<T>(&serialized); | ||
assert!(parsed1.is_ok()); | ||
let parsed1 = parsed1.unwrap(); | ||
|
||
assert_eq!(parsed0, parsed1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"version": { | ||
"block": "10", | ||
"app": "0" | ||
}, | ||
"chain_id": "cosmoshub-1", | ||
"height": "15", | ||
"time": "2019-03-13T23:09:34.503701042Z", | ||
"num_txs": "2", | ||
"total_txs": "4", | ||
"last_block_id": { | ||
"hash": "42C70F10EF1835CED7248114514B4EF3D06F0D7FD24F6486E3315DEE310D305C", | ||
"parts": { | ||
"total": "1", | ||
"hash": "F51D1B8E6ED859CE23F6B0539E0101653ED4025B13DAA3E76FCC779D5FD96ABE" | ||
} | ||
}, | ||
"last_commit_hash": "C499C138BCABA4D40D68A1446F6E5DE1965E07DF17EEACE1A69C1C9B1B8AC5AB", | ||
"data_hash": "AC6A27A91A6EF9057D1A33F7944DD9EDD5FC1A3CA49E04EF0801A17FF01B4412", | ||
"validators_hash": "EB25B1ACF639219180EB77AFC67E75A51A7CA0D666123E514B6882EC38868652", | ||
"next_validators_hash": "EB25B1ACF639219180EB77AFC67E75A51A7CA0D666123E514B6882EC38868652", | ||
"consensus_hash": "29C5629148426FB74676BE07F40F2ED79674A67F5833E4C9CCBF759C9372E99C", | ||
"app_hash": "0A5826D21A3B0B341C843A0E4946AC787EC9B42A7DC1BEAA344C03C43943B179", | ||
"last_results_hash": "", | ||
"evidence_hash": "", | ||
"proposer_address": "CC05882978FC5FDD6A7721687E14C0299AE004B8" | ||
} |