]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Bolt12Invoice::is_for_refund_without_paths tests
authorJeffrey Czyz <jkczyz@gmail.com>
Mon, 22 Jul 2024 21:14:00 +0000 (16:14 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Tue, 30 Jul 2024 21:06:24 +0000 (16:06 -0500)
lightning/src/offers/invoice.rs

index e1f30138212b7c9bbdf12c976a5b8ecf3b5b5307..7d482bc245e992ea2b7c0f9c813757e1151f0030 100644 (file)
@@ -1556,6 +1556,7 @@ mod tests {
                assert_eq!(invoice.payment_hash(), payment_hash);
                assert!(invoice.fallbacks().is_empty());
                assert_eq!(invoice.invoice_features(), &Bolt12InvoiceFeatures::empty());
+               assert!(!invoice.is_for_refund_without_paths());
 
                let message = TaggedHash::from_valid_tlv_stream_bytes(SIGNATURE_TAG, &invoice.bytes);
                assert!(merkle::verify_signature(&invoice.signature, &message, recipient_pubkey()).is_ok());
@@ -1653,6 +1654,7 @@ mod tests {
                assert_eq!(invoice.payment_hash(), payment_hash);
                assert!(invoice.fallbacks().is_empty());
                assert_eq!(invoice.invoice_features(), &Bolt12InvoiceFeatures::empty());
+               assert!(invoice.is_for_refund_without_paths());
 
                let message = TaggedHash::from_valid_tlv_stream_bytes(SIGNATURE_TAG, &invoice.bytes);
                assert!(merkle::verify_signature(&invoice.signature, &message, recipient_pubkey()).is_ok());
@@ -1845,6 +1847,37 @@ mod tests {
                }
        }
 
+       #[test]
+       fn builds_invoice_from_refund_with_path() {
+               let node_id = payer_pubkey();
+               let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
+               let entropy = FixedEntropy {};
+               let secp_ctx = Secp256k1::new();
+
+               let blinded_path = BlindedPath {
+                       introduction_node: IntroductionNode::NodeId(pubkey(40)),
+                       blinding_point: pubkey(41),
+                       blinded_hops: vec![
+                               BlindedHop { blinded_node_id: pubkey(42), encrypted_payload: vec![0; 43] },
+                               BlindedHop { blinded_node_id: node_id, encrypted_payload: vec![0; 44] },
+                       ],
+               };
+
+               let refund = RefundBuilder::new(vec![1; 32], payer_pubkey(), 1000).unwrap()
+                       .path(blinded_path)
+                       .build().unwrap();
+
+               let invoice = refund
+                       .respond_using_derived_keys_no_std(
+                               payment_paths(), payment_hash(), now(), &expanded_key, &entropy
+                       )
+                       .unwrap()
+                       .build_and_sign(&secp_ctx)
+                       .unwrap();
+               assert!(!invoice.message_paths().is_empty());
+               assert!(!invoice.is_for_refund_without_paths());
+       }
+
        #[test]
        fn builds_invoice_with_relative_expiry() {
                let now = now();