mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 23:08:36 +01:00
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:
parent
5590bc2fa8
commit
e217c62863
3 changed files with 70 additions and 9 deletions
|
@ -1738,7 +1738,9 @@ mod tests {
|
||||||
ExperimentalOfferTlvStreamRef {
|
ExperimentalOfferTlvStreamRef {
|
||||||
experimental_foo: None,
|
experimental_foo: None,
|
||||||
},
|
},
|
||||||
ExperimentalInvoiceRequestTlvStreamRef {},
|
ExperimentalInvoiceRequestTlvStreamRef {
|
||||||
|
experimental_bar: None,
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1835,7 +1837,9 @@ mod tests {
|
||||||
ExperimentalOfferTlvStreamRef {
|
ExperimentalOfferTlvStreamRef {
|
||||||
experimental_foo: None,
|
experimental_foo: None,
|
||||||
},
|
},
|
||||||
ExperimentalInvoiceRequestTlvStreamRef {},
|
ExperimentalInvoiceRequestTlvStreamRef {
|
||||||
|
experimental_bar: None,
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -241,6 +241,8 @@ macro_rules! invoice_request_builder_methods { (
|
||||||
InvoiceRequestContentsWithoutPayerSigningPubkey {
|
InvoiceRequestContentsWithoutPayerSigningPubkey {
|
||||||
payer: PayerContents(metadata), offer, chain: None, amount_msats: None,
|
payer: PayerContents(metadata), offer, chain: None, amount_msats: None,
|
||||||
features: InvoiceRequestFeatures::empty(), quantity: None, payer_note: 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
|
$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))]
|
#[cfg_attr(c_bindings, allow(dead_code))]
|
||||||
pub(super) fn build_unchecked($self: $self_type) -> UnsignedInvoiceRequest {
|
pub(super) fn build_unchecked($self: $self_type) -> UnsignedInvoiceRequest {
|
||||||
$self.build_without_checks().0
|
$self.build_without_checks().0
|
||||||
|
@ -691,6 +699,8 @@ pub(super) struct InvoiceRequestContentsWithoutPayerSigningPubkey {
|
||||||
features: InvoiceRequestFeatures,
|
features: InvoiceRequestFeatures,
|
||||||
quantity: Option<u64>,
|
quantity: Option<u64>,
|
||||||
payer_note: Option<String>,
|
payer_note: Option<String>,
|
||||||
|
#[cfg(test)]
|
||||||
|
experimental_bar: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! invoice_request_accessors { ($self: ident, $contents: expr) => {
|
macro_rules! invoice_request_accessors { ($self: ident, $contents: expr) => {
|
||||||
|
@ -994,7 +1004,9 @@ impl VerifiedInvoiceRequest {
|
||||||
let InvoiceRequestContents {
|
let InvoiceRequestContents {
|
||||||
payer_signing_pubkey,
|
payer_signing_pubkey,
|
||||||
inner: InvoiceRequestContentsWithoutPayerSigningPubkey {
|
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;
|
} = &self.inner.contents;
|
||||||
|
|
||||||
|
@ -1076,7 +1088,10 @@ impl InvoiceRequestContentsWithoutPayerSigningPubkey {
|
||||||
paths: None,
|
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)
|
(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> =
|
pub(super) const EXPERIMENTAL_INVOICE_REQUEST_TYPES: core::ops::Range<u64> =
|
||||||
2_000_000_000..3_000_000_000;
|
2_000_000_000..3_000_000_000;
|
||||||
|
|
||||||
|
#[cfg(not(test))]
|
||||||
tlv_stream!(
|
tlv_stream!(
|
||||||
ExperimentalInvoiceRequestTlvStream, ExperimentalInvoiceRequestTlvStreamRef,
|
ExperimentalInvoiceRequestTlvStream, ExperimentalInvoiceRequestTlvStreamRef,
|
||||||
EXPERIMENTAL_INVOICE_REQUEST_TYPES, {}
|
EXPERIMENTAL_INVOICE_REQUEST_TYPES, {}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
tlv_stream!(
|
||||||
|
ExperimentalInvoiceRequestTlvStream, ExperimentalInvoiceRequestTlvStreamRef,
|
||||||
|
EXPERIMENTAL_INVOICE_REQUEST_TYPES, {
|
||||||
|
(2_999_999_999, experimental_bar: (u64, HighZeroBytesDroppedBigSize)),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
type FullInvoiceRequestTlvStream = (
|
type FullInvoiceRequestTlvStream = (
|
||||||
PayerTlvStream, OfferTlvStream, InvoiceRequestTlvStream, SignatureTlvStream,
|
PayerTlvStream, OfferTlvStream, InvoiceRequestTlvStream, SignatureTlvStream,
|
||||||
ExperimentalOfferTlvStream, ExperimentalInvoiceRequestTlvStream,
|
ExperimentalOfferTlvStream, ExperimentalInvoiceRequestTlvStream,
|
||||||
|
@ -1244,7 +1268,10 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
|
||||||
chain, amount, features, quantity, payer_id, payer_note, paths,
|
chain, amount, features, quantity, payer_id, payer_note, paths,
|
||||||
},
|
},
|
||||||
experimental_offer_tlv_stream,
|
experimental_offer_tlv_stream,
|
||||||
ExperimentalInvoiceRequestTlvStream {},
|
ExperimentalInvoiceRequestTlvStream {
|
||||||
|
#[cfg(test)]
|
||||||
|
experimental_bar,
|
||||||
|
},
|
||||||
) = tlv_stream;
|
) = tlv_stream;
|
||||||
|
|
||||||
let payer = match metadata {
|
let payer = match metadata {
|
||||||
|
@ -1278,6 +1305,8 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
|
||||||
Ok(InvoiceRequestContents {
|
Ok(InvoiceRequestContents {
|
||||||
inner: InvoiceRequestContentsWithoutPayerSigningPubkey {
|
inner: InvoiceRequestContentsWithoutPayerSigningPubkey {
|
||||||
payer, offer, chain, amount_msats: amount, features, quantity, payer_note,
|
payer, offer, chain, amount_msats: amount, features, quantity, payer_note,
|
||||||
|
#[cfg(test)]
|
||||||
|
experimental_bar,
|
||||||
},
|
},
|
||||||
payer_signing_pubkey,
|
payer_signing_pubkey,
|
||||||
})
|
})
|
||||||
|
@ -1460,7 +1489,9 @@ mod tests {
|
||||||
ExperimentalOfferTlvStreamRef {
|
ExperimentalOfferTlvStreamRef {
|
||||||
experimental_foo: None,
|
experimental_foo: None,
|
||||||
},
|
},
|
||||||
ExperimentalInvoiceRequestTlvStreamRef {},
|
ExperimentalInvoiceRequestTlvStreamRef {
|
||||||
|
experimental_bar: None,
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1513,6 +1544,7 @@ mod tests {
|
||||||
let invoice_request = offer
|
let invoice_request = offer
|
||||||
.request_invoice_deriving_metadata(signing_pubkey, &expanded_key, nonce, payment_id)
|
.request_invoice_deriving_metadata(signing_pubkey, &expanded_key, nonce, payment_id)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
.experimental_bar(42)
|
||||||
.build().unwrap()
|
.build().unwrap()
|
||||||
.sign(payer_sign).unwrap();
|
.sign(payer_sign).unwrap();
|
||||||
assert_eq!(invoice_request.payer_signing_pubkey(), payer_pubkey());
|
assert_eq!(invoice_request.payer_signing_pubkey(), payer_pubkey());
|
||||||
|
@ -1603,6 +1635,7 @@ mod tests {
|
||||||
let invoice_request = offer
|
let invoice_request = offer
|
||||||
.request_invoice_deriving_signing_pubkey(&expanded_key, nonce, &secp_ctx, payment_id)
|
.request_invoice_deriving_signing_pubkey(&expanded_key, nonce, &secp_ctx, payment_id)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
.experimental_bar(42)
|
||||||
.build_and_sign()
|
.build_and_sign()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -178,6 +178,8 @@ macro_rules! refund_explicit_metadata_builder_methods { () => {
|
||||||
quantity: None, payer_signing_pubkey: signing_pubkey, payer_note: None, paths: None,
|
quantity: None, payer_signing_pubkey: signing_pubkey, payer_note: None, paths: None,
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
experimental_foo: None,
|
experimental_foo: None,
|
||||||
|
#[cfg(test)]
|
||||||
|
experimental_bar: None,
|
||||||
},
|
},
|
||||||
secp_ctx: 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,
|
quantity: None, payer_signing_pubkey: node_id, payer_note: None, paths: None,
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
experimental_foo: None,
|
experimental_foo: None,
|
||||||
|
#[cfg(test)]
|
||||||
|
experimental_bar: None,
|
||||||
},
|
},
|
||||||
secp_ctx: Some(secp_ctx),
|
secp_ctx: Some(secp_ctx),
|
||||||
})
|
})
|
||||||
|
@ -368,6 +372,12 @@ macro_rules! refund_builder_test_methods { (
|
||||||
$self.refund.experimental_foo = Some(experimental_foo);
|
$self.refund.experimental_foo = Some(experimental_foo);
|
||||||
$return_value
|
$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> {
|
impl<'a> RefundBuilder<'a, secp256k1::SignOnly> {
|
||||||
|
@ -449,6 +459,8 @@ pub(super) struct RefundContents {
|
||||||
paths: Option<Vec<BlindedMessagePath>>,
|
paths: Option<Vec<BlindedMessagePath>>,
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
experimental_foo: Option<u64>,
|
experimental_foo: Option<u64>,
|
||||||
|
#[cfg(test)]
|
||||||
|
experimental_bar: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Refund {
|
impl Refund {
|
||||||
|
@ -787,7 +799,10 @@ impl RefundContents {
|
||||||
experimental_foo: self.experimental_foo,
|
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)
|
(payer, offer, invoice_request, experimental_offer, experimental_invoice_request)
|
||||||
}
|
}
|
||||||
|
@ -879,7 +894,10 @@ impl TryFrom<RefundTlvStream> for RefundContents {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
experimental_foo,
|
experimental_foo,
|
||||||
},
|
},
|
||||||
ExperimentalInvoiceRequestTlvStream {},
|
ExperimentalInvoiceRequestTlvStream {
|
||||||
|
#[cfg(test)]
|
||||||
|
experimental_bar,
|
||||||
|
},
|
||||||
) = tlv_stream;
|
) = tlv_stream;
|
||||||
|
|
||||||
let payer = match payer_metadata {
|
let payer = match payer_metadata {
|
||||||
|
@ -942,6 +960,8 @@ impl TryFrom<RefundTlvStream> for RefundContents {
|
||||||
payer_signing_pubkey, payer_note, paths,
|
payer_signing_pubkey, payer_note, paths,
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
experimental_foo,
|
experimental_foo,
|
||||||
|
#[cfg(test)]
|
||||||
|
experimental_bar,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1050,7 +1070,9 @@ mod tests {
|
||||||
ExperimentalOfferTlvStreamRef {
|
ExperimentalOfferTlvStreamRef {
|
||||||
experimental_foo: None,
|
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)
|
::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx, 1000, payment_id)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.experimental_foo(42)
|
.experimental_foo(42)
|
||||||
|
.experimental_bar(42)
|
||||||
.build().unwrap();
|
.build().unwrap();
|
||||||
assert_eq!(refund.payer_signing_pubkey(), node_id);
|
assert_eq!(refund.payer_signing_pubkey(), node_id);
|
||||||
|
|
||||||
|
@ -1148,6 +1171,7 @@ mod tests {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.path(blinded_path)
|
.path(blinded_path)
|
||||||
.experimental_foo(42)
|
.experimental_foo(42)
|
||||||
|
.experimental_bar(42)
|
||||||
.build().unwrap();
|
.build().unwrap();
|
||||||
assert_ne!(refund.payer_signing_pubkey(), node_id);
|
assert_ne!(refund.payer_signing_pubkey(), node_id);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue