From: Antoine Riard Date: Mon, 13 Sep 2021 16:24:56 +0000 (-0400) Subject: -f more tests X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=987ef1ca00fd09980c9e2dba8152a5a4c7b2c1a9;p=rust-lightning -f more tests --- diff --git a/lightning/src/ln/chanmon_update_fail_tests.rs b/lightning/src/ln/chanmon_update_fail_tests.rs index 946da77aa..680ff9182 100644 --- a/lightning/src/ln/chanmon_update_fail_tests.rs +++ b/lightning/src/ln/chanmon_update_fail_tests.rs @@ -2647,6 +2647,8 @@ fn test_temporary_error_during_shutdown() { assert_eq!(txn_a, txn_b); assert_eq!(txn_a.len(), 1); check_spends!(txn_a[0], funding_tx); + check_closed_event!(nodes[1], 1); + check_closed_event!(nodes[0], 1); } #[test] @@ -2667,6 +2669,7 @@ fn test_permanent_error_during_sending_shutdown() { assert!(nodes[0].node.close_channel(&channel_id).is_ok()); check_closed_broadcast!(nodes[0], true); check_added_monitors!(nodes[0], 2); + check_closed_event!(nodes[0], 1); } #[test] @@ -2689,6 +2692,7 @@ fn test_permanent_error_during_handling_shutdown() { nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &InitFeatures::known(), &shutdown); check_closed_broadcast!(nodes[1], true); check_added_monitors!(nodes[1], 2); + check_closed_event!(nodes[1], 1); } #[test] diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index b7b1e94bc..f44fed6c2 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -2581,11 +2581,15 @@ fn test_htlc_on_chain_success() { added_monitors.clear(); } let forwarded_events = nodes[1].node.get_and_clear_pending_events(); - assert_eq!(forwarded_events.len(), 2); - if let Event::PaymentForwarded { fee_earned_msat: Some(1000), claim_from_onchain_tx: true } = forwarded_events[0] { - } else { panic!(); } + assert_eq!(forwarded_events.len(), 3); + match forwarded_events[0] { + Event::ChannelClosed { .. } => {} + _ => panic!("Unexpected event"), + } if let Event::PaymentForwarded { fee_earned_msat: Some(1000), claim_from_onchain_tx: true } = forwarded_events[1] { } else { panic!(); } + if let Event::PaymentForwarded { fee_earned_msat: Some(1000), claim_from_onchain_tx: true } = forwarded_events[2] { + } else { panic!(); } let events = nodes[1].node.get_and_clear_pending_msg_events(); { let mut added_monitors = nodes[1].chain_monitor.added_monitors.lock().unwrap(); @@ -2652,7 +2656,7 @@ fn test_htlc_on_chain_success() { mine_transaction(&nodes[1], &node_a_commitment_tx[0]); check_closed_broadcast!(nodes[1], true); check_added_monitors!(nodes[1], 1); - check_closed_event!(nodes[1], 2); + check_closed_event!(nodes[1], 1); let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clone(); assert_eq!(node_txn.len(), 6); // ChannelManager : 3 (commitment tx + HTLC-Sucess * 2), ChannelMonitor : 3 (HTLC-Success, 2* RBF bumps of above HTLC txn) let commitment_spend = @@ -5079,7 +5083,19 @@ fn test_onchain_to_onchain_claim() { let header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[1].best_block_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42}; connect_block(&nodes[1], &Block { header, txdata: vec![c_txn[1].clone(), c_txn[2].clone()]}); check_added_monitors!(nodes[1], 1); - expect_payment_forwarded!(nodes[1], Some(1000), true); + let events = nodes[1].node.get_and_clear_pending_events(); + assert_eq!(events.len(), 2); + match events[0] { + Event::ChannelClosed { .. } => {} + _ => panic!("Unexpected event"), + } + match events[1] { + Event::PaymentForwarded { fee_earned_msat, claim_from_onchain_tx } => { + assert_eq!(fee_earned_msat, Some(1000)); + assert_eq!(claim_from_onchain_tx, true); + }, + _ => panic!("Unexpected event"), + } { let mut b_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap(); // ChannelMonitor: claim tx @@ -5088,10 +5104,8 @@ fn test_onchain_to_onchain_claim() { b_txn.clear(); } check_added_monitors!(nodes[1], 1); - check_closed_event!(nodes[1], 1); let msg_events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(msg_events.len(), 3); - check_added_monitors!(nodes[1], 1); match msg_events[0] { MessageSendEvent::BroadcastChannelUpdate { .. } => {}, _ => panic!("Unexpected event"), diff --git a/lightning/src/ln/monitor_tests.rs b/lightning/src/ln/monitor_tests.rs index 237e62324..9c1695148 100644 --- a/lightning/src/ln/monitor_tests.rs +++ b/lightning/src/ln/monitor_tests.rs @@ -65,7 +65,7 @@ fn chanmon_fail_from_stale_commitment() { nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); commitment_signed_dance!(nodes[1], nodes[0], updates.commitment_signed, false); - let events = nodes[0].node.get_and_clear_pending_events(); + let events = nodes[1].node.get_and_clear_pending_events(); expect_pending_htlcs_forwardable!(nodes[1], events); get_htlc_update_msgs!(nodes[1], nodes[2].node.get_our_node_id()); check_added_monitors!(nodes[1], 1); @@ -75,10 +75,11 @@ fn chanmon_fail_from_stale_commitment() { mine_transaction(&nodes[1], &bs_txn[0]); check_added_monitors!(nodes[1], 1); check_closed_broadcast!(nodes[1], true); + check_closed_event!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1); - let events = nodes[0].node.get_and_clear_pending_events(); + let events = nodes[1].node.get_and_clear_pending_events(); expect_pending_htlcs_forwardable!(nodes[1], events); check_added_monitors!(nodes[1], 1); let fail_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); diff --git a/lightning/src/ln/reorg_tests.rs b/lightning/src/ln/reorg_tests.rs index da43773c9..98b942e9c 100644 --- a/lightning/src/ln/reorg_tests.rs +++ b/lightning/src/ln/reorg_tests.rs @@ -468,9 +468,11 @@ fn do_test_to_remote_after_local_detection(style: ConnectStyle) { assert!(nodes[0].node.list_channels().is_empty()); check_closed_broadcast!(nodes[0], true); check_added_monitors!(nodes[0], 1); + check_closed_event!(nodes[0], 1); assert!(nodes[1].node.list_channels().is_empty()); check_closed_broadcast!(nodes[1], true); check_added_monitors!(nodes[1], 1); + check_closed_event!(nodes[1], 1); // Drop transactions broadcasted in response to the first commitment transaction (we have good // test coverage of these things already elsewhere). diff --git a/lightning/src/ln/shutdown_tests.rs b/lightning/src/ln/shutdown_tests.rs index 26d39fbad..91c608b55 100644 --- a/lightning/src/ln/shutdown_tests.rs +++ b/lightning/src/ln/shutdown_tests.rs @@ -67,6 +67,8 @@ fn pre_funding_lock_shutdown_test() { assert!(nodes[0].node.list_channels().is_empty()); assert!(nodes[1].node.list_channels().is_empty()); + check_closed_event!(nodes[0], 1); + check_closed_event!(nodes[1], 1); } #[test] @@ -139,6 +141,8 @@ fn updates_shutdown_wait() { nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); let (_, node_1_none) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id()); assert!(node_1_none.is_none()); + check_closed_event!(nodes[0], 1); + check_closed_event!(nodes[1], 1); assert!(nodes[0].node.list_channels().is_empty()); @@ -147,6 +151,8 @@ fn updates_shutdown_wait() { close_channel(&nodes[1], &nodes[2], &chan_2.2, chan_2.3, true); assert!(nodes[1].node.list_channels().is_empty()); assert!(nodes[2].node.list_channels().is_empty()); + check_closed_event!(nodes[1], 1); + check_closed_event!(nodes[2], 1); } #[test] @@ -221,6 +227,9 @@ fn htlc_fail_async_shutdown() { close_channel(&nodes[1], &nodes[2], &chan_2.2, chan_2.3, true); assert!(nodes[1].node.list_channels().is_empty()); assert!(nodes[2].node.list_channels().is_empty()); + check_closed_event!(nodes[0], 1); + check_closed_event!(nodes[1], 2); + check_closed_event!(nodes[2], 1); } fn do_test_shutdown_rebroadcast(recv_count: u8) { @@ -359,6 +368,7 @@ fn do_test_shutdown_rebroadcast(recv_count: u8) { nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); let (_, node_1_none) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id()); assert!(node_1_none.is_none()); + check_closed_event!(nodes[1], 1); } else { // If one node, however, received + responded with an identical closing_signed we end // up erroring and node[0] will try to broadcast its own latest commitment transaction. @@ -387,6 +397,7 @@ fn do_test_shutdown_rebroadcast(recv_count: u8) { // closing_signed so we do it ourselves check_closed_broadcast!(nodes[1], false); check_added_monitors!(nodes[1], 1); + check_closed_event!(nodes[1], 1); } assert!(nodes[0].node.list_channels().is_empty()); @@ -396,6 +407,9 @@ fn do_test_shutdown_rebroadcast(recv_count: u8) { close_channel(&nodes[1], &nodes[2], &chan_2.2, chan_2.3, true); assert!(nodes[1].node.list_channels().is_empty()); assert!(nodes[2].node.list_channels().is_empty()); + check_closed_event!(nodes[0], 1); + check_closed_event!(nodes[1], 1); + check_closed_event!(nodes[2], 1); } #[test] @@ -489,6 +503,7 @@ fn test_upfront_shutdown_script() { MessageSendEvent::SendClosingSigned { node_id, .. } => { assert_eq!(node_id, nodes[1].node.get_our_node_id()) } _ => panic!("Unexpected event"), } + check_closed_event!(nodes[2], 1); } #[test] @@ -538,6 +553,7 @@ fn test_unsupported_anysegwit_upfront_shutdown_script() { }, _ => panic!("Unexpected event"), } + check_closed_event!(nodes[0], 1); } #[test] @@ -685,6 +701,7 @@ fn test_unsupported_anysegwit_shutdown_script() { _ => panic!("Unexpected event"), } check_added_monitors!(nodes[0], 1); + check_closed_event!(nodes[0], 1); } #[test] @@ -720,6 +737,7 @@ fn test_invalid_shutdown_script() { _ => panic!("Unexpected event"), } check_added_monitors!(nodes[0], 1); + check_closed_event!(nodes[0], 1); } #[derive(PartialEq)] @@ -785,7 +803,9 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) { let node_0_2nd_closing_signed = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); if timeout_step == TimeoutStep::NoTimeout { nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.1.unwrap()); + check_closed_event!(nodes[1], 1); } + check_closed_event!(nodes[0], 1); } if timeout_step != TimeoutStep::NoTimeout { @@ -808,6 +828,7 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) { txn[0].output[0].script_pubkey.is_v0_p2wsh())); check_closed_broadcast!(nodes[1], true); check_added_monitors!(nodes[1], 1); + check_closed_event!(nodes[1], 1); } else { assert!(txn[0].output[0].script_pubkey.is_v0_p2wpkh()); assert!(txn[0].output[1].script_pubkey.is_v0_p2wpkh()); @@ -867,6 +888,8 @@ fn do_simple_legacy_shutdown_test(high_initiator_fee: bool) { nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed.unwrap()); let (_, node_0_none) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); assert!(node_0_none.is_none()); + check_closed_event!(nodes[0], 1); + check_closed_event!(nodes[1], 1); } #[test] @@ -920,4 +943,6 @@ fn simple_target_feerate_shutdown() { nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed); let (_, node_0_none) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); assert!(node_0_none.is_none()); + check_closed_event!(nodes[0], 1); + check_closed_event!(nodes[1], 1); }