Skip to content

Commit 1e51511

Browse files
committed
f - move tests to right commit
1 parent 67744e0 commit 1e51511

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

lightning/src/blinded_path/payment.rs

+9
Original file line numberDiff line numberDiff line change
@@ -638,11 +638,15 @@ impl_writeable_tlv_based!(Bolt12RefundContext, {});
638638

639639
#[cfg(test)]
640640
mod tests {
641+
use bitcoin::hashes::hmac::Hmac;
642+
use bitcoin::hashes::sha256::Hash as Sha256;
643+
use bitcoin::hashes::Hash;
641644
use bitcoin::secp256k1::PublicKey;
642645
use crate::blinded_path::payment::{PaymentForwardNode, ForwardTlvs, ReceiveTlvs, PaymentConstraints, PaymentContext, PaymentRelay};
643646
use crate::types::payment::PaymentSecret;
644647
use crate::types::features::BlindedHopFeatures;
645648
use crate::ln::functional_test_utils::TEST_FINAL_CLTV;
649+
use crate::offers::nonce::Nonce;
646650

647651
#[test]
648652
fn compute_payinfo() {
@@ -691,6 +695,7 @@ mod tests {
691695
htlc_minimum_msat: 1,
692696
},
693697
payment_context: PaymentContext::unknown(),
698+
authentication: (Hmac::<Sha256>::hash(&[42u8]), Nonce([42u8; 16])),
694699
};
695700
let htlc_maximum_msat = 100_000;
696701
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat, 12).unwrap();
@@ -710,6 +715,7 @@ mod tests {
710715
htlc_minimum_msat: 1,
711716
},
712717
payment_context: PaymentContext::unknown(),
718+
authentication: (Hmac::<Sha256>::hash(&[42u8]), Nonce([42u8; 16])),
713719
};
714720
let blinded_payinfo = super::compute_payinfo(&[], &recv_tlvs, 4242, TEST_FINAL_CLTV as u16).unwrap();
715721
assert_eq!(blinded_payinfo.fee_base_msat, 0);
@@ -766,6 +772,7 @@ mod tests {
766772
htlc_minimum_msat: 3,
767773
},
768774
payment_context: PaymentContext::unknown(),
775+
authentication: (Hmac::<Sha256>::hash(&[42u8]), Nonce([42u8; 16])),
769776
};
770777
let htlc_maximum_msat = 100_000;
771778
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat, TEST_FINAL_CLTV as u16).unwrap();
@@ -819,6 +826,7 @@ mod tests {
819826
htlc_minimum_msat: 1,
820827
},
821828
payment_context: PaymentContext::unknown(),
829+
authentication: (Hmac::<Sha256>::hash(&[42u8]), Nonce([42u8; 16])),
822830
};
823831
let htlc_minimum_msat = 3798;
824832
assert!(super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_minimum_msat - 1, TEST_FINAL_CLTV as u16).is_err());
@@ -876,6 +884,7 @@ mod tests {
876884
htlc_minimum_msat: 1,
877885
},
878886
payment_context: PaymentContext::unknown(),
887+
authentication: (Hmac::<Sha256>::hash(&[42u8]), Nonce([42u8; 16])),
879888
};
880889

881890
let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, 10_000, TEST_FINAL_CLTV as u16).unwrap();

lightning/src/ln/blinded_payment_tests.rs

+29-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
// You may not use this file except in accordance with one or both of these
88
// licenses.
99

