X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Freorg_tests.rs;h=4e13478db39a6f144d548a02b010e73a1159b79c;hb=2024c5e1049ef399fb24e5c466924f980e949c69;hp=e5feeb25e4266f29975ec7e8f8020e923b4da52c;hpb=a8bc8fb3494def71db645cefac89abc133b95b99;p=rust-lightning diff --git a/lightning/src/ln/reorg_tests.rs b/lightning/src/ln/reorg_tests.rs index e5feeb25..4e13478d 100644 --- a/lightning/src/ln/reorg_tests.rs +++ b/lightning/src/ln/reorg_tests.rs @@ -15,15 +15,15 @@ use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs}; use ln::features::InitFeatures; use ln::msgs::{ChannelMessageHandler, ErrorAction, HTLCFailChannelUpdate}; use util::enforcing_trait_impls::EnforcingSigner; -use util::events::{Event, EventsProvider, MessageSendEvent, MessageSendEventsProvider}; +use util::events::{Event, MessageSendEvent, MessageSendEventsProvider}; use util::test_utils; use util::ser::{ReadableArgs, Writeable}; use bitcoin::blockdata::block::{Block, BlockHeader}; use bitcoin::hash_types::BlockHash; -use std::collections::HashMap; -use std::mem; +use prelude::*; +use core::mem; use ln::functional_test_utils::*; @@ -101,16 +101,17 @@ fn do_test_onchain_htlc_reorg(local_commitment: bool, claim: bool) { // Give node 1 node 2's commitment transaction and get its response (timing the HTLC out) mine_transaction(&nodes[1], &node_2_commitment_txn[0]); - let node_1_commitment_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap(); - assert_eq!(node_1_commitment_txn.len(), 3); // ChannelMonitor: 1 offered HTLC-Timeout, ChannelManger: 1 local commitment tx, 1 Offered HTLC-Timeout - assert_eq!(node_1_commitment_txn[1].output.len(), 2); // to-local and Offered HTLC (to-remote is dust) - check_spends!(node_1_commitment_txn[1], chan_2.3); - check_spends!(node_1_commitment_txn[2], node_1_commitment_txn[1]); - check_spends!(node_1_commitment_txn[0], node_2_commitment_txn[0]); + connect_blocks(&nodes[1], TEST_FINAL_CLTV - 1); // Confirm blocks until the HTLC expires + let node_1_commitment_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clone(); + assert_eq!(node_1_commitment_txn.len(), 2); // ChannelMonitor: 1 offered HTLC-Timeout, ChannelManger: 1 local commitment tx + assert_eq!(node_1_commitment_txn[0].output.len(), 2); // to-local and Offered HTLC (to-remote is dust) + check_spends!(node_1_commitment_txn[0], chan_2.3); + check_spends!(node_1_commitment_txn[1], node_2_commitment_txn[0]); // Confirm node 2's commitment txn (and node 1's HTLC-Timeout) on node 1 header.prev_blockhash = nodes[1].best_block_hash(); - connect_block(&nodes[1], &Block { header, txdata: vec![node_2_commitment_txn[0].clone(), node_1_commitment_txn[0].clone()] }); + let block = Block { header, txdata: vec![node_2_commitment_txn[0].clone(), node_1_commitment_txn[1].clone()] }; + connect_block(&nodes[1], &block); // ...but return node 2's commitment tx (and claim) in case claim is set and we're preparing to reorg node_2_commitment_txn }; @@ -131,8 +132,9 @@ fn do_test_onchain_htlc_reorg(local_commitment: bool, claim: bool) { connect_block(&nodes[1], &block); // ChannelManager only polls chain::Watch::release_pending_monitor_events when we - // probe it for events, so we probe non-message events here (which should still end up empty): - assert_eq!(nodes[1].node.get_and_clear_pending_events().len(), 0); + // probe it for events, so we probe non-message events here (which should just be the + // PaymentForwarded event). + expect_payment_forwarded!(nodes[1], Some(1000), true); } else { // Confirm the timeout tx and check that we fail the HTLC backwards let block = Block {