]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Provide some test coverage of `shutdown` msgs for unfunded chans 2023-09-finish-force-close-deadlocks
authorMatt Corallo <git@bluematt.me>
Mon, 25 Sep 2023 19:49:15 +0000 (19:49 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 26 Sep 2023 00:38:17 +0000 (00:38 +0000)
We have code to handle receiving `shutdown` messages on unfudned
channels. However, it had no test coverage, which we add here.

lightning/src/ln/shutdown_tests.rs

index 01f2837abc5c691ce0c32296dbe16d3748226dd5..07bb72ce9cb7036179adff1083b23d39b1c76ea3 100644 (file)
@@ -253,6 +253,28 @@ fn test_lnd_bug_6039() {
        assert!(nodes[0].node.list_channels().is_empty());
 }
 
+#[test]
+fn shutdown_on_unfunded_channel() {
+       // Test receiving a shutdown prior to funding generation
+       let chanmon_cfgs = create_chanmon_cfgs(2);
+       let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
+       let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
+       let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
+
+       nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 1_000_000, 100_000, 0, None).unwrap();
+       let open_chan = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
+
+       // P2WSH
+       let script = Builder::new().push_int(0)
+               .push_slice(&[0; 20])
+               .into_script();
+
+       nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &msgs::Shutdown {
+               channel_id: open_chan.temporary_channel_id, scriptpubkey: script,
+       });
+       check_closed_event!(nodes[0], 1, ClosureReason::CounterpartyCoopClosedUnfundedChannel, [nodes[1].node.get_our_node_id()], 1_000_000);
+}
+
 #[test]
 fn expect_channel_shutdown_state_with_force_closure() {
        // Test sending a shutdown prior to channel_ready after funding generation