X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Ffunctional_test_utils.rs;h=53ba82c4a0dfb92f612c3bc6891f165a6d98654a;hb=46ac4c796a31c1cb1334e57a98e0dfa09f009539;hp=ed1585f68e4f19677b4c847bc1c7bf06c2e4404a;hpb=5cd1857c5598211ec0180f8651e5bf168ae95bf3;p=rust-lightning diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index ed1585f6..53ba82c4 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -62,7 +62,7 @@ pub fn mine_transaction<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &Transac pub fn confirm_transaction_at<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &Transaction, conf_height: u32) { let first_connect_height = node.best_block_info().1 + 1; assert!(first_connect_height <= conf_height); - if conf_height - first_connect_height >= 1 { + if conf_height > first_connect_height { connect_blocks(node, conf_height - first_connect_height); } let mut block = Block { @@ -281,7 +281,7 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> { let mut w = test_utils::TestVecWriter(Vec::new()); self.node.write(&mut w).unwrap(); <(BlockHash, ChannelManager)>::read(&mut ::std::io::Cursor::new(w.0), ChannelManagerReadArgs { - default_config: UserConfig::default(), + default_config: *self.node.get_current_default_configuration(), keys_manager: self.keys_manager, fee_estimator: &test_utils::TestFeeEstimator { sat_per_kw: 253 }, chain_monitor: self.chain_monitor, @@ -365,6 +365,24 @@ macro_rules! get_event_msg { } } +/// Get a specific event from the pending events queue. +#[macro_export] +macro_rules! get_event { + ($node: expr, $event_type: path) => { + { + let mut events = $node.node.get_and_clear_pending_events(); + assert_eq!(events.len(), 1); + let ev = events.pop().unwrap(); + match ev { + $event_type { .. } => { + ev + }, + _ => panic!("Unexpected event"), + } + } + } +} + #[cfg(test)] macro_rules! get_htlc_update_msgs { ($node: expr, $node_id: expr) => { @@ -393,7 +411,8 @@ macro_rules! get_feerate { } } -#[cfg(test)] +/// Returns any local commitment transactions for the channel. +#[macro_export] macro_rules! get_local_commitment_txn { ($node: expr, $channel_id: expr) => { { @@ -473,7 +492,7 @@ pub fn create_chan_between_nodes_with_value_init<'a, 'b, 'c>(node_a: &Node<'a, ' let (temporary_channel_id, tx, funding_output) = create_funding_transaction(node_a, channel_value, 42); - node_a.node.funding_transaction_generated(&temporary_channel_id, funding_output); + node_a.node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap(); check_added_monitors!(node_a, 0); node_b.node.handle_funding_created(&node_a.node.get_our_node_id(), &get_event_msg!(node_a, MessageSendEvent::SendFundingCreated, node_b.node.get_our_node_id())); @@ -493,14 +512,11 @@ pub fn create_chan_between_nodes_with_value_init<'a, 'b, 'c>(node_a: &Node<'a, ' } let events_4 = node_a.node.get_and_clear_pending_events(); - assert_eq!(events_4.len(), 1); - match events_4[0] { - Event::FundingBroadcastSafe { ref funding_txo, user_channel_id } => { - assert_eq!(user_channel_id, 42); - assert_eq!(*funding_txo, funding_output); - }, - _ => panic!("Unexpected event"), - }; + assert_eq!(events_4.len(), 0); + + assert_eq!(node_a.tx_broadcaster.txn_broadcasted.lock().unwrap().len(), 1); + assert_eq!(node_a.tx_broadcaster.txn_broadcasted.lock().unwrap()[0], tx); + node_a.tx_broadcaster.txn_broadcasted.lock().unwrap().clear(); tx } @@ -899,7 +915,7 @@ macro_rules! expect_pending_htlcs_forwardable { }} } -#[cfg(test)] +#[cfg(any(test, feature = "unstable"))] macro_rules! expect_payment_received { ($node: expr, $expected_payment_hash: expr, $expected_recv_value: expr) => { let events = $node.node.get_and_clear_pending_events();