X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Freorg_tests.rs;h=9946cc24a3cb2485597dee37cac9c22d1efa3fa1;hb=2b08a47e887913c8b056192d5b9df4569cf32548;hp=d5a3d042f297846d3d4af516a878b8985f48427d;hpb=9397db6119a63acb7fb0b8f56134b2f854077acc;p=rust-lightning diff --git a/lightning/src/ln/reorg_tests.rs b/lightning/src/ln/reorg_tests.rs index d5a3d042..9946cc24 100644 --- a/lightning/src/ln/reorg_tests.rs +++ b/lightning/src/ln/reorg_tests.rs @@ -10,20 +10,20 @@ //! Further functional tests which test blockchain reorganizations. use chain::channelmonitor::{ANTI_REORG_DELAY, ChannelMonitor}; -use chain::Watch; +use chain::{Confirm, Watch}; 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::*; @@ -56,10 +56,10 @@ fn do_test_onchain_htlc_reorg(local_commitment: bool, claim: bool) { connect_blocks(&nodes[1], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[1].best_block_info().1); connect_blocks(&nodes[2], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[2].best_block_info().1); - let (our_payment_preimage, our_payment_hash) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1000000); + let (our_payment_preimage, our_payment_hash, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1000000); // Provide preimage to node 2 by claiming payment - nodes[2].node.claim_funds(our_payment_preimage, &None, 1000000); + nodes[2].node.claim_funds(our_payment_preimage); check_added_monitors!(nodes[2], 1); get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); @@ -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 }; @@ -301,7 +302,7 @@ fn do_test_unconf_chan(reload_node: bool, reorg_after_reload: bool, use_funding_ // Now check that we can create a new channel create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); - send_payment(&nodes[0], &[&nodes[1]], 8000000, 8_000_000); + send_payment(&nodes[0], &[&nodes[1]], 8000000); } #[test] @@ -358,8 +359,8 @@ fn test_set_outpoints_partial_claiming() { // Connect blocks on node A to advance height towards TEST_FINAL_CLTV // Provide node A with both preimage - nodes[0].node.claim_funds(payment_preimage_1, &None, 3_000_000); - nodes[0].node.claim_funds(payment_preimage_2, &None, 3_000_000); + nodes[0].node.claim_funds(payment_preimage_1); + nodes[0].node.claim_funds(payment_preimage_2); check_added_monitors!(nodes[0], 2); nodes[0].node.get_and_clear_pending_events(); nodes[0].node.get_and_clear_pending_msg_events();