From: Jeffrey Czyz Date: Thu, 8 Aug 2024 21:50:26 +0000 (-0500) Subject: Test verification with experimental invreq TLVs X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=e217c628635669bb2800f1e79bfb9ec3eea37f51;p=rust-lightning Test verification with experimental invreq TLVs 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. --- diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index 2c4e4e5ac..eb2a0cdcc 100644 --- a/lightning/src/offers/invoice.rs +++ b/lightning/src/offers/invoice.rs @@ -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, + }, ), ); diff --git a/lightning/src/offers/invoice_request.rs b/lightning/src/offers/invoice_request.rs index dd0d52358..2a618bae5 100644 --- a/lightning/src/offers/invoice_request.rs +++ b/lightning/src/offers/invoice_request.rs @@ -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, payer_note: Option, + #[cfg(test)] + experimental_bar: Option, } 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 = 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 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 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(); diff --git a/lightning/src/offers/refund.rs b/lightning/src/offers/refund.rs index 2eb54b12e..1d29785c5 100644 --- a/lightning/src/offers/refund.rs +++ b/lightning/src/offers/refund.rs @@ -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>, #[cfg(test)] experimental_foo: Option, + #[cfg(test)] + experimental_bar: Option, } 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 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 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);