Replace serde_json with strason in tests

This commit is contained in:
Andrew Poelstra 2015-11-22 09:46:05 -06:00
parent fa59c35e9a
commit c3c6983789
4 changed files with 12 additions and 20 deletions

View File

@ -26,6 +26,6 @@ rust-crypto = "0.2"
rustc-serialize = "0.3"
secp256k1 = "0.5"
serde = "0.6"
serde_json = "0.6"
strason = "0.3"
time = "0.1"

View File

@ -46,7 +46,7 @@ extern crate rand;
extern crate rustc_serialize as serialize;
extern crate secp256k1;
extern crate serde;
extern crate serde_json as json;
extern crate strason;
#[cfg(all(test, feature = "unstable"))] extern crate test;
extern crate time;

View File

@ -19,17 +19,13 @@
#[macro_export]
macro_rules! serde_round_trip (
($var:expr) => ({
use serde::{json, Serialize, Deserialize};
use serde::{Serialize, Deserialize};
use strason;
let start = $var;
let mut encoded = Vec::new();
{
let mut serializer = json::ser::Serializer::new(&mut encoded);
start.serialize(&mut serializer).unwrap();
}
let mut deserializer = json::de::Deserializer::new(encoded.iter().map(|c| Ok(*c))).unwrap();
let decoded = Deserialize::deserialize(&mut deserializer);
assert_eq!(Some(start), decoded.ok());
let encoded = strason::from_serialize(start).unwrap();
let decoded = encoded.into_deserialize().unwrap();
assert_eq!(start, decoded);
})
);

View File

@ -282,7 +282,7 @@ impl <T: BitcoinHash> MerkleRoot for Vec<T> {
mod tests {
use num::FromPrimitive;
use serde::{Serialize, Deserialize};
use json;
use strason;
use network::serialize::{serialize, deserialize};
use util::hash::Sha256dHash;
@ -309,15 +309,11 @@ mod tests {
#[test]
fn test_hash_encode_decode() {
let hash = Sha256dHash::from_data(&[]);
let mut writer = vec![];
{
let mut serializer = json::ser::Serializer::new(&mut writer);
assert!(hash.serialize(&mut serializer).is_ok());
}
assert_eq!(&writer[..],
let encoded = strason::from_serialize(&hash).unwrap();
assert_eq!(encoded.to_bytes(),
"\"56944c5d3f98413ef45cf54545538103cc9f298e0575820ad3591376e2e0f65d\"".as_bytes());
let mut deserializer = json::de::Deserializer::new(writer.iter().map(|c| Ok(*c)));
assert_eq!(hash, Deserialize::deserialize(&mut deserializer).unwrap());
let decoded = encoded.into_deserialize().unwrap();
assert_eq!(hash, decoded);
}
#[test]