pow chain store tests added

This commit is contained in:
Grant Wuerker 2018-11-11 13:15:39 -06:00
parent 7cc2800916
commit 20961c612a
2 changed files with 41 additions and 1 deletions

View File

@ -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"

View File

@ -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());
}
}