10+
use bitcoin::hashes::hmac::Hmac;
1011
use bitcoin::hashes::hex::FromHex;
12+
use bitcoin::hashes::sha256::Hash as Sha256;
1113
use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey, schnorr};
1214
use bitcoin::secp256k1::ecdh::SharedSecret;
1315
use bitcoin::secp256k1::ecdsa::{RecoverableSignature, Signature};
@@ -17,16 +19,18 @@ use crate::events::{Event, HTLCDestination, MessageSendEvent, MessageSendEventsP
1719
use crate::ln::types::ChannelId;
1820
use crate::types::payment::{PaymentHash, PaymentSecret};
1921
use crate::ln::channelmanager;
20-
use crate::ln::channelmanager::{HTLCFailureMsg, PaymentId, RecipientOnionFields};
22+
use crate::ln::channelmanager::{HTLCFailureMsg, PaymentId, RecipientOnionFields, Verification};
2123
use crate::types::features::{BlindedHopFeatures, ChannelFeatures, NodeFeatures};
2224
use crate::ln::functional_test_utils::*;
25+
use crate::ln::inbound_payment::ExpandedKey;
2326
use crate::ln::msgs;
2427
use crate::ln::msgs::{ChannelMessageHandler, UnsignedGossipMessage};
2528
use crate::ln::onion_payment;
2629
use crate::ln::onion_utils;
2730
use crate::ln::onion_utils::INVALID_ONION_BLINDING;
2831
use crate::ln::outbound_payment::{Retry, IDEMPOTENCY_TIMEOUT_TICKS};
2932
use crate::offers::invoice::UnsignedBolt12Invoice;
33+
use crate::offers::nonce::Nonce;
3034
use crate::prelude::*;
3135
use crate::routing::router::{BlindedTail, Path, Payee, PaymentParameters, RouteHop, RouteParameters};
3236
use crate::sign::{KeyMaterial, NodeSigner, Recipient};
@@ -69,15 +73,19 @@ fn blinded_payment_path(
6973
.unwrap_or_else(|| channel_upds[idx - 1].htlc_maximum_msat),
7074
});
7175
}
76+
77+
let payment_context = PaymentContext::unknown();
7278
let payee_tlvs = ReceiveTlvs {
7379
payment_secret,
7480
payment_constraints: PaymentConstraints {
7581
max_cltv_expiry: u32::max_value(),
7682
htlc_minimum_msat:
7783
intro_node_min_htlc_opt.unwrap_or_else(|| channel_upds.last().unwrap().htlc_minimum_msat),
7884
},
79-
payment_context: PaymentContext::unknown(),
85+
authentication: hmac_payment_context(&payment_context, keys_manager),
86+
payment_context,
8087
};
88+
8189
let mut secp_ctx = Secp256k1::new();
8290
BlindedPaymentPath::new(
8391
&intermediate_nodes[..], *node_ids.last().unwrap(), payee_tlvs,
@@ -86,6 +94,15 @@ fn blinded_payment_path(
8694
).unwrap()
8795
}
8896

