Skip to content

Commit 6f92436

Browse files
committed
f enforce monitor update structure in new test
1 parent c4d9854 commit 6f92436

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lightning/src/ln/reorg_tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ fn do_test_unconf_chan(reload_node: bool, reorg_after_reload: bool) {
200200
let new_chain_monitor: test_utils::TestChainMonitor;
201201
let nodes_0_deserialized: ChannelManager<EnforcingSigner, &test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>;
202202
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
203-
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
203+
let chan_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2;
204204

205205
let channel_state = nodes[0].node.channel_state.lock().unwrap();
206206
assert_eq!(channel_state.by_id.len(), 1);
@@ -278,6 +278,7 @@ fn do_test_unconf_chan(reload_node: bool, reorg_after_reload: bool) {
278278
}
279279
}
280280

281+
*nodes[0].chain_monitor.expect_channel_force_closed.lock().unwrap() = Some((chan_id, true));
281282
nodes[0].node.test_process_background_events(); // Required to free the pending background monitor update
282283
check_added_monitors!(nodes[0], 1);
283284
}

lightning/src/util/test_utils.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub struct TestChainMonitor<'a> {
8585
// If this is set to Some(), after the next return, we'll always return this until update_ret
8686
// is changed:
8787
pub next_update_ret: Mutex<Option<Result<(), channelmonitor::ChannelMonitorUpdateErr>>>,
88+
pub expect_channel_force_closed: Mutex<Option<([u8; 32], bool)>>,
8889
}
8990
impl<'a> TestChainMonitor<'a> {
9091
pub fn new(chain_source: Option<&'a TestChainSource>, broadcaster: &'a chaininterface::BroadcasterInterface, logger: &'a TestLogger, fee_estimator: &'a TestFeeEstimator, persister: &'a channelmonitor::Persist<EnforcingSigner>, keys_manager: &'a TestKeysInterface) -> Self {
@@ -95,6 +96,7 @@ impl<'a> TestChainMonitor<'a> {
9596
keys_manager,
9697
update_ret: Mutex::new(None),
9798
next_update_ret: Mutex::new(None),
99+
expect_channel_force_closed: Mutex::new(None),
98100
}
99101
}
100102
}
@@ -129,6 +131,14 @@ impl<'a> chain::Watch<EnforcingSigner> for TestChainMonitor<'a> {
129131
assert!(channelmonitor::ChannelMonitorUpdate::read(
130132
&mut ::std::io::Cursor::new(&w.0)).unwrap() == update);
131133

134+
if let Some(exp) = self.expect_channel_force_closed.lock().unwrap().take() {
135+
assert_eq!(funding_txo.to_channel_id(), exp.0);
136+
assert_eq!(update.updates.len(), 1);
137+
if let channelmonitor::ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast } = update.updates[0] {
138+
assert_eq!(should_broadcast, exp.1);
139+
} else { panic!(); }
140+
}
141+
132142
self.latest_monitor_update_id.lock().unwrap().insert(funding_txo.to_channel_id(), (funding_txo, update.update_id));
133143
let update_res = self.chain_monitor.update_channel(funding_txo, update);
134144
// At every point where we get a monitor update, we should be able to send a useful monitor

0 commit comments

Comments
 (0)