]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Test verification with experimental invreq TLVs
authorJeffrey Czyz <jkczyz@gmail.com>
Thu, 8 Aug 2024 21:50:26 +0000 (16:50 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Tue, 5 Nov 2024 00:00:23 +0000 (18:00 -0600)
Payer metadata is generated from the invreq TLVs and should included
those in the experimental range. When verifying invoice messages, these
TLVs must be included. Modify the BOLT12 verification tests to cover
them.

lightning/src/offers/invoice.rs
lightning/src/offers/invoice_request.rs
lightning/src/offers/refund.rs

index 2c4e4e5ac12b228c472151ba10b5f34f4dcf05df..eb2a0cdccea76210efbda4eac9718369564ad62e 100644 (file)
@@ -1738,7 +1738,9 @@ mod tests {
                                ExperimentalOfferTlvStreamRef {
                                        experimental_foo: None,
                                },
-                               ExperimentalInvoiceRequestTlvStreamRef {},
+                               ExperimentalInvoiceRequestTlvStreamRef {
+                                       experimental_bar: None,
+                               },
                        ),
                );
 
@@ -1835,7 +1837,9 @@ mod tests {
                                ExperimentalOfferTlvStreamRef {
                                        experimental_foo: None,
                                },
-                               ExperimentalInvoiceRequestTlvStreamRef {},
+                               ExperimentalInvoiceRequestTlvStreamRef {
+                                       experimental_bar: None,
+                               },
                        ),
                );
 
