X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fonion_route_tests.rs;h=4feae104d759a11fb47ee0b21b1f8f4be20b2311;hb=d734ad814e14097f1b1a053e8d63b3a84b1c9435;hp=f3681946d194f614583c64488bb809103fccc9ec;hpb=59659d3171141a4aab65d24462786578aa1aeaf1;p=rust-lightning diff --git a/lightning/src/ln/onion_route_tests.rs b/lightning/src/ln/onion_route_tests.rs index f3681946..4feae104 100644 --- a/lightning/src/ln/onion_route_tests.rs +++ b/lightning/src/ln/onion_route_tests.rs @@ -12,7 +12,7 @@ //! returned errors decode to the correct thing. use chain::channelmonitor::{CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS}; -use ln::{PaymentPreimage, PaymentHash, PaymentSecret}; +use ln::{PaymentHash, PaymentSecret}; use ln::channelmanager::{HTLCForwardInfo, CLTV_FAR_FAR_AWAY}; use ln::onion_utils; use routing::network_graph::NetworkUpdate; @@ -26,7 +26,6 @@ use util::config::UserConfig; use bitcoin::hash_types::BlockHash; -use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::hashes::Hash; use bitcoin::secp256k1; @@ -477,6 +476,11 @@ fn test_onion_failure() { bogus_route.paths[0][route_len-1].fee_msat = amt_to_forward; run_onion_failure_test("amount_below_minimum", 0, &nodes, &bogus_route, &payment_hash, &payment_secret, |_| {}, ||{}, true, Some(UPDATE|11), Some(NetworkUpdate::ChannelUpdateMessage{msg: ChannelUpdate::dummy(short_channel_id)}), Some(short_channel_id)); + // Clear pending payments so that the following positive test has the correct payment hash. + for node in nodes.iter() { + node.node.clear_pending_payments(); + } + // Test a positive test-case with one extra msat, meeting the minimum. bogus_route.paths[0][route_len-1].fee_msat = amt_to_forward + 1; let preimage = send_along_route(&nodes[0], bogus_route, &[&nodes[1], &nodes[2]], amt_to_forward+1).0; @@ -559,4 +563,13 @@ fn test_onion_failure() { msg.cltv_expiry = htlc_cltv; msg.onion_routing_packet = onion_packet; }, ||{}, true, Some(21), Some(NetworkUpdate::NodeFailure{node_id: route.paths[0][0].pubkey, is_permanent: true}), Some(route.paths[0][0].short_channel_id)); + + run_onion_failure_test_with_fail_intercept("mpp_timeout", 200, &nodes, &route, &payment_hash, &payment_secret, |_msg| {}, |msg| { + // Tamper returning error message + let session_priv = SecretKey::from_slice(&[3; 32]).unwrap(); + let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap(); + msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[1].shared_secret[..], 23, &[0;0]); + }, ||{ + nodes[2].node.fail_htlc_backwards(&payment_hash); + }, true, Some(23), None, None); }