Skip to content

Commit ea646ae

Browse files
committed
Test manual funding transaction Event::DiscardFunding generation
1 parent 683aa83 commit ea646ae

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

lightning/src/ln/functional_tests.rs

+43-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::chain::channelmonitor;
1818
use crate::chain::channelmonitor::{CLOSED_CHANNEL_UPDATE_ID, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY};
1919
use crate::chain::transaction::OutPoint;
2020
use crate::sign::{ecdsa::EcdsaChannelSigner, EntropySource, OutputSpender, SignerProvider};
21-
use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentPurpose, ClosureReason, HTLCDestination, PaymentFailureReason};
21+
use crate::events::{Event, FundingInfo, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentPurpose, ClosureReason, HTLCDestination, PaymentFailureReason};
2222
use crate::ln::types::{ChannelId, PaymentPreimage, PaymentSecret, PaymentHash};
2323
use crate::ln::channel::{CONCURRENT_INBOUND_HTLC_FEE_BUFFER, FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE, MIN_AFFORDABLE_HTLC_COUNT, get_holder_selected_channel_reserve_satoshis, OutboundV1Channel, InboundV1Channel, COINBASE_MATURITY, ChannelPhase};
2424
use crate::ln::channelmanager::{self, PaymentId, RAACommitmentOrder, PaymentSendFailure, RecipientOnionFields, BREAKDOWN_TIMEOUT, ENABLE_GOSSIP_TICKS, DISABLE_GOSSIP_TICKS, MIN_CLTV_EXPIRY_DELTA};
@@ -11209,6 +11209,48 @@ fn test_accept_inbound_channel_errors_queued() {
1120911209
open_channel_msg.common_fields.temporary_channel_id);
1121011210
}
1121111211

11212+
#[test]
11213+
fn test_manual_funding_abandon() {
11214+
let mut cfg = UserConfig::default();
11215+
cfg.channel_handshake_config.minimum_depth = 1;
11216+
let chanmon_cfgs = create_chanmon_cfgs(2);
11217+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
11218+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(cfg), Some(cfg)]);
11219+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
11220+
11221+
assert!(nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100_000, 0, 42, None, None).is_ok());
11222+
let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
11223+
11224+
nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel);
11225+
let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id());
11226+
11227+
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel);
11228+
let (temporary_channel_id, _tx, funding_outpoint) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100_000, 42);
11229+
nodes[0].node.unsafe_manual_funding_transaction_generated(temporary_channel_id, nodes[1].node.get_our_node_id(), funding_outpoint).unwrap();
11230+
check_added_monitors!(nodes[0], 0);
11231+
11232+
let funding_created = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id());
11233+
nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created);
11234+
check_added_monitors!(nodes[1], 1);
11235+
expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id());
11236+
11237+
let funding_signed = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id());
11238+
let err = msgs::ErrorMessage { channel_id: funding_signed.channel_id, data: "".to_string() };
11239+
nodes[0].node.handle_error(&nodes[1].node.get_our_node_id(), &err);
11240+
11241+
let close_events = nodes[0].node.get_and_clear_pending_events();
11242+
assert_eq!(close_events.len(), 2);
11243+
assert!(close_events.iter().any(|ev| matches!(ev, Event::ChannelClosed { .. })));
11244+
assert!(close_events.iter().any(|ev| match ev {
11245+
Event::DiscardFunding { channel_id, funding_info: FundingInfo::OutPoint { outpoint } } => {
11246+
assert_eq!(*channel_id, err.channel_id);
11247+
assert_eq!(*outpoint, funding_outpoint);
11248+
true
11249+
}
11250+
_ => false,
11251+
}));
11252+
}
11253+
1121211254
#[test]
1121311255
fn test_funding_signed_event() {
1121411256
let mut cfg = UserConfig::default();

0 commit comments

Comments
 (0)