From cf0b8b7681156e1ee5c92d844d1cd0b50b17c9db Mon Sep 17 00:00:00 2001 From: Guanqun Lu Date: Thu, 11 May 2017 13:30:11 +0800 Subject: [PATCH] add several new tests for spec::account --- json/src/spec/account.rs | 57 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/json/src/spec/account.rs b/json/src/spec/account.rs index 046592a71..2c98fd3f1 100644 --- a/json/src/spec/account.rs +++ b/json/src/spec/account.rs @@ -39,7 +39,7 @@ pub struct Account { } impl Account { - /// Returns true if account does not have nonce and balance. + /// Returns true if account does not have nonce, balance, code and storage. pub fn is_empty(&self) -> bool { self.balance.is_none() && self.nonce.is_none() && self.code.is_none() && self.storage.is_none() } @@ -54,6 +54,59 @@ mod tests { use uint::Uint; use bytes::Bytes; + #[test] + fn account_balance_missing_not_empty() { + let s = r#"{ + "nonce": "0", + "code": "1234", + "storage": { "0x7fffffffffffffff7fffffffffffffff": "0x1" } + }"#; + let deserialized: Account = serde_json::from_str(s).unwrap(); + assert!(!deserialized.is_empty()); + } + + #[test] + fn account_nonce_missing_not_empty() { + let s = r#"{ + "balance": "1", + "code": "1234", + "storage": { "0x7fffffffffffffff7fffffffffffffff": "0x1" } + }"#; + let deserialized: Account = serde_json::from_str(s).unwrap(); + assert!(!deserialized.is_empty()); + } + + #[test] + fn account_code_missing_not_empty() { + let s = r#"{ + "balance": "1", + "nonce": "0", + "storage": { "0x7fffffffffffffff7fffffffffffffff": "0x1" } + }"#; + let deserialized: Account = serde_json::from_str(s).unwrap(); + assert!(!deserialized.is_empty()); + } + + #[test] + fn account_storage_missing_not_empty() { + let s = r#"{ + "balance": "1", + "nonce": "0", + "code": "1234" + }"#; + let deserialized: Account = serde_json::from_str(s).unwrap(); + assert!(!deserialized.is_empty()); + } + + #[test] + fn account_empty() { + let s = r#"{ + "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } + }"#; + let deserialized: Account = serde_json::from_str(s).unwrap(); + assert!(deserialized.is_empty()); + } + #[test] fn account_deserialization() { let s = r#"{ @@ -63,6 +116,7 @@ mod tests { "code": "1234" }"#; let deserialized: Account = serde_json::from_str(s).unwrap(); + assert!(!deserialized.is_empty()); assert_eq!(deserialized.balance.unwrap(), Uint(U256::from(1))); assert_eq!(deserialized.nonce.unwrap(), Uint(U256::from(0))); assert_eq!(deserialized.code.unwrap(), Bytes::new(vec![0x12, 0x34])); @@ -78,6 +132,7 @@ mod tests { "storage": { "0x7fffffffffffffff7fffffffffffffff": "0x1" } }"#; let deserialized: Account = serde_json::from_str(s).unwrap(); + assert!(!deserialized.is_empty()); assert_eq!(deserialized.balance.unwrap(), Uint(U256::from(1))); assert_eq!(deserialized.nonce.unwrap(), Uint(U256::from(0))); assert_eq!(deserialized.code.unwrap(), Bytes::new(vec![0x12, 0x34]));