97+
fn hmac_payment_context(
98+
payment_context: &PaymentContext, keys_manager: &test_utils::TestKeysInterface,
99+
) -> (Hmac<Sha256>, Nonce) {
100+
let nonce = Nonce([42u8; 16]);
101+
let expanded_key = ExpandedKey::new(&keys_manager.get_inbound_payment_key_material());
102+
let hmac = payment_context.hmac_for_offer_payment(nonce, &expanded_key);
103+
(hmac, nonce)
104+
}
105+
89106
pub fn get_blinded_route_parameters(
90107
amt_msat: u64, payment_secret: PaymentSecret, intro_node_min_htlc: u64, intro_node_max_htlc: u64,
91108
node_ids: Vec<PublicKey>, channel_upds: &[&msgs::UnsignedChannelUpdate],
@@ -116,13 +133,15 @@ fn do_one_hop_blinded_path(success: bool) {
116133

117134
let amt_msat = 5000;
118135
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[1], Some(amt_msat), None);
136+
let payment_context = PaymentContext::unknown();
119137
let payee_tlvs = ReceiveTlvs {
120138
payment_secret,
121139
payment_constraints: PaymentConstraints {
122140
max_cltv_expiry: u32::max_value(),
123141
htlc_minimum_msat: chan_upd.htlc_minimum_msat,
124142
},
125-
payment_context: PaymentContext::unknown(),
143+
authentication: hmac_payment_context(&payment_context, &chanmon_cfgs[1].keys_manager),
144+
payment_context,
126145
};
127146
let mut secp_ctx = Secp256k1::new();
128147
let blinded_path = BlindedPaymentPath::new(
@@ -160,13 +179,15 @@ fn mpp_to_one_hop_blinded_path() {
160179

161180
let amt_msat = 15_000_000;
162181
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[3], Some(amt_msat), None);
182+
let payment_context = PaymentContext::unknown();
163183
let payee_tlvs = ReceiveTlvs {
164184
payment_secret,
165185
payment_constraints: PaymentConstraints {
166186
max_cltv_expiry: u32::max_value(),
167187
htlc_minimum_msat: chan_upd_1_3.htlc_minimum_msat,
168188
},
169-
payment_context: PaymentContext::unknown(),
189+
authentication: hmac_payment_context(&payment_context, &chanmon_cfgs[3].keys_manager),
190+
payment_context,
170191
};
171192
let blinded_path = BlindedPaymentPath::new(
172193
&[], nodes[3].node.get_our_node_id(), payee_tlvs, u64::MAX, TEST_FINAL_CLTV as u16,
@@ -302,7 +323,7 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
302323
let mut route_params = get_blinded_route_parameters(amt_msat, payment_secret, 1, 1_0000_0000,
303324
nodes.iter().skip(1).map(|n| n.node.get_our_node_id()).collect(),
304325
&[&chan_upd_1_2, &chan_upd_2_3], &chanmon_cfgs[3].keys_manager);
305-
route_params.payment_params.max_path_length = 18;
326+
route_params.payment_params.max_path_length = 17;
306327

307328
let route = get_route(&nodes[0], &route_params).unwrap();
308329
node_cfgs[0].router.expect_find_route(route_params.clone(), Ok(route.clone()));
@@ -1375,13 +1396,15 @@ fn custom_tlvs_to_blinded_path() {
13751396

13761397
let amt_msat = 5000;
13771398
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[1], Some(amt_msat), None);
1399+
let payment_context = PaymentContext::unknown();
13781400
let payee_tlvs = ReceiveTlvs {
13791401
payment_secret,
13801402
payment_constraints: PaymentConstraints {
13811403
max_cltv_expiry: u32::max_value(),
13821404
htlc_minimum_msat: chan_upd.htlc_minimum_msat,
13831405
},
1384-
payment_context: PaymentContext::unknown(),
1406+
authentication: hmac_payment_context(&payment_context, &chanmon_cfgs[1].keys_manager),
1407+
payment_context,
13851408
};
13861409
let mut secp_ctx = Secp256k1::new();
13871410
let blinded_path = BlindedPaymentPath::new(

lightning/src/ln/max_payment_path_len_tests.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@ use crate::blinded_path::payment::{BlindedPayInfo, BlindedPaymentPath, PaymentCo
1616
use crate::events::{Event, MessageSendEventsProvider};
1717
use crate::types::payment::PaymentSecret;
1818
use crate::ln::blinded_payment_tests::get_blinded_route_parameters;
19-
use crate::ln::channelmanager::PaymentId;
19+
use crate::ln::channelmanager::{PaymentId, Verification};
2020
use crate::types::features::BlindedHopFeatures;
2121
use crate::ln::functional_test_utils::*;
22+
use crate::ln::inbound_payment::ExpandedKey;
2223
use crate::ln::msgs;
2324
use crate::ln::msgs::OnionMessageHandler;
2425
use crate::ln::onion_utils;
2526
use crate::ln::onion_utils::MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY;
2627
use crate::ln::outbound_payment::{RecipientOnionFields, Retry, RetryableSendFailure};
28+
use crate::offers::nonce::Nonce;
2729
use crate::prelude::*;
2830
use crate::routing::router::{DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA, PaymentParameters, RouteParameters};
31+
use crate::sign::NodeSigner;
2932
use crate::util::errors::APIError;
3033
use crate::util::ser::Writeable;
3134
use crate::util::test_utils;
@@ -157,13 +160,18 @@ fn one_hop_blinded_path_with_custom_tlv() {
157160
// Construct the route parameters for sending to nodes[2]'s 1-hop blinded path.
158161
let amt_msat = 100_000;
159162
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], Some(amt_msat), None);
163+
let payment_context = PaymentContext::unknown();
164+
let nonce = Nonce([42u8; 16]);
165+
let expanded_key = ExpandedKey::new(&chanmon_cfgs[2].keys_manager.get_inbound_payment_key_material());
166+
let hmac = payment_context.hmac_for_offer_payment(nonce, &expanded_key);
160167
let payee_tlvs = ReceiveTlvs {
161168
payment_secret,
162169
payment_constraints: PaymentConstraints {
163170
max_cltv_expiry: u32::max_value(),
164171
htlc_minimum_msat: chan_upd_1_2.htlc_minimum_msat,
165172
},
166-
payment_context: PaymentContext::unknown(),
173+
payment_context,
174+
authentication: (hmac, nonce),
167175
};
168176
let mut secp_ctx = Secp256k1::new();
169177
let blinded_path = BlindedPaymentPath::new(

0 commit comments

Comments
 (0)