Skip to content

Commit

Permalink
Add tests for binary serialization via bincode
Browse files Browse the repository at this point in the history
  • Loading branch information
shesek committed Jan 5, 2021
1 parent d0eed01 commit 1be22c3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -35,6 +35,7 @@ serde = { version = "1", optional = true }
serde_derive = "<1.0.99"
serde_json = "<1.0.45"
serde_test = "1"
bincode = "1.3.1"
secp256k1 = { version = "0.19.0", features = [ "recovery", "rand-std" ] }
# We need to pin ryu (transitive dep from serde_json) to stay compatible with Rust 1.22.0
ryu = "<1.0.5"
1 change: 1 addition & 0 deletions src/lib.rs
Expand Up @@ -48,6 +48,7 @@ pub extern crate bech32;
#[cfg(all(test, feature = "serde"))] #[macro_use] extern crate serde_derive; // for 1.22.0 compat
#[cfg(all(test, feature = "serde"))] extern crate serde_json;
#[cfg(all(test, feature = "serde"))] extern crate serde_test;
#[cfg(all(test, feature = "serde"))] extern crate bincode;
#[cfg(all(test, feature = "unstable"))] extern crate test;

#[cfg(target_pointer_width = "16")]
Expand Down
4 changes: 4 additions & 0 deletions src/util/uint.rs
Expand Up @@ -721,6 +721,10 @@ mod tests {
let json = format!("\"{}\"", hex);
assert_eq!(::serde_json::to_string(&uint).unwrap(), json);
assert_eq!(::serde_json::from_str::<Uint256>(&json).unwrap(), uint);

let bin_encoded = ::bincode::serialize(&uint).unwrap();
let bin_decoded: Uint256 = ::bincode::deserialize(&bin_encoded).unwrap();
assert_eq!(bin_decoded, uint);
};

check(
Expand Down

0 comments on commit 1be22c3

Please sign in to comment.