Skip to content

Commit 975984f

Browse files
committed
f add coverage for custom expiry
1 parent 652c45d commit 975984f

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

lightning-invoice/src/utils.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ where
157157
.duration_since(UNIX_EPOCH)
158158
.expect("Time must be > 1970")
159159
.as_secs(),
160-
None,
160+
min_final_cltv_expiry_delta,
161161
)
162162
.map_err(|_| SignOrCreationError::CreationError(CreationError::InvalidAmount))?;
163163
(payment_hash, payment_secret)
@@ -171,7 +171,7 @@ where
171171
.duration_since(UNIX_EPOCH)
172172
.expect("Time must be > 1970")
173173
.as_secs(),
174-
None,
174+
min_final_cltv_expiry_delta,
175175
)
176176
.map_err(|_| SignOrCreationError::CreationError(CreationError::InvalidAmount))?
177177
};
@@ -722,6 +722,22 @@ mod test {
722722
assert_eq!(events.len(), 2);
723723
}
724724

725+
#[test]
726+
fn test_create_invoice_with_custom_min_final_cltv_delta() {
727+
let chanmon_cfgs = create_chanmon_cfgs(2);
728+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
729+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
730+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
731+
let description_hash = crate::Sha256(Hash::hash("Testing description_hash".as_bytes()));
732+
let invoice = crate::utils::create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch(
733+
&nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
734+
Some(10_000), description_hash, Duration::from_secs(1234567), 3600, None,
735+
).unwrap();
736+
assert_eq!(invoice.amount_pico_btc(), Some(100_000));
737+
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
738+
assert_eq!(invoice.description(), InvoiceDescription::Hash(&crate::Sha256(Sha256::hash("Testing description_hash".as_bytes()))));
739+
}
740+
725741
#[test]
726742
fn test_create_invoice_with_description_hash() {
727743
let chanmon_cfgs = create_chanmon_cfgs(2);
@@ -1141,6 +1157,35 @@ mod test {
11411157
assert_eq!(invoice.description(), InvoiceDescription::Hash(&crate::Sha256(Sha256::hash("Description hash phantom invoice".as_bytes()))));
11421158
}
11431159

1160+
#[test]
1161+
#[cfg(feature = "std")]
1162+
fn create_phantom_invoice_with_custom_payment_hash_and_custom_min_final_cltv_delta() {
1163+
let chanmon_cfgs = create_chanmon_cfgs(3);
1164+
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
1165+
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
1166+
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
1167+
1168+
let payment_amt = 20_000;
1169+
let route_hints = vec![
1170+
nodes[1].node.get_phantom_route_hints(),
1171+
nodes[2].node.get_phantom_route_hints(),
1172+
];
1173+
let user_payment_preimage = PaymentPreimage([1; 32]);
1174+
let payment_hash = Some(PaymentHash(Sha256::hash(&user_payment_preimage.0[..]).into_inner()));
1175+
let non_default_invoice_expiry_secs = 4200;
1176+
let min_final_cltv_expiry_delta = Some(100);
1177+
let invoice = crate::utils::create_phantom_invoice::<
1178+
&test_utils::TestKeysInterface, &test_utils::TestLogger,
1179+
>(
1180+
Some(payment_amt), payment_hash, "".into(), non_default_invoice_expiry_secs, route_hints,
1181+
&nodes[1].keys_manager, &nodes[1].logger, Currency::BitcoinTestnet, min_final_cltv_expiry_delta,
1182+
)
1183+
.unwrap();
1184+
assert_eq!(invoice.amount_pico_btc(), Some(200_000));
1185+
assert_eq!(invoice.min_final_cltv_expiry_delta(), min_final_cltv_expiry_delta.unwrap() as u64);
1186+
assert_eq!(invoice.expiry_time(), Duration::from_secs(non_default_invoice_expiry_secs.into()));
1187+
}
1188+
11441189
#[test]
11451190
#[cfg(feature = "std")]
11461191
fn test_multi_node_hints_includes_single_channels_to_participating_nodes() {

0 commit comments

Comments
 (0)