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.
This commit is contained in:
Jeffrey Czyz 2024-08-08 16:50:26 -05:00
parent 5590bc2fa8
commit e217c62863
No known key found for this signature in database
GPG key ID: 912EF12EA67705F5
3 changed files with 70 additions and 9 deletions

View 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,
},
),
);

View 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();

View 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);