X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fpayment_tests.rs;h=9e044d1c92d686479d6f76187001ac75c55d92aa;hb=bada71394e96971bcf29fe997ecc9602ec305da4;hp=0cdc2c9153f634953b83b217067002ecc711e306;hpb=56b0c9683864d6860aa117b80470eda64e104854;p=rust-lightning diff --git a/lightning/src/ln/payment_tests.rs b/lightning/src/ln/payment_tests.rs index 0cdc2c91..9e044d1c 100644 --- a/lightning/src/ln/payment_tests.rs +++ b/lightning/src/ln/payment_tests.rs @@ -30,8 +30,6 @@ use crate::util::errors::APIError; use crate::util::ser::Writeable; use crate::util::string::UntrustedString; -use bitcoin::{Block, BlockHeader, TxMerkleNode}; -use bitcoin::hashes::Hash; use bitcoin::network::constants::Network; use crate::prelude::*; @@ -693,8 +691,7 @@ fn do_test_dup_htlc_onchain_fails_on_reload(persist_manager_post_event: bool, co check_added_monitors!(nodes[1], 1); expect_payment_claimed!(nodes[1], payment_hash, 10_000_000); - let mut header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[1].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 }; - connect_block(&nodes[1], &Block { header, txdata: vec![node_txn[1].clone()]}); + connect_block(&nodes[1], &create_dummy_block(nodes[1].best_block_hash(), 42, vec![node_txn[1].clone()])); check_closed_broadcast!(nodes[1], true); check_added_monitors!(nodes[1], 1); check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed); @@ -702,15 +699,13 @@ fn do_test_dup_htlc_onchain_fails_on_reload(persist_manager_post_event: bool, co assert_eq!(claim_txn.len(), 1); check_spends!(claim_txn[0], node_txn[1]); - header.prev_blockhash = nodes[0].best_block_hash(); - connect_block(&nodes[0], &Block { header, txdata: vec![node_txn[1].clone()]}); + connect_block(&nodes[0], &create_dummy_block(nodes[0].best_block_hash(), 42, vec![node_txn[1].clone()])); if confirm_commitment_tx { connect_blocks(&nodes[0], BREAKDOWN_TIMEOUT as u32 - 1); } - header.prev_blockhash = nodes[0].best_block_hash(); - let claim_block = Block { header, txdata: if payment_timeout { timeout_txn } else { vec![claim_txn[0].clone()] } }; + let claim_block = create_dummy_block(nodes[0].best_block_hash(), 42, if payment_timeout { timeout_txn } else { vec![claim_txn[0].clone()] }); if payment_timeout { assert!(confirm_commitment_tx); // Otherwise we're spending below our CSV! @@ -857,14 +852,14 @@ fn get_ldk_payment_preimage() { let (payment_hash, payment_secret) = nodes[1].node.create_inbound_payment(Some(amt_msat), expiry_secs, None).unwrap(); let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV) - .with_features(nodes[1].node.invoice_features()); + .with_bolt11_features(nodes[1].node.invoice_features()).unwrap(); let scorer = test_utils::TestScorer::new(); let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet); let random_seed_bytes = keys_manager.get_secure_random_bytes(); let route = get_route( &nodes[0].node.get_our_node_id(), &payment_params, &nodes[0].network_graph.read_only(), Some(&nodes[0].node.list_usable_channels().iter().collect::>()), - amt_msat, nodes[0].logger, &scorer, &random_seed_bytes).unwrap(); + amt_msat, nodes[0].logger, &scorer, &(), &random_seed_bytes).unwrap(); nodes[0].node.send_payment_with_route(&route, payment_hash, RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_hash.0)).unwrap(); check_added_monitors!(nodes[0], 1); @@ -1409,8 +1404,8 @@ fn do_test_intercepted_payment(test: InterceptTest) { htlc_minimum_msat: None, htlc_maximum_msat: None, }]) - ]) - .with_features(nodes[2].node.invoice_features()); + ]).unwrap() + .with_bolt11_features(nodes[2].node.invoice_features()).unwrap(); let route_params = RouteParameters { payment_params, final_value_msat: amt_msat, @@ -1418,7 +1413,7 @@ fn do_test_intercepted_payment(test: InterceptTest) { let route = get_route( &nodes[0].node.get_our_node_id(), &route_params.payment_params, &nodes[0].network_graph.read_only(), None, route_params.final_value_msat, - nodes[0].logger, &scorer, &random_seed_bytes, + nodes[0].logger, &scorer, &(), &random_seed_bytes, ).unwrap(); let (payment_hash, payment_secret) = nodes[2].node.create_inbound_payment(Some(amt_msat), 60 * 60, None).unwrap(); @@ -1522,10 +1517,7 @@ fn do_test_intercepted_payment(test: InterceptTest) { _ => panic!("Unexpected event") } } else if test == InterceptTest::Timeout { - let mut block = Block { - header: BlockHeader { version: 0x20000000, prev_blockhash: nodes[0].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 }, - txdata: vec![], - }; + let mut block = create_dummy_block(nodes[0].best_block_hash(), 42, Vec::new()); connect_block(&nodes[0], &block); connect_block(&nodes[1], &block); for _ in 0..TEST_FINAL_CLTV { @@ -1600,7 +1592,7 @@ fn do_automatic_retries(test: AutoRetry) { invoice_features.set_basic_mpp_optional(); let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV) .with_expiry_time(payment_expiry_secs as u64) - .with_features(invoice_features); + .with_bolt11_features(invoice_features).unwrap(); let route_params = RouteParameters { payment_params, final_value_msat: amt_msat, @@ -1819,7 +1811,7 @@ fn auto_retry_partial_failure() { invoice_features.set_basic_mpp_optional(); let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV) .with_expiry_time(payment_expiry_secs as u64) - .with_features(invoice_features); + .with_bolt11_features(invoice_features).unwrap(); let route_params = RouteParameters { payment_params, final_value_msat: amt_msat, @@ -2031,7 +2023,7 @@ fn auto_retry_zero_attempts_send_error() { invoice_features.set_basic_mpp_optional(); let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV) .with_expiry_time(payment_expiry_secs as u64) - .with_features(invoice_features); + .with_bolt11_features(invoice_features).unwrap(); let route_params = RouteParameters { payment_params, final_value_msat: amt_msat, @@ -2071,7 +2063,7 @@ fn fails_paying_after_rejected_by_payee() { invoice_features.set_basic_mpp_optional(); let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV) .with_expiry_time(payment_expiry_secs as u64) - .with_features(invoice_features); + .with_bolt11_features(invoice_features).unwrap(); let route_params = RouteParameters { payment_params, final_value_msat: amt_msat, @@ -2118,7 +2110,7 @@ fn retry_multi_path_single_failed_payment() { invoice_features.set_basic_mpp_optional(); let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV) .with_expiry_time(payment_expiry_secs as u64) - .with_features(invoice_features); + .with_bolt11_features(invoice_features).unwrap(); let route_params = RouteParameters { payment_params: payment_params.clone(), final_value_msat: amt_msat, @@ -2212,7 +2204,7 @@ fn immediate_retry_on_failure() { invoice_features.set_basic_mpp_optional(); let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV) .with_expiry_time(payment_expiry_secs as u64) - .with_features(invoice_features); + .with_bolt11_features(invoice_features).unwrap(); let route_params = RouteParameters { payment_params, final_value_msat: amt_msat, @@ -2301,7 +2293,7 @@ fn no_extra_retries_on_back_to_back_fail() { invoice_features.set_basic_mpp_optional(); let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV) .with_expiry_time(payment_expiry_secs as u64) - .with_features(invoice_features); + .with_bolt11_features(invoice_features).unwrap(); let route_params = RouteParameters { payment_params, final_value_msat: amt_msat, @@ -2503,7 +2495,7 @@ fn test_simple_partial_retry() { invoice_features.set_basic_mpp_optional(); let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV) .with_expiry_time(payment_expiry_secs as u64) - .with_features(invoice_features); + .with_bolt11_features(invoice_features).unwrap(); let route_params = RouteParameters { payment_params, final_value_msat: amt_msat, @@ -2669,7 +2661,7 @@ fn test_threaded_payment_retries() { invoice_features.set_basic_mpp_optional(); let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV) .with_expiry_time(payment_expiry_secs as u64) - .with_features(invoice_features); + .with_bolt11_features(invoice_features).unwrap(); let mut route_params = RouteParameters { payment_params, final_value_msat: amt_msat, @@ -2906,7 +2898,7 @@ fn do_claim_from_closed_chan(fail_payment: bool) { let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[3]); let mut route_params = RouteParameters { payment_params: PaymentParameters::from_node_id(nodes[3].node.get_our_node_id(), TEST_FINAL_CLTV) - .with_features(nodes[1].node.invoice_features()), + .with_bolt11_features(nodes[1].node.invoice_features()).unwrap(), final_value_msat: 10_000_000, }; let mut route = nodes[0].router.find_route(&nodes[0].node.get_our_node_id(), &route_params, @@ -3050,7 +3042,7 @@ fn do_test_payment_metadata_consistency(do_reload: bool, do_modify: bool) { let payment_metadata = vec![44, 49, 52, 142]; let payment_params = PaymentParameters::from_node_id(nodes[3].node.get_our_node_id(), TEST_FINAL_CLTV) - .with_features(nodes[1].node.invoice_features()); + .with_bolt11_features(nodes[1].node.invoice_features()).unwrap(); let mut route_params = RouteParameters { payment_params, final_value_msat: amt_msat,