removed DecoderError::BadRlp

This commit is contained in:
debris 2015-12-02 14:20:41 +01:00
parent 356be1c635
commit aa02a71d09
2 changed files with 22 additions and 4 deletions

View File

@ -86,7 +86,6 @@ pub enum DecoderError {
RlpIsTooShort, RlpIsTooShort,
RlpExpectedToBeList, RlpExpectedToBeList,
RlpExpectedToBeData, RlpExpectedToBeData,
BadRlp,
} }
impl StdError for DecoderError { impl StdError for DecoderError {
fn description(&self) -> &str { fn description(&self) -> &str {
@ -725,9 +724,9 @@ impl BasicDecoder {
let header_len = 1 + len_of_len; let header_len = 1 + len_of_len;
let value_len = try!(usize::from_bytes(&bytes[1..header_len])); let value_len = try!(usize::from_bytes(&bytes[1..header_len]));
PayloadInfo::new(header_len, value_len) PayloadInfo::new(header_len, value_len)
} },
// we cant reach this place, but rust requires _ to be implemented // 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() { 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])); let len = try!(usize::from_bytes(&bytes[1..begin_of_value]));
Ok(try!(f(&bytes[begin_of_value..begin_of_value + len]))) Ok(try!(f(&bytes[begin_of_value..begin_of_value + len])))
} }
_ => Err(DecoderError::BadRlp), // we are reading value, not a list!
_ => { panic!(); }
} }
} }
} }

View File

@ -280,7 +280,10 @@ fn test_hex_prefix_encode() {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::str::FromStr; use std::str::FromStr;
use std::collections::BTreeMap;
use rustc_serialize::hex::FromHex; use rustc_serialize::hex::FromHex;
use rustc_serialize::json::Json;
use bytes::*;
use hash::*; use hash::*;
use triehash::*; use triehash::*;
@ -377,4 +380,19 @@ mod tests {
assert_eq!(trie_root(v), H256::from_str("9f6221ebb8efe7cff60a716ecb886e67dd042014be444669f0159d8e68b42100").unwrap()); 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);
}
} }