diff --git a/Cargo.lock b/Cargo.lock index 6ccbcac6f..2aca73a3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -905,7 +905,6 @@ dependencies = [ "heapsize 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0", "kvdb-memorydb 0.1.0", - "kvdb-rocksdb 0.1.0", "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/util/Cargo.toml b/util/Cargo.toml index 2bd3654a1..0a1c6e22c 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -36,7 +36,6 @@ util-error = { path = "error" } kvdb = { path = "kvdb" } [dev-dependencies] -kvdb-rocksdb = { path = "kvdb-rocksdb" } kvdb-memorydb = { path = "kvdb-memorydb" } [features] diff --git a/util/src/journaldb/archivedb.rs b/util/src/journaldb/archivedb.rs index 1ea8e8559..2152c10d8 100644 --- a/util/src/journaldb/archivedb.rs +++ b/util/src/journaldb/archivedb.rs @@ -55,13 +55,6 @@ impl ArchiveDB { } } - /// Create a new instance with an anonymous temporary database. - #[cfg(test)] - fn new_temp() -> ArchiveDB { - let backing = Arc::new(::kvdb_memorydb::in_memory(0)); - Self::new(backing, None) - } - fn payload(&self, key: &H256) -> Option { self.backing.get(self.column, key).expect("Low-level database error. Some issue with your hard disk?") } @@ -206,18 +199,16 @@ mod tests { #![cfg_attr(feature="dev", allow(blacklisted_name))] #![cfg_attr(feature="dev", allow(similar_names))] - use std::path::Path; use keccak::keccak; use hashdb::{HashDB, DBValue}; use super::*; use journaldb::traits::JournalDB; - use kvdb_rocksdb::Database; - use bigint::hash::H32; + use kvdb_memorydb::in_memory; #[test] fn insert_same_in_fork() { // history is 1 - let mut jdb = ArchiveDB::new_temp(); + let mut jdb = ArchiveDB::new(Arc::new(in_memory(0)), None); let x = jdb.insert(b"X"); jdb.commit_batch(1, &keccak(b"1"), None).unwrap(); @@ -239,7 +230,7 @@ mod tests { #[test] fn long_history() { // history is 3 - let mut jdb = ArchiveDB::new_temp(); + let mut jdb = ArchiveDB::new(Arc::new(in_memory(0)), None); let h = jdb.insert(b"foo"); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); assert!(jdb.contains(&h)); @@ -257,7 +248,7 @@ mod tests { #[test] #[should_panic] fn multiple_owed_removal_not_allowed() { - let mut jdb = ArchiveDB::new_temp(); + let mut jdb = ArchiveDB::new(Arc::new(in_memory(0)), None); let h = jdb.insert(b"foo"); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); assert!(jdb.contains(&h)); @@ -271,7 +262,7 @@ mod tests { #[test] fn complex() { // history is 1 - let mut jdb = ArchiveDB::new_temp(); + let mut jdb = ArchiveDB::new(Arc::new(in_memory(0)), None); let foo = jdb.insert(b"foo"); let bar = jdb.insert(b"bar"); @@ -303,7 +294,7 @@ mod tests { #[test] fn fork() { // history is 1 - let mut jdb = ArchiveDB::new_temp(); + let mut jdb = ArchiveDB::new(Arc::new(in_memory(0)), None); let foo = jdb.insert(b"foo"); let bar = jdb.insert(b"bar"); @@ -329,7 +320,7 @@ mod tests { #[test] fn overwrite() { // history is 1 - let mut jdb = ArchiveDB::new_temp(); + let mut jdb = ArchiveDB::new(Arc::new(in_memory(0)), None); let foo = jdb.insert(b"foo"); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); @@ -348,7 +339,7 @@ mod tests { #[test] fn fork_same_key() { // history is 1 - let mut jdb = ArchiveDB::new_temp(); + let mut jdb = ArchiveDB::new(Arc::new(in_memory(0)), None); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); let foo = jdb.insert(b"foo"); @@ -362,19 +353,13 @@ mod tests { assert!(jdb.contains(&foo)); } - fn new_db(dir: &Path) -> ArchiveDB { - let db = Database::open_default(dir.to_str().unwrap()).unwrap(); - ArchiveDB::new(Arc::new(db), None) - } - #[test] fn reopen() { - let mut dir = ::std::env::temp_dir(); - dir.push(H32::random().hex()); + let shared_db = Arc::new(in_memory(0)); let bar = H256::random(); let foo = { - let mut jdb = new_db(&dir); + let mut jdb = ArchiveDB::new(shared_db.clone(), None); // history is 1 let foo = jdb.insert(b"foo"); jdb.emplace(bar.clone(), DBValue::from_slice(b"bar")); @@ -383,13 +368,13 @@ mod tests { }; { - let mut jdb = new_db(&dir); + let mut jdb = ArchiveDB::new(shared_db.clone(), None); jdb.remove(&foo); jdb.commit_batch(1, &keccak(b"1"), Some((0, keccak(b"0")))).unwrap(); } { - let mut jdb = new_db(&dir); + let mut jdb = ArchiveDB::new(shared_db, None); assert!(jdb.contains(&foo)); assert!(jdb.contains(&bar)); jdb.commit_batch(2, &keccak(b"2"), Some((1, keccak(b"1")))).unwrap(); @@ -398,11 +383,10 @@ mod tests { #[test] fn reopen_remove() { - let mut dir = ::std::env::temp_dir(); - dir.push(H32::random().hex()); + let shared_db = Arc::new(in_memory(0)); let foo = { - let mut jdb = new_db(&dir); + let mut jdb = ArchiveDB::new(shared_db.clone(), None); // history is 1 let foo = jdb.insert(b"foo"); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); @@ -416,7 +400,7 @@ mod tests { }; { - let mut jdb = new_db(&dir); + let mut jdb = ArchiveDB::new(shared_db, None); jdb.remove(&foo); jdb.commit_batch(3, &keccak(b"3"), Some((2, keccak(b"2")))).unwrap(); assert!(jdb.contains(&foo)); @@ -428,10 +412,9 @@ mod tests { #[test] fn reopen_fork() { - let mut dir = ::std::env::temp_dir(); - dir.push(H32::random().hex()); + let shared_db = Arc::new(in_memory(0)); let (foo, _, _) = { - let mut jdb = new_db(&dir); + let mut jdb = ArchiveDB::new(shared_db.clone(), None); // history is 1 let foo = jdb.insert(b"foo"); let bar = jdb.insert(b"bar"); @@ -446,7 +429,7 @@ mod tests { }; { - let mut jdb = new_db(&dir); + let mut jdb = ArchiveDB::new(shared_db, None); jdb.commit_batch(2, &keccak(b"2b"), Some((1, keccak(b"1b")))).unwrap(); assert!(jdb.contains(&foo)); } @@ -454,17 +437,17 @@ mod tests { #[test] fn returns_state() { - let temp = ::devtools::RandomTempPath::new(); + let shared_db = Arc::new(in_memory(0)); let key = { - let mut jdb = new_db(temp.as_path().as_path()); + let mut jdb = ArchiveDB::new(shared_db.clone(), None); let key = jdb.insert(b"foo"); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); key }; { - let jdb = new_db(temp.as_path().as_path()); + let jdb = ArchiveDB::new(shared_db, None); let state = jdb.state(&key); assert!(state.is_some()); } @@ -472,9 +455,7 @@ mod tests { #[test] fn inject() { - let temp = ::devtools::RandomTempPath::new(); - - let mut jdb = new_db(temp.as_path().as_path()); + let mut jdb = ArchiveDB::new(Arc::new(in_memory(0)), None); let key = jdb.insert(b"dog"); jdb.inject_batch().unwrap(); diff --git a/util/src/journaldb/earlymergedb.rs b/util/src/journaldb/earlymergedb.rs index 025955839..901ea5d8e 100644 --- a/util/src/journaldb/earlymergedb.rs +++ b/util/src/journaldb/earlymergedb.rs @@ -140,13 +140,6 @@ impl EarlyMergeDB { } } - /// Create a new instance with an anonymous temporary database. - #[cfg(test)] - fn new_temp() -> EarlyMergeDB { - let backing = Arc::new(::kvdb_memorydb::in_memory(0)); - Self::new(backing, None) - } - fn morph_key(key: &H256, index: u8) -> Bytes { let mut ret = (&**key).to_owned(); ret.push(index); @@ -554,19 +547,17 @@ mod tests { #![cfg_attr(feature="dev", allow(blacklisted_name))] #![cfg_attr(feature="dev", allow(similar_names))] - use std::path::Path; use keccak::keccak; use hashdb::{HashDB, DBValue}; use super::*; use super::super::traits::JournalDB; use ethcore_logger::init_log; - use kvdb_rocksdb::{DatabaseConfig}; - use bigint::hash::H32; + use kvdb_memorydb::in_memory; #[test] fn insert_same_in_fork() { // history is 1 - let mut jdb = EarlyMergeDB::new_temp(); + let mut jdb = new_db(); let x = jdb.insert(b"X"); jdb.commit_batch(1, &keccak(b"1"), None).unwrap(); @@ -595,7 +586,7 @@ mod tests { #[test] fn insert_older_era() { - let mut jdb = EarlyMergeDB::new_temp(); + let mut jdb = new_db(); let foo = jdb.insert(b"foo"); jdb.commit_batch(0, &keccak(b"0a"), None).unwrap(); assert!(jdb.can_reconstruct_refs()); @@ -616,7 +607,7 @@ mod tests { #[test] fn long_history() { // history is 3 - let mut jdb = EarlyMergeDB::new_temp(); + let mut jdb = new_db(); let h = jdb.insert(b"foo"); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); assert!(jdb.can_reconstruct_refs()); @@ -639,7 +630,7 @@ mod tests { #[test] fn complex() { // history is 1 - let mut jdb = EarlyMergeDB::new_temp(); + let mut jdb = new_db(); let foo = jdb.insert(b"foo"); let bar = jdb.insert(b"bar"); @@ -682,7 +673,7 @@ mod tests { #[test] fn fork() { // history is 1 - let mut jdb = EarlyMergeDB::new_temp(); + let mut jdb = new_db(); let foo = jdb.insert(b"foo"); let bar = jdb.insert(b"bar"); @@ -714,7 +705,7 @@ mod tests { #[test] fn overwrite() { // history is 1 - let mut jdb = EarlyMergeDB::new_temp(); + let mut jdb = new_db(); let foo = jdb.insert(b"foo"); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); @@ -737,7 +728,7 @@ mod tests { #[test] fn fork_same_key_one() { - let mut jdb = EarlyMergeDB::new_temp(); + let mut jdb = new_db(); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); assert!(jdb.can_reconstruct_refs()); @@ -762,7 +753,7 @@ mod tests { #[test] fn fork_same_key_other() { - let mut jdb = EarlyMergeDB::new_temp(); + let mut jdb = new_db(); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); assert!(jdb.can_reconstruct_refs()); @@ -787,7 +778,7 @@ mod tests { #[test] fn fork_ins_del_ins() { - let mut jdb = EarlyMergeDB::new_temp(); + let mut jdb = new_db(); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); assert!(jdb.can_reconstruct_refs()); @@ -818,20 +809,18 @@ mod tests { assert!(jdb.can_reconstruct_refs()); } - fn new_db(path: &Path) -> EarlyMergeDB { - let config = DatabaseConfig::with_columns(Some(1)); - let backing = Arc::new(::kvdb_rocksdb::Database::open(&config, path.to_str().unwrap()).unwrap()); - EarlyMergeDB::new(backing, Some(0)) + fn new_db() -> EarlyMergeDB { + let backing = Arc::new(in_memory(0)); + EarlyMergeDB::new(backing, None) } #[test] fn reopen() { - let mut dir = ::std::env::temp_dir(); - dir.push(H32::random().hex()); + let shared_db = Arc::new(in_memory(0)); let bar = H256::random(); let foo = { - let mut jdb = new_db(&dir); + let mut jdb = EarlyMergeDB::new(shared_db.clone(), None); // history is 1 let foo = jdb.insert(b"foo"); jdb.emplace(bar.clone(), DBValue::from_slice(b"bar")); @@ -841,14 +830,14 @@ mod tests { }; { - let mut jdb = new_db(&dir); + let mut jdb = EarlyMergeDB::new(shared_db.clone(), None); jdb.remove(&foo); jdb.commit_batch(1, &keccak(b"1"), Some((0, keccak(b"0")))).unwrap(); assert!(jdb.can_reconstruct_refs()); } { - let mut jdb = new_db(&dir); + let mut jdb = EarlyMergeDB::new(shared_db, None); assert!(jdb.contains(&foo)); assert!(jdb.contains(&bar)); jdb.commit_batch(2, &keccak(b"2"), Some((1, keccak(b"1")))).unwrap(); @@ -861,7 +850,7 @@ mod tests { fn insert_delete_insert_delete_insert_expunge() { init_log(); - let mut jdb = EarlyMergeDB::new_temp(); + let mut jdb = new_db(); // history is 4 let foo = jdb.insert(b"foo"); @@ -887,7 +876,7 @@ mod tests { #[test] fn forked_insert_delete_insert_delete_insert_expunge() { init_log(); - let mut jdb = EarlyMergeDB::new_temp(); + let mut jdb = new_db(); // history is 4 let foo = jdb.insert(b"foo"); @@ -933,7 +922,7 @@ mod tests { #[test] fn broken_assert() { - let mut jdb = EarlyMergeDB::new_temp(); + let mut jdb = new_db(); // history is 1 let foo = jdb.insert(b"foo"); @@ -962,7 +951,7 @@ mod tests { #[test] fn reopen_test() { - let mut jdb = EarlyMergeDB::new_temp(); + let mut jdb = new_db(); // history is 4 let foo = jdb.insert(b"foo"); @@ -997,13 +986,11 @@ mod tests { fn reopen_remove_three() { init_log(); - let mut dir = ::std::env::temp_dir(); - dir.push(H32::random().hex()); - + let shared_db = Arc::new(in_memory(0)); let foo = keccak(b"foo"); { - let mut jdb = new_db(&dir); + let mut jdb = EarlyMergeDB::new(shared_db.clone(), None); // history is 1 jdb.insert(b"foo"); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); @@ -1025,7 +1012,7 @@ mod tests { // incantation to reopen the db }; { - let mut jdb = new_db(&dir); + let mut jdb = EarlyMergeDB::new(shared_db.clone(), None); jdb.remove(&foo); jdb.commit_batch(4, &keccak(b"4"), Some((2, keccak(b"2")))).unwrap(); @@ -1034,7 +1021,7 @@ mod tests { // incantation to reopen the db }; { - let mut jdb = new_db(&dir); + let mut jdb = EarlyMergeDB::new(shared_db.clone(), None); jdb.commit_batch(5, &keccak(b"5"), Some((3, keccak(b"3")))).unwrap(); assert!(jdb.can_reconstruct_refs()); @@ -1042,7 +1029,7 @@ mod tests { // incantation to reopen the db }; { - let mut jdb = new_db(&dir); + let mut jdb = EarlyMergeDB::new(shared_db, None); jdb.commit_batch(6, &keccak(b"6"), Some((4, keccak(b"4")))).unwrap(); assert!(jdb.can_reconstruct_refs()); @@ -1052,10 +1039,10 @@ mod tests { #[test] fn reopen_fork() { - let mut dir = ::std::env::temp_dir(); - dir.push(H32::random().hex()); + let shared_db = Arc::new(in_memory(0)); + let (foo, bar, baz) = { - let mut jdb = new_db(&dir); + let mut jdb = EarlyMergeDB::new(shared_db.clone(), None); // history is 1 let foo = jdb.insert(b"foo"); let bar = jdb.insert(b"bar"); @@ -1073,7 +1060,7 @@ mod tests { }; { - let mut jdb = new_db(&dir); + let mut jdb = EarlyMergeDB::new(shared_db, None); jdb.commit_batch(2, &keccak(b"2b"), Some((1, keccak(b"1b")))).unwrap(); assert!(jdb.can_reconstruct_refs()); assert!(jdb.contains(&foo)); @@ -1084,9 +1071,7 @@ mod tests { #[test] fn inject() { - let temp = ::devtools::RandomTempPath::new(); - - let mut jdb = new_db(temp.as_path().as_path()); + let mut jdb = new_db(); let key = jdb.insert(b"dog"); jdb.inject_batch().unwrap(); diff --git a/util/src/journaldb/overlayrecentdb.rs b/util/src/journaldb/overlayrecentdb.rs index 7ffe4cf70..510bcbd6d 100644 --- a/util/src/journaldb/overlayrecentdb.rs +++ b/util/src/journaldb/overlayrecentdb.rs @@ -117,13 +117,6 @@ impl OverlayRecentDB { } } - /// Create a new instance with an anonymous temporary database. - #[cfg(test)] - pub fn new_temp() -> OverlayRecentDB { - let backing = Arc::new(::kvdb_memorydb::in_memory(0)); - Self::new(backing, None) - } - #[cfg(test)] fn can_reconstruct_refs(&self) -> bool { let reconstructed = Self::read_overlay(&*self.backing, self.column); @@ -462,24 +455,22 @@ mod tests { #![cfg_attr(feature="dev", allow(blacklisted_name))] #![cfg_attr(feature="dev", allow(similar_names))] - use std::path::Path; use keccak::keccak; use super::*; use hashdb::{HashDB, DBValue}; use ethcore_logger::init_log; use journaldb::JournalDB; - use kvdb_rocksdb::Database; - use bigint::hash::H32; + use kvdb_memorydb::in_memory; - fn new_db(path: &Path) -> OverlayRecentDB { - let backing = Arc::new(Database::open_default(path.to_str().unwrap()).unwrap()); + fn new_db() -> OverlayRecentDB { + let backing = Arc::new(in_memory(0)); OverlayRecentDB::new(backing, None) } #[test] fn insert_same_in_fork() { // history is 1 - let mut jdb = OverlayRecentDB::new_temp(); + let mut jdb = new_db(); let x = jdb.insert(b"X"); jdb.commit_batch(1, &keccak(b"1"), None).unwrap(); @@ -509,7 +500,7 @@ mod tests { #[test] fn long_history() { // history is 3 - let mut jdb = OverlayRecentDB::new_temp(); + let mut jdb = new_db(); let h = jdb.insert(b"foo"); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); assert!(jdb.can_reconstruct_refs()); @@ -532,7 +523,7 @@ mod tests { #[test] fn complex() { // history is 1 - let mut jdb = OverlayRecentDB::new_temp(); + let mut jdb = new_db(); let foo = jdb.insert(b"foo"); let bar = jdb.insert(b"bar"); @@ -575,7 +566,7 @@ mod tests { #[test] fn fork() { // history is 1 - let mut jdb = OverlayRecentDB::new_temp(); + let mut jdb = new_db(); let foo = jdb.insert(b"foo"); let bar = jdb.insert(b"bar"); @@ -607,7 +598,7 @@ mod tests { #[test] fn overwrite() { // history is 1 - let mut jdb = OverlayRecentDB::new_temp(); + let mut jdb = new_db(); let foo = jdb.insert(b"foo"); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); @@ -629,7 +620,7 @@ mod tests { #[test] fn fork_same_key_one() { - let mut jdb = OverlayRecentDB::new_temp(); + let mut jdb = new_db(); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); assert!(jdb.can_reconstruct_refs()); @@ -654,7 +645,7 @@ mod tests { #[test] fn fork_same_key_other() { - let mut jdb = OverlayRecentDB::new_temp(); + let mut jdb = new_db(); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); assert!(jdb.can_reconstruct_refs()); @@ -680,7 +671,7 @@ mod tests { #[test] fn fork_ins_del_ins() { - let mut jdb = OverlayRecentDB::new_temp(); + let mut jdb = new_db(); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); assert!(jdb.can_reconstruct_refs()); @@ -714,12 +705,11 @@ mod tests { #[test] fn reopen() { - let mut dir = ::std::env::temp_dir(); - dir.push(H32::random().hex()); + let shared_db = Arc::new(in_memory(0)); let bar = H256::random(); let foo = { - let mut jdb = new_db(&dir); + let mut jdb = OverlayRecentDB::new(shared_db.clone(), None); // history is 1 let foo = jdb.insert(b"foo"); jdb.emplace(bar.clone(), DBValue::from_slice(b"bar")); @@ -729,14 +719,14 @@ mod tests { }; { - let mut jdb = new_db(&dir); + let mut jdb = OverlayRecentDB::new(shared_db.clone(), None); jdb.remove(&foo); jdb.commit_batch(1, &keccak(b"1"), Some((0, keccak(b"0")))).unwrap(); assert!(jdb.can_reconstruct_refs()); } { - let mut jdb = new_db(&dir); + let mut jdb = OverlayRecentDB::new(shared_db.clone(), None); assert!(jdb.contains(&foo)); assert!(jdb.contains(&bar)); jdb.commit_batch(2, &keccak(b"2"), Some((1, keccak(b"1")))).unwrap(); @@ -748,7 +738,7 @@ mod tests { #[test] fn insert_delete_insert_delete_insert_expunge() { init_log(); - let mut jdb = OverlayRecentDB::new_temp(); + let mut jdb = new_db(); // history is 4 let foo = jdb.insert(b"foo"); @@ -774,7 +764,7 @@ mod tests { #[test] fn forked_insert_delete_insert_delete_insert_expunge() { init_log(); - let mut jdb = OverlayRecentDB::new_temp(); + let mut jdb = new_db(); // history is 4 let foo = jdb.insert(b"foo"); @@ -820,7 +810,7 @@ mod tests { #[test] fn broken_assert() { - let mut jdb = OverlayRecentDB::new_temp(); + let mut jdb = new_db(); let foo = jdb.insert(b"foo"); jdb.commit_batch(1, &keccak(b"1"), Some((0, keccak(b"0")))).unwrap(); @@ -848,7 +838,7 @@ mod tests { #[test] fn reopen_test() { - let mut jdb = OverlayRecentDB::new_temp(); + let mut jdb = new_db(); // history is 4 let foo = jdb.insert(b"foo"); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); @@ -882,13 +872,11 @@ mod tests { fn reopen_remove_three() { init_log(); - let mut dir = ::std::env::temp_dir(); - dir.push(H32::random().hex()); - + let shared_db = Arc::new(in_memory(0)); let foo = keccak(b"foo"); { - let mut jdb = new_db(&dir); + let mut jdb = OverlayRecentDB::new(shared_db.clone(), None); // history is 1 jdb.insert(b"foo"); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); @@ -910,7 +898,7 @@ mod tests { // incantation to reopen the db }; { - let mut jdb = new_db(&dir); + let mut jdb = OverlayRecentDB::new(shared_db.clone(), None); jdb.remove(&foo); jdb.commit_batch(4, &keccak(b"4"), Some((2, keccak(b"2")))).unwrap(); @@ -919,7 +907,7 @@ mod tests { // incantation to reopen the db }; { - let mut jdb = new_db(&dir); + let mut jdb = OverlayRecentDB::new(shared_db.clone(), None); jdb.commit_batch(5, &keccak(b"5"), Some((3, keccak(b"3")))).unwrap(); assert!(jdb.can_reconstruct_refs()); @@ -927,7 +915,7 @@ mod tests { // incantation to reopen the db }; { - let mut jdb = new_db(&dir); + let mut jdb = OverlayRecentDB::new(shared_db, None); jdb.commit_batch(6, &keccak(b"6"), Some((4, keccak(b"4")))).unwrap(); assert!(jdb.can_reconstruct_refs()); @@ -937,10 +925,10 @@ mod tests { #[test] fn reopen_fork() { - let mut dir = ::std::env::temp_dir(); - dir.push(H32::random().hex()); + let shared_db = Arc::new(in_memory(0)); + let (foo, bar, baz) = { - let mut jdb = new_db(&dir); + let mut jdb = OverlayRecentDB::new(shared_db.clone(), None); // history is 1 let foo = jdb.insert(b"foo"); let bar = jdb.insert(b"bar"); @@ -958,7 +946,7 @@ mod tests { }; { - let mut jdb = new_db(&dir); + let mut jdb = OverlayRecentDB::new(shared_db, None); jdb.commit_batch(2, &keccak(b"2b"), Some((1, keccak(b"1b")))).unwrap(); assert!(jdb.can_reconstruct_refs()); assert!(jdb.contains(&foo)); @@ -969,7 +957,7 @@ mod tests { #[test] fn insert_older_era() { - let mut jdb = OverlayRecentDB::new_temp(); + let mut jdb = new_db(); let foo = jdb.insert(b"foo"); jdb.commit_batch(0, &keccak(b"0a"), None).unwrap(); assert!(jdb.can_reconstruct_refs()); @@ -989,9 +977,7 @@ mod tests { #[test] fn inject() { - let temp = ::devtools::RandomTempPath::new(); - - let mut jdb = new_db(temp.as_path().as_path()); + let mut jdb = new_db(); let key = jdb.insert(b"dog"); jdb.inject_batch().unwrap(); @@ -1004,10 +990,10 @@ mod tests { #[test] fn earliest_era() { - let temp = ::devtools::RandomTempPath::new(); + let shared_db = Arc::new(in_memory(0)); // empty DB - let mut jdb = new_db(temp.as_path().as_path()); + let mut jdb = OverlayRecentDB::new(shared_db.clone(), None); assert!(jdb.earliest_era().is_none()); // single journalled era. @@ -1041,7 +1027,7 @@ mod tests { // reconstructed: no journal entries. drop(jdb); - let jdb = new_db(temp.as_path().as_path()); + let jdb = OverlayRecentDB::new(shared_db, None); assert_eq!(jdb.earliest_era(), None); } } diff --git a/util/src/journaldb/refcounteddb.rs b/util/src/journaldb/refcounteddb.rs index bcb41723e..0c2bd02ce 100644 --- a/util/src/journaldb/refcounteddb.rs +++ b/util/src/journaldb/refcounteddb.rs @@ -75,13 +75,6 @@ impl RefCountedDB { column: col, } } - - /// Create a new instance with an anonymous temporary database. - #[cfg(test)] - fn new_temp() -> RefCountedDB { - let backing = Arc::new(::kvdb_memorydb::in_memory(0)); - Self::new(backing, None) - } } impl HashDB for RefCountedDB { @@ -217,13 +210,19 @@ mod tests { use keccak::keccak; use hashdb::{HashDB, DBValue}; + use kvdb_memorydb::in_memory; use super::*; use super::super::traits::JournalDB; + fn new_db() -> RefCountedDB { + let backing = Arc::new(in_memory(0)); + RefCountedDB::new(backing, None) + } + #[test] fn long_history() { // history is 3 - let mut jdb = RefCountedDB::new_temp(); + let mut jdb = new_db(); let h = jdb.insert(b"foo"); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); assert!(jdb.contains(&h)); @@ -241,7 +240,7 @@ mod tests { #[test] fn latest_era_should_work() { // history is 3 - let mut jdb = RefCountedDB::new_temp(); + let mut jdb = new_db(); assert_eq!(jdb.latest_era(), None); let h = jdb.insert(b"foo"); jdb.commit_batch(0, &keccak(b"0"), None).unwrap(); @@ -260,7 +259,7 @@ mod tests { #[test] fn complex() { // history is 1 - let mut jdb = RefCountedDB::new_temp(); + let mut jdb = new_db(); let foo = jdb.insert(b"foo"); let bar = jdb.insert(b"bar"); @@ -298,7 +297,7 @@ mod tests { #[test] fn fork() { // history is 1 - let mut jdb = RefCountedDB::new_temp(); + let mut jdb = new_db(); let foo = jdb.insert(b"foo"); let bar = jdb.insert(b"bar"); @@ -325,7 +324,7 @@ mod tests { #[test] fn inject() { - let mut jdb = RefCountedDB::new_temp(); + let mut jdb = new_db(); let key = jdb.insert(b"dog"); jdb.inject_batch().unwrap(); diff --git a/util/src/lib.rs b/util/src/lib.rs index aac5024e0..4c50013a5 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -112,8 +112,6 @@ extern crate util_error as error; #[cfg(test)] extern crate kvdb_memorydb; -#[cfg(test)] -extern crate kvdb_rocksdb; #[macro_use] extern crate log as rlog;