test storage stub

This commit is contained in:
NikVolf 2016-10-21 19:31:33 +03:00
parent e3558fc269
commit 526f2f023e
2 changed files with 62 additions and 1 deletions

View File

@ -21,5 +21,5 @@ pub enum BlockRef {
Hash(primitives::hash::H256),
}
pub use storage::{Storage, Store};
pub use storage::{Storage, Store, Error};
pub use kvdb::Database;

View File

@ -15,3 +15,64 @@ impl Verify for ChainVerifier {
Ok(Chain::Main)
}
}
#[cfg(test)]
mod tests {
use primitives::hash::H256;
use chain;
use std::collections::HashMap;
use db::{self, BlockRef, Store};
use serialization;
use serialization::bytes::Bytes;
struct TestStorage {
blocks: HashMap<H256, chain::Block>,
heights: HashMap<usize, H256>,
}
impl TestStorage {
fn resolve_hash(&self, block_ref: BlockRef) -> Option<H256> {
match block_ref {
BlockRef::Number(n) => self.block_hash(n),
BlockRef::Hash(h) => Some(h),
}
}
}
impl Store for TestStorage {
fn block_hash(&self, number: u64) -> Option<H256> {
self.heights.get(&(number as usize)).map(|h| h.clone())
}
fn block_header_bytes(&self, block_ref: BlockRef) -> Option<Bytes> {
None
}
fn block_transaction_hashes(&self, block_ref: BlockRef) -> Vec<H256> {
Vec::new()
}
fn transaction_bytes(&self, hash: &H256) -> Option<Bytes> {
None
}
fn transaction(&self, hash: &H256) -> Option<chain::Transaction> {
None
}
fn block_transactions(&self, block_ref: BlockRef) -> Vec<chain::Transaction> {
Vec::new()
}
fn block(&self, block_ref: BlockRef) -> Option<chain::Block> {
None
}
fn insert_block(&self, block: &chain::Block) -> Result<(), db::Error> {
Ok(())
}
}
}