index dd0d523588c4ff5c62c420137d461cba0e669455..2a618bae5f8612ae3d91f242701fbbd67a7eeed2 100644 (file)
@@ -241,6 +241,8 @@ macro_rules! invoice_request_builder_methods { (
                InvoiceRequestContentsWithoutPayerSigningPubkey {
                        payer: PayerContents(metadata), offer, chain: None, amount_msats: None,
                        features: InvoiceRequestFeatures::empty(), quantity: None, payer_note: None,
+                       #[cfg(test)]
+                       experimental_bar: None,
                }
        }
 
@@ -404,6 +406,12 @@ macro_rules! invoice_request_builder_test_methods { (
                $return_value
        }
 
+       #[cfg_attr(c_bindings, allow(dead_code))]
+       pub(super) fn experimental_bar($($self_mut)* $self: $self_type, experimental_bar: u64) -> $return_type {
+               $self.invoice_request.experimental_bar = Some(experimental_bar);
+               $return_value
+       }
+
        #[cfg_attr(c_bindings, allow(dead_code))]
        pub(super) fn build_unchecked($self: $self_type) -> UnsignedInvoiceRequest {
                $self.build_without_checks().0
@@ -691,6 +699,8 @@ pub(super) struct InvoiceRequestContentsWithoutPayerSigningPubkey {
        features: InvoiceRequestFeatures,
        quantity: Option<u64>,
        payer_note: Option<String>,
+       #[cfg(test)]
+       experimental_bar: Option<u64>,
 }
 
 macro_rules! invoice_request_accessors { ($self: ident, $contents: expr) => {
@@ -994,7 +1004,9 @@ impl VerifiedInvoiceRequest {
                let InvoiceRequestContents {
                        payer_signing_pubkey,
                        inner: InvoiceRequestContentsWithoutPayerSigningPubkey {
-                               payer: _, offer: _, chain: _, amount_msats: _, features: _, quantity, payer_note
+                               payer: _, offer: _, chain: _, amount_msats: _, features: _, quantity, payer_note,
+                               #[cfg(test)]
+                               experimental_bar: _,
                        },
                } = &self.inner.contents;
 
@@ -1076,7 +1088,10 @@ impl InvoiceRequestContentsWithoutPayerSigningPubkey {
                        paths: None,
                };
 
-               let experimental_invoice_request = ExperimentalInvoiceRequestTlvStreamRef {};
+               let experimental_invoice_request = ExperimentalInvoiceRequestTlvStreamRef {
+                       #[cfg(test)]
+                       experimental_bar: self.experimental_bar,
+               };
 
                (payer, offer, invoice_request, experimental_offer, experimental_invoice_request)
        }
@@ -1133,11 +1148,20 @@ tlv_stream!(InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef<'a>, INVOICE_REQ
 pub(super) const EXPERIMENTAL_INVOICE_REQUEST_TYPES: core::ops::Range<u64> =
        2_000_000_000..3_000_000_000;
 
+#[cfg(not(test))]
 tlv_stream!(
        ExperimentalInvoiceRequestTlvStream, ExperimentalInvoiceRequestTlvStreamRef,
        EXPERIMENTAL_INVOICE_REQUEST_TYPES, {}
 );
 
+#[cfg(test)]
+tlv_stream!(
+       ExperimentalInvoiceRequestTlvStream, ExperimentalInvoiceRequestTlvStreamRef,
+       EXPERIMENTAL_INVOICE_REQUEST_TYPES, {
+               (2_999_999_999, experimental_bar: (u64, HighZeroBytesDroppedBigSize)),
+       }
+);
+
 type FullInvoiceRequestTlvStream = (
        PayerTlvStream, OfferTlvStream, InvoiceRequestTlvStream, SignatureTlvStream,
        ExperimentalOfferTlvStream, ExperimentalInvoiceRequestTlvStream,
@@ -1244,7 +1268,10 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
                                chain, amount, features, quantity, payer_id, payer_note, paths,
                        },
                        experimental_offer_tlv_stream,
-                       ExperimentalInvoiceRequestTlvStream {},
+                       ExperimentalInvoiceRequestTlvStream {
+                               #[cfg(test)]
+                               experimental_bar,
+                       },
                ) = tlv_stream;
 
                let payer = match metadata {
@@ -1278,6 +1305,8 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
                Ok(InvoiceRequestContents {
                        inner: InvoiceRequestContentsWithoutPayerSigningPubkey {
                                payer, offer, chain, amount_msats: amount, features, quantity, payer_note,
+                               #[cfg(test)]
+                               experimental_bar,
                        },
                        payer_signing_pubkey,
                })
@@ -1460,7 +1489,9 @@ mod tests {
                                ExperimentalOfferTlvStreamRef {
                                        experimental_foo: None,
                                },
-                               ExperimentalInvoiceRequestTlvStreamRef {},
+                               ExperimentalInvoiceRequestTlvStreamRef {
+                                       experimental_bar: None,
+                               },
                        ),
                );
 
@@ -1513,6 +1544,7 @@ mod tests {
                let invoice_request = offer
                        .request_invoice_deriving_metadata(signing_pubkey, &expanded_key, nonce, payment_id)
                        .unwrap()
+                       .experimental_bar(42)
                        .build().unwrap()
                        .sign(payer_sign).unwrap();
                assert_eq!(invoice_request.payer_signing_pubkey(), payer_pubkey());
@@ -1603,6 +1635,7 @@ mod tests {
                let invoice_request = offer
                        .request_invoice_deriving_signing_pubkey(&expanded_key, nonce, &secp_ctx, payment_id)
                        .unwrap()
+                       .experimental_bar(42)
                        .build_and_sign()
                        .unwrap();
 
index 2eb54b12e10b816080b30c21a1ca58dce021c134..1d29785c5339f56866c8700f0037f73933db9e87 100644 (file)
@@ -178,6 +178,8 @@ macro_rules! refund_explicit_metadata_builder_methods { () => {
                                quantity: None, payer_signing_pubkey: signing_pubkey, payer_note: None, paths: None,
                                #[cfg(test)]
                                experimental_foo: None,
+                               #[cfg(test)]
+                               experimental_bar: None,
                        },
                        secp_ctx: None,
                })
@@ -222,6 +224,8 @@ macro_rules! refund_builder_methods { (
                                quantity: None, payer_signing_pubkey: node_id, payer_note: None, paths: None,
                                #[cfg(test)]
                                experimental_foo: None,
+                               #[cfg(test)]
+                               experimental_bar: None,
                        },
                        secp_ctx: Some(secp_ctx),
                })
@@ -368,6 +372,12 @@ macro_rules! refund_builder_test_methods { (
                $self.refund.experimental_foo = Some(experimental_foo);
                $return_value
        }
+
+       #[cfg_attr(c_bindings, allow(dead_code))]
+       pub(super) fn experimental_bar($($self_mut)* $self: $self_type, experimental_bar: u64) -> $return_type {
+               $self.refund.experimental_bar = Some(experimental_bar);
+               $return_value
+       }
 } }
 
 impl<'a> RefundBuilder<'a, secp256k1::SignOnly> {
@@ -449,6 +459,8 @@ pub(super) struct RefundContents {
        paths: Option<Vec<BlindedMessagePath>>,
        #[cfg(test)]
        experimental_foo: Option<u64>,
+       #[cfg(test)]
+       experimental_bar: Option<u64>,
 }
 
 impl Refund {
@@ -787,7 +799,10 @@ impl RefundContents {
                        experimental_foo: self.experimental_foo,
                };
 
-               let experimental_invoice_request = ExperimentalInvoiceRequestTlvStreamRef {};
+               let experimental_invoice_request = ExperimentalInvoiceRequestTlvStreamRef {
+                       #[cfg(test)]
+                       experimental_bar: self.experimental_bar,
+               };
 
                (payer, offer, invoice_request, experimental_offer, experimental_invoice_request)
        }
@@ -879,7 +894,10 @@ impl TryFrom<RefundTlvStream> for RefundContents {
                                #[cfg(test)]
                                experimental_foo,
                        },
-                       ExperimentalInvoiceRequestTlvStream {},
+                       ExperimentalInvoiceRequestTlvStream {
+                               #[cfg(test)]
+                               experimental_bar,
+                       },
                ) = tlv_stream;
 
                let payer = match payer_metadata {
@@ -942,6 +960,8 @@ impl TryFrom<RefundTlvStream> for RefundContents {
                        payer_signing_pubkey, payer_note, paths,
                        #[cfg(test)]
                        experimental_foo,
+                       #[cfg(test)]
+                       experimental_bar,
                })
        }
 }
@@ -1050,7 +1070,9 @@ mod tests {
                                ExperimentalOfferTlvStreamRef {
                                        experimental_foo: None,
                                },
-                               ExperimentalInvoiceRequestTlvStreamRef {},
+                               ExperimentalInvoiceRequestTlvStreamRef {
+                                       experimental_bar: None,
+                               },
                        ),
                );
 
@@ -1080,6 +1102,7 @@ mod tests {
                        ::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx, 1000, payment_id)
                        .unwrap()
                        .experimental_foo(42)
+                       .experimental_bar(42)
                        .build().unwrap();
                assert_eq!(refund.payer_signing_pubkey(), node_id);
 
@@ -1148,6 +1171,7 @@ mod tests {
                        .unwrap()
                        .path(blinded_path)
                        .experimental_foo(42)
+                       .experimental_bar(42)
                        .build().unwrap();
                assert_ne!(refund.payer_signing_pubkey(), node_id);