pop & test

This commit is contained in:
NikVolf 2016-10-19 15:02:28 +03:00
parent cb7766ddd6
commit c3d854d848
1 changed files with 18 additions and 0 deletions

View File

@ -97,6 +97,10 @@ impl Queue {
Ok(())
}
pub fn pop_valid(&self) -> Option<(H256, VerifiedBlock)> {
self.verified.write().pop_front()
}
}
#[cfg(test)]
@ -197,4 +201,18 @@ mod tests {
assert_eq!(queue.block_status(&test_data::block_h1().hash()), BlockStatus::Valid);
assert_eq!(queue.block_status(&test_data::block_h2().hash()), BlockStatus::Valid);
}
#[test]
fn pop() {
let queue = Queue::new(Box::new(FacileVerifier));
let block = test_data::block1();
let hash = block.hash();
queue.push(block).unwrap();
queue.process();
let (h, _b) = queue.pop_valid().unwrap();
assert_eq!(queue.block_status(&hash), BlockStatus::Absent);
assert_eq!(h, hash);
}
}