Add test to cover case where a block has no coinbase outputs or kernels (#656)

This commit is contained in:
Antioch Peverell 2018-01-26 17:35:58 -05:00 committed by Ignotus Peverell
parent 5a7d22977e
commit 84128964fa

View file

@ -898,6 +898,24 @@ mod test {
assert!(b.validate().is_err()); 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] #[test]
// builds a block with a tx spending another and check that cut_through occurred // builds a block with a tx spending another and check that cut_through occurred
fn block_with_cut_through() { fn block_with_cut_through() {
@ -953,6 +971,18 @@ mod test {
let b3 = b1.merge(b2); let b3 = b1.merge(b2);
assert_eq!(b3.inputs.len(), 3); assert_eq!(b3.inputs.len(), 3);
assert_eq!(b3.outputs.len(), 4); 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] #[test]