From c3d854d848fb9585272cb034e8d65c80f9cfaade Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 19 Oct 2016 15:02:28 +0300 Subject: [PATCH] pop & test --- verification/src/queue.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/verification/src/queue.rs b/verification/src/queue.rs index 674554dc..c94f9306 100644 --- a/verification/src/queue.rs +++ b/verification/src/queue.rs @@ -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); + } }