From a0dd77ca016516840012dc9279a4ea8a24463ee7 Mon Sep 17 00:00:00 2001 From: Guanqun Lu Date: Fri, 12 May 2017 23:46:29 +0800 Subject: [PATCH] add asserts in spec::validatorset's unit test --- json/src/spec/validator_set.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/json/src/spec/validator_set.rs b/json/src/spec/validator_set.rs index f433caa03..abcb35848 100644 --- a/json/src/spec/validator_set.rs +++ b/json/src/spec/validator_set.rs @@ -40,6 +40,10 @@ pub enum ValidatorSet { #[cfg(test)] mod tests { use serde_json; + use uint::Uint; + use util::U256; + use hash::Address; + use util::hash::H160; use spec::validator_set::ValidatorSet; #[test] @@ -58,6 +62,20 @@ mod tests { } }]"#; - let _deserialized: Vec = serde_json::from_str(s).unwrap(); + let deserialized: Vec = serde_json::from_str(s).unwrap(); + assert_eq!(deserialized.len(), 4); + + assert_eq!(deserialized[0], ValidatorSet::List(vec![Address(H160::from("0xc6d9d2cd449a754c494264e1809c50e34d64562b"))])); + assert_eq!(deserialized[1], ValidatorSet::SafeContract(Address(H160::from("0xc6d9d2cd449a754c494264e1809c50e34d64562b")))); + assert_eq!(deserialized[2], ValidatorSet::Contract(Address(H160::from("0xc6d9d2cd449a754c494264e1809c50e34d64562b")))); + match deserialized[3] { + ValidatorSet::Multi(ref map) => { + assert_eq!(map.len(), 3); + assert!(map.contains_key(&Uint(U256::from(0)))); + assert!(map.contains_key(&Uint(U256::from(10)))); + assert!(map.contains_key(&Uint(U256::from(20)))); + }, + _ => assert!(false), + } } }