pow chain store tests added
This commit is contained in:
parent
7cc2800916
commit
20961c612a
@ -11,3 +11,4 @@ rocksdb = "0.10.1"
|
||||
ssz = { path = "../../beacon_chain/utils/ssz" }
|
||||
ssz_helpers = { path = "../../beacon_chain/utils/ssz_helpers" }
|
||||
types = { path = "../../beacon_chain/types" }
|
||||
rand = "0.5.5"
|
||||
|
@ -4,6 +4,7 @@ use super::{
|
||||
DBError,
|
||||
};
|
||||
use super::POW_CHAIN_DB_COLUMN as DB_COLUMN;
|
||||
extern crate rand;
|
||||
|
||||
pub struct PoWChainStore<T>
|
||||
where T: ClientDB
|
||||
@ -31,4 +32,42 @@ impl<T: ClientDB> PoWChainStore<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: add tests once a memory-db is implemented
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use super::super::super::MemoryDB;
|
||||
|
||||
#[test]
|
||||
fn test_put_block_hash() {
|
||||
let db = Arc::new(MemoryDB::open());
|
||||
let store = PoWChainStore::new(db.clone());
|
||||
|
||||
let hash: &[u8] = &[rand::random()];
|
||||
store.put_block_hash(hash);
|
||||
|
||||
assert!(db.exists(DB_COLUMN, hash).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_block_hash_exists() {
|
||||
let db = Arc::new(MemoryDB::open());
|
||||
let store = PoWChainStore::new(db.clone());
|
||||
|
||||
let hash: &[u8] = &[rand::random()];
|
||||
db.put(DB_COLUMN, hash, &[0]);
|
||||
|
||||
assert!(store.block_hash_exists(hash).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_block_hash_does_not_exist() {
|
||||
let db = Arc::new(MemoryDB::open());
|
||||
let store = PoWChainStore::new(db.clone());
|
||||
|
||||
let hash: &[u8] = &[rand::random()];
|
||||
let other_hash: &[u8] = &[rand::random()];
|
||||
db.put(DB_COLUMN, hash, &[0]);
|
||||
|
||||
assert!(!store.block_hash_exists(other_hash).unwrap());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user