Skip to content

Commit 6e89432

Browse files
committed
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.
1 parent 0045086 commit 6e89432

File tree

3 files changed

+70
-9
lines changed

3 files changed

+70
-9
lines changed

lightning/src/offers/invoice.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,7 +1708,9 @@ mod tests {
17081708
ExperimentalOfferTlvStreamRef {
17091709
experimental_foo: None,
17101710
},
1711-
ExperimentalInvoiceRequestTlvStreamRef {},
1711+
ExperimentalInvoiceRequestTlvStreamRef {
1712+
experimental_bar: None,
1713+
},
17121714
),
17131715
);
17141716

@@ -1805,7 +1807,9 @@ mod tests {
18051807
ExperimentalOfferTlvStreamRef {
18061808
experimental_foo: None,
18071809
},
1808-
ExperimentalInvoiceRequestTlvStreamRef {},
1810+
ExperimentalInvoiceRequestTlvStreamRef {
1811+
experimental_bar: None,
1812+
},
18091813
),
18101814
);
18111815

lightning/src/offers/invoice_request.rs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ macro_rules! invoice_request_builder_methods { (
241241
InvoiceRequestContentsWithoutPayerSigningPubkey {
242242
payer: PayerContents(metadata), offer, chain: None, amount_msats: None,
243243
features: InvoiceRequestFeatures::empty(), quantity: None, payer_note: None,
244+
#[cfg(test)]
245+
experimental_bar: None,
244246
}
245247
}
246248

@@ -404,6 +406,12 @@ macro_rules! invoice_request_builder_test_methods { (
404406
$return_value
405407
}
406408

409+
#[cfg_attr(c_bindings, allow(dead_code))]
410+
pub(super) fn experimental_bar($($self_mut)* $self: $self_type, experimental_bar: u64) -> $return_type {
411+
$self.invoice_request.experimental_bar = Some(experimental_bar);
412+
$return_value
413+
}
414+
407415
#[cfg_attr(c_bindings, allow(dead_code))]
408416
pub(super) fn build_unchecked($self: $self_type) -> UnsignedInvoiceRequest {
409417
$self.build_without_checks().0
@@ -663,6 +671,8 @@ pub(super) struct InvoiceRequestContentsWithoutPayerSigningPubkey {
663671
features: InvoiceRequestFeatures,
664672
quantity: Option<u64>,
665673
payer_note: Option<String>,
674+
#[cfg(test)]
675+
experimental_bar: Option<u64>,
666676
}
667677

668678
macro_rules! invoice_request_accessors { ($self: ident, $contents: expr) => {
@@ -966,7 +976,9 @@ impl VerifiedInvoiceRequest {
966976
let InvoiceRequestContents {
967977
payer_signing_pubkey,
968978
inner: InvoiceRequestContentsWithoutPayerSigningPubkey {
969-
payer: _, offer: _, chain: _, amount_msats: _, features: _, quantity, payer_note
979+
payer: _, offer: _, chain: _, amount_msats: _, features: _, quantity, payer_note,
980+
#[cfg(test)]
981+
experimental_bar: _,
970982
},
971983
} = &self.inner.contents;
972984

@@ -1048,7 +1060,10 @@ impl InvoiceRequestContentsWithoutPayerSigningPubkey {
10481060
paths: None,
10491061
};
10501062

1051-
let experimental_invoice_request = ExperimentalInvoiceRequestTlvStreamRef {};
1063+
let experimental_invoice_request = ExperimentalInvoiceRequestTlvStreamRef {
1064+
#[cfg(test)]
1065+
experimental_bar: self.experimental_bar,
1066+
};
10521067

10531068
(payer, offer, invoice_request, experimental_offer, experimental_invoice_request)
10541069
}
@@ -1105,11 +1120,20 @@ tlv_stream!(InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef<'a>, INVOICE_REQ
11051120
pub(super) const EXPERIMENTAL_INVOICE_REQUEST_TYPES: core::ops::Range<u64> =
11061121
2_000_000_000..3_000_000_000;
11071122

1123+
#[cfg(not(test))]
11081124
tlv_stream!(
11091125
ExperimentalInvoiceRequestTlvStream, ExperimentalInvoiceRequestTlvStreamRef,
11101126
EXPERIMENTAL_INVOICE_REQUEST_TYPES, {}
11111127
);
11121128

1129+
#[cfg(test)]
1130+
tlv_stream!(
1131+
ExperimentalInvoiceRequestTlvStream, ExperimentalInvoiceRequestTlvStreamRef,
1132+
EXPERIMENTAL_INVOICE_REQUEST_TYPES, {
1133+
(2_999_999_999, experimental_bar: (u64, HighZeroBytesDroppedBigSize)),
1134+
}
1135+
);
1136+
11131137
type FullInvoiceRequestTlvStream = (
11141138
PayerTlvStream, OfferTlvStream, InvoiceRequestTlvStream, SignatureTlvStream,
11151139
ExperimentalOfferTlvStream, ExperimentalInvoiceRequestTlvStream,
@@ -1217,7 +1241,10 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
12171241
chain, amount, features, quantity, payer_id, payer_note, paths,
12181242
},
12191243
experimental_offer_tlv_stream,
1220-
ExperimentalInvoiceRequestTlvStream {},
1244+
ExperimentalInvoiceRequestTlvStream {
1245+
#[cfg(test)]
1246+
experimental_bar,
1247+
},
12211248
) = tlv_stream;
12221249

12231250
let payer = match metadata {
@@ -1251,6 +1278,8 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
12511278
Ok(InvoiceRequestContents {
12521279
inner: InvoiceRequestContentsWithoutPayerSigningPubkey {
12531280
payer, offer, chain, amount_msats: amount, features, quantity, payer_note,
1281+
#[cfg(test)]
1282+
experimental_bar,
12541283
},
12551284
payer_signing_pubkey,
12561285
})
@@ -1433,7 +1462,9 @@ mod tests {
14331462
ExperimentalOfferTlvStreamRef {
14341463
experimental_foo: None,
14351464
},
1436-
ExperimentalInvoiceRequestTlvStreamRef {},
1465+
ExperimentalInvoiceRequestTlvStreamRef {
1466+
experimental_bar: None,
1467+
},
14371468
),
14381469
);
14391470

@@ -1486,6 +1517,7 @@ mod tests {
14861517
let invoice_request = offer
14871518
.request_invoice_deriving_metadata(signing_pubkey, &expanded_key, nonce, payment_id)
14881519
.unwrap()
1520+
.experimental_bar(42)
14891521
.build().unwrap()
14901522
.sign(payer_sign).unwrap();
14911523
assert_eq!(invoice_request.payer_signing_pubkey(), payer_pubkey());
@@ -1576,6 +1608,7 @@ mod tests {
15761608
let invoice_request = offer
15771609
.request_invoice_deriving_signing_pubkey(&expanded_key, nonce, &secp_ctx, payment_id)
15781610
.unwrap()
1611+
.experimental_bar(42)
15791612
.build_and_sign()
15801613
.unwrap();
15811614

lightning/src/offers/refund.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ macro_rules! refund_explicit_metadata_builder_methods { () => {
178178
quantity: None, payer_signing_pubkey: signing_pubkey, payer_note: None, paths: None,
179179
#[cfg(test)]
180180
experimental_foo: None,
181+
#[cfg(test)]
182+
experimental_bar: None,
181183
},
182184
secp_ctx: None,
183185
})
@@ -222,6 +224,8 @@ macro_rules! refund_builder_methods { (
222224
quantity: None, payer_signing_pubkey: node_id, payer_note: None, paths: None,
223225
#[cfg(test)]
224226
experimental_foo: None,
227+
#[cfg(test)]
228+
experimental_bar: None,
225229
},
226230
secp_ctx: Some(secp_ctx),
227231
})
@@ -368,6 +372,12 @@ macro_rules! refund_builder_test_methods { (
368372
$self.refund.experimental_foo = Some(experimental_foo);
369373
$return_value
370374
}
375+
376+
#[cfg_attr(c_bindings, allow(dead_code))]
377+
pub(super) fn experimental_bar($($self_mut)* $self: $self_type, experimental_bar: u64) -> $return_type {
378+
$self.refund.experimental_bar = Some(experimental_bar);
379+
$return_value
380+
}
371381
} }
372382

373383
impl<'a> RefundBuilder<'a, secp256k1::SignOnly> {
@@ -449,6 +459,8 @@ pub(super) struct RefundContents {
449459
paths: Option<Vec<BlindedMessagePath>>,
450460
#[cfg(test)]
451461
experimental_foo: Option<u64>,
462+
#[cfg(test)]
463+
experimental_bar: Option<u64>,
452464
}
453465

454466
impl Refund {
@@ -787,7 +799,10 @@ impl RefundContents {
787799
experimental_foo: self.experimental_foo,
788800
};
789801

790-
let experimental_invoice_request = ExperimentalInvoiceRequestTlvStreamRef {};
802+
let experimental_invoice_request = ExperimentalInvoiceRequestTlvStreamRef {
803+
#[cfg(test)]
804+
experimental_bar: self.experimental_bar,
805+
};
791806

792807
(payer, offer, invoice_request, experimental_offer, experimental_invoice_request)
793808
}
@@ -879,7 +894,10 @@ impl TryFrom<RefundTlvStream> for RefundContents {
879894
#[cfg(test)]
880895
experimental_foo,
881896
},
882-
ExperimentalInvoiceRequestTlvStream {},
897+
ExperimentalInvoiceRequestTlvStream {
898+
#[cfg(test)]
899+
experimental_bar,
900+
},
883901
) = tlv_stream;
884902

885903
let payer = match payer_metadata {
@@ -942,6 +960,8 @@ impl TryFrom<RefundTlvStream> for RefundContents {
942960
payer_signing_pubkey, payer_note, paths,
943961
#[cfg(test)]
944962
experimental_foo,
963+
#[cfg(test)]
964+
experimental_bar,
945965
})
946966
}
947967
}
@@ -1050,7 +1070,9 @@ mod tests {
10501070
ExperimentalOfferTlvStreamRef {
10511071
experimental_foo: None,
10521072
},
1053-
ExperimentalInvoiceRequestTlvStreamRef {},
1073+
ExperimentalInvoiceRequestTlvStreamRef {
1074+
experimental_bar: None,
1075+
},
10541076
),
10551077
);
10561078

@@ -1080,6 +1102,7 @@ mod tests {
10801102
::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx, 1000, payment_id)
10811103
.unwrap()
10821104
.experimental_foo(42)
1105+
.experimental_bar(42)
10831106
.build().unwrap();
10841107
assert_eq!(refund.payer_signing_pubkey(), node_id);
10851108

@@ -1148,6 +1171,7 @@ mod tests {
11481171
.unwrap()
11491172
.path(blinded_path)
11501173
.experimental_foo(42)
1174+
.experimental_bar(42)
11511175
.build().unwrap();
11521176
assert_ne!(refund.payer_signing_pubkey(), node_id);
11531177

0 commit comments

Comments
 (0)