empty lists tests

This commit is contained in:
debris 2015-12-03 06:06:42 +01:00
parent 9f9c508ebd
commit 84eb30a133
4 changed files with 63 additions and 66 deletions

View File

@ -14,5 +14,5 @@
"value": "dog"
}
],
"output": "0xc88363617183646f67"
"output": "0xc88363617483646f67"
}

View File

@ -0,0 +1,38 @@
{
"input":
[
{
"operation": "append_list",
"len": 3
},
{
"operation": "append_list",
"len": 0
},
{
"operation": "append_list",
"len": 1
},
{
"operation": "append_list",
"len": 0
},
{
"operation": "append_list",
"len": 2
},
{
"operation": "append_list",
"len": 0
},
{
"operation": "append_list",
"len": 1
},
{
"operation": "append_list",
"len": 0
}
],
"output": "0xc7c0c1c0c3c0c1c0"
}

View File

@ -1098,6 +1098,9 @@ impl Encoder for BasicEncoder {
#[cfg(test)]
mod tests {
extern crate json_tests;
use self::json_tests::execute_tests_from_directory;
use self::json_tests::rlp as rlptest;
use std::{fmt, cmp};
use std::str::FromStr;
use rlp;
@ -1496,4 +1499,25 @@ mod tests {
let view = View::new(&data);
let _data_slice = view.offset(1).data();
}
#[test]
fn test_rlp_json() {
println!("Json rlp test: ");
execute_tests_from_directory::<rlptest::RlpStreamTest, _>("json-tests/json/rlp/*.json", &mut | file, input, output | {
println!("file: {}", file);
let mut stream = RlpStream::new();
for operation in input.into_iter() {
match operation {
rlptest::Operation::Append(ref v) => stream.append(v),
rlptest::Operation::AppendList(len) => stream.append_list(len),
rlptest::Operation::AppendRaw(ref raw, len) => stream.append_raw(raw, len),
rlptest::Operation::AppendEmpty => stream.append_empty_data()
};
}
assert_eq!(stream.out(), output);
});
}
}

View File

@ -743,7 +743,6 @@ impl Trie for TrieDB {
mod tests {
extern crate json_tests;
use self::json_tests::{trie, execute_tests_from_directory};
use rustc_serialize::hex::FromHex;
use triehash::*;
use hash::*;
use super::*;
@ -969,24 +968,6 @@ mod tests {
//assert!(false);
}
fn test_all(v: Vec<(Vec<u8>, Vec<u8>)>) {
let mut t = TrieDB::new_memory();
for i in 0..v.len() {
let key: &[u8]= &v[i].0;
let val: &[u8] = &v[i].1;
t.insert(&key, &val);
}
// trace!("{:?}", t);
// println!("{:?}", t);
// check lifetime
// let _q = t.at(&[b'd', b'o']).unwrap();
assert_eq!(*t.root(), trie_root(v));
}
fn random_key() -> Vec<u8> {
let chars = b"abcdefgrstuvwABCDEFGRSTUVW";
let mut ret: Vec<u8> = Vec::new();
@ -1041,52 +1022,6 @@ mod tests {
t
}
#[test]
fn test_at_dog() {
env_logger::init().ok();
let v = vec![
(From::from("do"), From::from("verb")),
(From::from("dog"), From::from("puppy")),
(From::from("doge"), From::from("coin")),
(From::from("horse"), From::from("stallion")),
];
test_all(v);
}
#[test]
fn test_more_data() {
let v = vec![
("0000000000000000000000000000000000000000000000000000000000000045".from_hex().unwrap(),
"22b224a1420a802ab51d326e29fa98e34c4f24ea".from_hex().unwrap()),
("0000000000000000000000000000000000000000000000000000000000000046".from_hex().unwrap(),
"67706c2076330000000000000000000000000000000000000000000000000000".from_hex().unwrap()),
("000000000000000000000000697c7b8c961b56f675d570498424ac8de1a918f6".from_hex().unwrap(),
"6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000".from_hex().unwrap()),
("0000000000000000000000007ef9e639e2733cb34e4dfc576d4b23f72db776b2".from_hex().unwrap(),
"4655474156000000000000000000000000000000000000000000000000000000".from_hex().unwrap()),
("000000000000000000000000ec4f34c97e43fbb2816cfd95e388353c7181dab1".from_hex().unwrap(),
"4e616d6552656700000000000000000000000000000000000000000000000000".from_hex().unwrap()),
("4655474156000000000000000000000000000000000000000000000000000000".from_hex().unwrap(),
"7ef9e639e2733cb34e4dfc576d4b23f72db776b2".from_hex().unwrap()),
("4e616d6552656700000000000000000000000000000000000000000000000000".from_hex().unwrap(),
"ec4f34c97e43fbb2816cfd95e388353c7181dab1".from_hex().unwrap()),
("6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000".from_hex().unwrap(),
"697c7b8c961b56f675d570498424ac8de1a918f6".from_hex().unwrap())
];
test_all(v);
}
#[test]
fn test_trie_json() {
println!("Json trie test: ");