Skip to content

Commit 353b45f

Browse files
committed
Bolt12Invoice::is_for_refund_without_paths tests
1 parent 50d21b7 commit 353b45f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

lightning/src/offers/invoice.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,7 @@ mod tests {
15561556
assert_eq!(invoice.payment_hash(), payment_hash);
15571557
assert!(invoice.fallbacks().is_empty());
15581558
assert_eq!(invoice.invoice_features(), &Bolt12InvoiceFeatures::empty());
1559+
assert!(!invoice.is_for_refund_without_paths());
15591560

15601561
let message = TaggedHash::from_valid_tlv_stream_bytes(SIGNATURE_TAG, &invoice.bytes);
15611562
assert!(merkle::verify_signature(&invoice.signature, &message, recipient_pubkey()).is_ok());
@@ -1653,6 +1654,7 @@ mod tests {
16531654
assert_eq!(invoice.payment_hash(), payment_hash);
16541655
assert!(invoice.fallbacks().is_empty());
16551656
assert_eq!(invoice.invoice_features(), &Bolt12InvoiceFeatures::empty());
1657+
assert!(invoice.is_for_refund_without_paths());
16561658

16571659
let message = TaggedHash::from_valid_tlv_stream_bytes(SIGNATURE_TAG, &invoice.bytes);
16581660
assert!(merkle::verify_signature(&invoice.signature, &message, recipient_pubkey()).is_ok());
@@ -1845,6 +1847,37 @@ mod tests {
18451847
}
18461848
}
18471849

1850+
#[test]
1851+
fn builds_invoice_from_refund_with_path() {
1852+
let node_id = payer_pubkey();
1853+
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
1854+
let entropy = FixedEntropy {};
1855+
let secp_ctx = Secp256k1::new();
1856+
1857+
let blinded_path = BlindedPath {
1858+
introduction_node: IntroductionNode::NodeId(pubkey(40)),
1859+
blinding_point: pubkey(41),
1860+
blinded_hops: vec![
1861+
BlindedHop { blinded_node_id: pubkey(42), encrypted_payload: vec![0; 43] },
1862+
BlindedHop { blinded_node_id: node_id, encrypted_payload: vec![0; 44] },
1863+
],
1864+
};
1865+
1866+
let refund = RefundBuilder::new(vec![1; 32], payer_pubkey(), 1000).unwrap()
1867+
.path(blinded_path)
1868+
.build().unwrap();
1869+
1870+
let invoice = refund
1871+
.respond_using_derived_keys_no_std(
1872+
payment_paths(), payment_hash(), now(), &expanded_key, &entropy
1873+
)
1874+
.unwrap()
1875+
.build_and_sign(&secp_ctx)
1876+
.unwrap();
1877+
assert!(!invoice.message_paths().is_empty());
1878+
assert!(!invoice.is_for_refund_without_paths());
1879+
}
1880+
18481881
#[test]
18491882
fn builds_invoice_with_relative_expiry() {
18501883
let now = now();

0 commit comments

Comments
 (0)