Skip to content

Commit

Permalink
Merge branch 'master' into ao-update-deps
Browse files Browse the repository at this point in the history
* master:
  Split trie-db test in a different crate. (#111)
  • Loading branch information
ordian committed Jan 5, 2021
2 parents 4ef3104 + f72a465 commit 8b9144e
Show file tree
Hide file tree
Showing 32 changed files with 2,613 additions and 2,382 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ members = [
"test-support/trie-standardmap",
"test-support/trie-bench",
"trie-db",
"trie-root"
"trie-db/test",
"trie-root",
"trie-root/test"
]
9 changes: 4 additions & 5 deletions test-support/reference-trie/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ use trie_db::{
use std::borrow::Borrow;
use keccak_hasher::KeccakHasher;

pub use trie_db::{
decode_compact, encode_compact,
nibble_ops, NibbleSlice, NibbleVec, NodeCodec, proof, Record, Recorder,
Trie, TrieConfiguration, TrieDB, TrieDBIterator, TrieDBMut, TrieDBNodeIterator, TrieError,
TrieIterator, TrieLayout, TrieMut,
use trie_db::{
nibble_ops, NodeCodec,
Trie, TrieConfiguration,
TrieLayout, TrieMut,
};
pub use trie_root::TrieStream;
pub mod node {
Expand Down
16 changes: 0 additions & 16 deletions trie-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,9 @@ hash-db = { path = "../hash-db", default-features = false, version = "0.15.2"}
hashbrown = { version = "0.9.1", default-features = false, features = ["ahash"] }
rustc-hex = { version = "2.1.0", default-features = false, optional = true }

[dev-dependencies]
env_logger = "0.8"
memory-db = { path = "../memory-db", version = "0.25.0" }
rand = { version = "0.8.1", default-features = false, features = ["small_rng"] }
trie-root = { path = "../trie-root", version = "0.16.0"}
trie-standardmap = { path = "../test-support/trie-standardmap", version = "0.15.2" }
keccak-hasher = { path = "../test-support/keccak-hasher", version = "0.15.2" }
# DISABLE the following line when publishing until cyclic dependencies are resolved https://github.com/rust-lang/cargo/issues/4242
reference-trie = { path = "../test-support/reference-trie", default-features = false, version = "0.22.0" }
hex-literal = "0.3"
criterion = "0.3"

[features]
default = ["std"]
std = [
"hash-db/std",
"rustc-hex",
]

[[bench]]
name = "bench"
harness = false
26 changes: 1 addition & 25 deletions trie-db/src/fatdb.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017, 2018 Parity Technologies
// Copyright 2017, 2020 Parity Technologies
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -125,27 +125,3 @@ where
})
}
}

#[cfg(test)]
mod test {
use memory_db::{MemoryDB, HashKey};
use crate::DBValue;
use keccak_hasher::KeccakHasher;
use reference_trie::{RefFatDBMut, RefFatDB, Trie, TrieMut};

#[test]
fn fatdb_to_trie() {
let mut memdb = MemoryDB::<KeccakHasher, HashKey<_>, DBValue>::default();
let mut root = Default::default();
{
let mut t = RefFatDBMut::new(&mut memdb, &mut root);
t.insert(&[0x01u8, 0x23], &[0x01u8, 0x23]).unwrap();
}
let t = RefFatDB::new(&memdb, &root).unwrap();
assert_eq!(t.get(&[0x01u8, 0x23]).unwrap().unwrap(), vec![0x01u8, 0x23]);
assert_eq!(
t.iter().unwrap().map(Result::unwrap).collect::<Vec<_>>(),
vec![(vec![0x01u8, 0x23], vec![0x01u8, 0x23])]
);
}
}
41 changes: 1 addition & 40 deletions trie-db/src/fatdbmut.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017, 2018 Parity Technologies
// Copyright 2017, 2020 Parity Technologies
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -106,42 +106,3 @@ where
Ok(out)
}
}

#[cfg(test)]
mod test {
use memory_db::{MemoryDB, HashKey};
use hash_db::{Hasher, EMPTY_PREFIX};
use keccak_hasher::KeccakHasher;
use reference_trie::{RefFatDBMut, RefTrieDB, Trie, TrieMut};

#[test]
fn fatdbmut_to_trie() {
let mut memdb = MemoryDB::<KeccakHasher, HashKey<_>, _>::default();
let mut root = Default::default();
{
let mut t = RefFatDBMut::new(&mut memdb, &mut root);
t.insert(&[0x01u8, 0x23], &[0x01u8, 0x23]).unwrap();
}
let t = RefTrieDB::new(&memdb, &root).unwrap();
assert_eq!(
t.get(&KeccakHasher::hash(&[0x01u8, 0x23])),
Ok(Some(vec![0x01u8, 0x23])),
);
}

#[test]
fn fatdbmut_insert_remove_key_mapping() {
let mut memdb = MemoryDB::<KeccakHasher, HashKey<_>, _>::default();
let mut root = Default::default();
let key = [0x01u8, 0x23];
let val = [0x01u8, 0x24];
let key_hash = KeccakHasher::hash(&key);
let aux_hash = KeccakHasher::hash(&key_hash);
let mut t = RefFatDBMut::new(&mut memdb, &mut root);
t.insert(&key, &val).unwrap();
assert_eq!(t.get(&key), Ok(Some(val.to_vec())));
assert_eq!(t.db().get(&aux_hash, EMPTY_PREFIX), Some(key.to_vec()));
t.remove(&key).unwrap();
assert_eq!(t.db().get(&aux_hash, EMPTY_PREFIX), None);
}
}
Loading

0 comments on commit 8b9144e

Please sign in to comment.