X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-block-sync%2Fsrc%2Ftest_utils.rs;h=0c402deb3294663527afaab0011cea1f627569ef;hb=f99301dd8a7f056c0ed09ec827fddc00f325b3e5;hp=fe57c0c606d02d5cfbc5bf79f3bba1637904711f;hpb=9afc1ec36c39a0a1c8aecd68653d53d5ccde7819;p=rust-lightning diff --git a/lightning-block-sync/src/test_utils.rs b/lightning-block-sync/src/test_utils.rs index fe57c0c6..0c402deb 100644 --- a/lightning-block-sync/src/test_utils.rs +++ b/lightning-block-sync/src/test_utils.rs @@ -6,6 +6,8 @@ use bitcoin::blockdata::constants::genesis_block; use bitcoin::hash_types::BlockHash; use bitcoin::network::constants::Network; use bitcoin::util::uint::Uint256; +use bitcoin::util::hash::bitcoin_merkle_root; +use bitcoin::{PackedLockTime, Transaction}; use lightning::chain; @@ -37,16 +39,27 @@ impl Blockchain { let prev_block = &self.blocks[i - 1]; let prev_blockhash = prev_block.block_hash(); let time = prev_block.header.time + height as u32; + // Must have at least one transaction, because the merkle root is not defined for an empty block + // and we would fail when we later checked, as of bitcoin crate 0.28.0. + // Note that elsewhere in tests we assume that the merkle root of an empty block is all zeros, + // but that's OK because those tests don't trigger the check. + let coinbase = Transaction { + version: 0, + lock_time: PackedLockTime::ZERO, + input: vec![], + output: vec![] + }; + let merkle_root = bitcoin_merkle_root(vec![coinbase.txid().as_hash()].into_iter()).unwrap(); self.blocks.push(Block { header: BlockHeader { version: 0, prev_blockhash, - merkle_root: Default::default(), + merkle_root: merkle_root.into(), time, bits, nonce: 0, }, - txdata: vec![], + txdata: vec![coinbase], }); } self @@ -166,7 +179,7 @@ impl BlockSource for Blockchain { pub struct NullChainListener; impl chain::Listen for NullChainListener { - fn block_connected(&self, _block: &Block, _height: u32) {} + fn filtered_block_connected(&self, _header: &BlockHeader, _txdata: &chain::transaction::TransactionData, _height: u32) {} fn block_disconnected(&self, _header: &BlockHeader, _height: u32) {} } @@ -195,13 +208,13 @@ impl MockChainListener { } impl chain::Listen for MockChainListener { - fn block_connected(&self, block: &Block, height: u32) { + fn filtered_block_connected(&self, header: &BlockHeader, _txdata: &chain::transaction::TransactionData, height: u32) { match self.expected_blocks_connected.borrow_mut().pop_front() { None => { - panic!("Unexpected block connected: {:?}", block.block_hash()); + panic!("Unexpected block connected: {:?}", header.block_hash()); }, Some(expected_block) => { - assert_eq!(block.block_hash(), expected_block.header.block_hash()); + assert_eq!(header.block_hash(), expected_block.header.block_hash()); assert_eq!(height, expected_block.height); }, }