X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=lightning%2Fsrc%2Fln%2Fchanmon_update_fail_tests.rs;h=fdcf7c2de70ee71edb5bd8e3d2ff4dfdafa67606;hb=6d98aedaf5dba6565839aa1b806ed730e0c7935c;hp=2e758aa48c82a0eecf1a9761741cf37e81ecabc6;hpb=f8450a7c2cd6d31b0691e771c1b36ea857c26c2a;p=rust-lightning diff --git a/lightning/src/ln/chanmon_update_fail_tests.rs b/lightning/src/ln/chanmon_update_fail_tests.rs index 2e758aa4..fdcf7c2d 100644 --- a/lightning/src/ln/chanmon_update_fail_tests.rs +++ b/lightning/src/ln/chanmon_update_fail_tests.rs @@ -13,6 +13,7 @@ //! here. See also the chanmon_fail_consistency fuzz test. use bitcoin::blockdata::block::{Block, BlockHeader}; +use bitcoin::blockdata::constants::genesis_block; use bitcoin::hash_types::BlockHash; use bitcoin::network::constants::Network; use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr}; @@ -30,6 +31,7 @@ use util::enforcing_trait_impls::EnforcingSigner; use util::events::{Event, MessageSendEvent, MessageSendEventsProvider}; use util::errors::APIError; use util::ser::{ReadableArgs, Writeable}; +use util::test_utils::TestBroadcaster; use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::hashes::Hash; @@ -38,7 +40,8 @@ use ln::functional_test_utils::*; use util::test_utils; -use std::collections::HashMap; +use prelude::*; +use std::sync::{Arc, Mutex}; // If persister_fail is true, we have the persister return a PermanentFailure // instead of the higher-level ChainMonitor. @@ -106,6 +109,13 @@ fn test_monitor_and_persister_update_fail() { let chain_source = test_utils::TestChainSource::new(Network::Testnet); let logger = test_utils::TestLogger::with_id(format!("node {}", 0)); let persister = test_utils::TestPersister::new(); + let tx_broadcaster = TestBroadcaster { + txn_broadcasted: Mutex::new(Vec::new()), + // Because we will connect a block at height 200 below, we need the TestBroadcaster to know + // that we are at height 200 so that it doesn't think we're violating the time lock + // requirements of transactions broadcasted at that point. + blocks: Arc::new(Mutex::new(vec![(genesis_block(Network::Testnet).header, 200); 200])), + }; let chain_mon = { let monitors = nodes[0].chain_monitor.chain_monitor.monitors.read().unwrap(); let monitor = monitors.get(&outpoint).unwrap(); @@ -114,7 +124,7 @@ fn test_monitor_and_persister_update_fail() { let new_monitor = <(BlockHash, ChannelMonitor)>::read( &mut ::std::io::Cursor::new(&w.0), &test_utils::OnlyReadsKeysInterface {}).unwrap().1; assert!(new_monitor == *monitor); - let chain_mon = test_utils::TestChainMonitor::new(Some(&chain_source), &chanmon_cfgs[0].tx_broadcaster, &logger, &chanmon_cfgs[0].fee_estimator, &persister, &node_cfgs[0].keys_manager); + let chain_mon = test_utils::TestChainMonitor::new(Some(&chain_source), &tx_broadcaster, &logger, &chanmon_cfgs[0].fee_estimator, &persister, &node_cfgs[0].keys_manager); assert!(chain_mon.watch_channel(outpoint, new_monitor).is_ok()); chain_mon };