From 84128964fa5dce67a2b4e27f65deb75dc6b44c67 Mon Sep 17 00:00:00 2001 From: Antioch Peverell <30642645+antiochp@users.noreply.github.com> Date: Fri, 26 Jan 2018 17:35:58 -0500 Subject: [PATCH] Add test to cover case where a block has no coinbase outputs or kernels (#656) --- core/src/core/block.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/core/src/core/block.rs b/core/src/core/block.rs index 06bf83f06..e9b97ae58 100644 --- a/core/src/core/block.rs +++ b/core/src/core/block.rs @@ -898,6 +898,24 @@ mod test { assert!(b.validate().is_err()); } + #[test] + // block with no inputs/outputs/kernels + // no fees, no reward, no coinbase + fn very_empty_block() { + let b = Block { + header: BlockHeader::default(), + inputs: vec![], + outputs: vec![], + kernels: vec![], + }; + + assert_eq!( + b.verify_coinbase(), + Err(Error::Secp(secp::Error::IncorrectCommitSum)) + ); + + } + #[test] // builds a block with a tx spending another and check that cut_through occurred fn block_with_cut_through() { @@ -953,6 +971,18 @@ mod test { let b3 = b1.merge(b2); assert_eq!(b3.inputs.len(), 3); assert_eq!(b3.outputs.len(), 4); + assert_eq!(b3.kernels.len(), 5); + + // The merged block will actually fail validation (>1 coinbase kernels) + // Technically we support blocks with multiple coinbase kernels but we are + // artificially limiting it to 1 for now + assert!(b3.validate().is_err()); + assert_eq!( + b3.kernels + .iter() + .filter(|x| x.features.contains(COINBASE_KERNEL)) + .count(), + 2); } #[test]