From aa02a71d09a91f35274bb1d28db6ffbe5774a57f Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 2 Dec 2015 14:20:41 +0100 Subject: [PATCH] removed DecoderError::BadRlp --- src/rlp.rs | 8 ++++---- src/triehash.rs | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/rlp.rs b/src/rlp.rs index 4c22b7dcc..5f718ac3e 100644 --- a/src/rlp.rs +++ b/src/rlp.rs @@ -86,7 +86,6 @@ pub enum DecoderError { RlpIsTooShort, RlpExpectedToBeList, RlpExpectedToBeData, - BadRlp, } impl StdError for DecoderError { fn description(&self) -> &str { @@ -725,9 +724,9 @@ impl BasicDecoder { let header_len = 1 + len_of_len; let value_len = try!(usize::from_bytes(&bytes[1..header_len])); PayloadInfo::new(header_len, value_len) - } + }, // we cant reach this place, but rust requires _ to be implemented - _ => return Err(DecoderError::BadRlp), + _ => { panic!(); } }; match item.header_len + item.value_len <= bytes.len() { @@ -753,7 +752,8 @@ impl Decoder for BasicDecoder { let len = try!(usize::from_bytes(&bytes[1..begin_of_value])); Ok(try!(f(&bytes[begin_of_value..begin_of_value + len]))) } - _ => Err(DecoderError::BadRlp), + // we are reading value, not a list! + _ => { panic!(); } } } } diff --git a/src/triehash.rs b/src/triehash.rs index 56dafcb2e..8c8e9fd85 100644 --- a/src/triehash.rs +++ b/src/triehash.rs @@ -280,7 +280,10 @@ fn test_hex_prefix_encode() { #[cfg(test)] mod tests { use std::str::FromStr; + use std::collections::BTreeMap; use rustc_serialize::hex::FromHex; + use rustc_serialize::json::Json; + use bytes::*; use hash::*; use triehash::*; @@ -377,4 +380,19 @@ mod tests { assert_eq!(trie_root(v), H256::from_str("9f6221ebb8efe7cff60a716ecb886e67dd042014be444669f0159d8e68b42100").unwrap()); } + + #[test] + fn test_triehash_json_trietest_json() { + let data = include_bytes!("../tests/TrieTests/trietest.json"); + + let s = String::from_bytes(data).unwrap(); + let json = Json::from_str(&s).unwrap(); + let obj = json.as_object().unwrap(); + + for (key, value) in obj.iter() { + println!("running test: {}", key); + } + assert!(false); + } + }