@@ -565,22 +565,33 @@ mod tests {
565
565
use crate :: blinded_path:: { BlindedHop , BlindedPath , IntroductionNode } ;
566
566
use crate :: ln:: features:: { Bolt12InvoiceFeatures , OfferFeatures } ;
567
567
use crate :: ln:: inbound_payment:: ExpandedKey ;
568
- use crate :: offers:: invoice:: SIGNATURE_TAG ;
568
+ use crate :: offers:: invoice:: { InvoiceTlvStreamRef , SIGNATURE_TAG } ;
569
569
use crate :: offers:: merkle;
570
- use crate :: offers:: merkle:: TaggedHash ;
571
- use crate :: offers:: offer:: { Offer , OfferBuilder , Quantity } ;
570
+ use crate :: offers:: merkle:: { SignatureTlvStreamRef , TaggedHash } ;
571
+ use crate :: offers:: offer:: { Offer , OfferBuilder , OfferTlvStreamRef , Quantity } ;
572
572
use crate :: offers:: parse:: Bolt12SemanticError ;
573
573
use crate :: offers:: static_invoice:: {
574
574
StaticInvoice , StaticInvoiceBuilder , DEFAULT_RELATIVE_EXPIRY ,
575
575
} ;
576
576
use crate :: offers:: test_utils:: * ;
577
577
use crate :: sign:: KeyMaterial ;
578
- use crate :: util:: ser:: Writeable ;
578
+ use crate :: util:: ser:: { Iterable , Writeable } ;
579
579
use bitcoin:: blockdata:: constants:: ChainHash ;
580
580
use bitcoin:: secp256k1:: Secp256k1 ;
581
581
use bitcoin:: Network ;
582
582
use core:: time:: Duration ;
583
583
584
+ impl StaticInvoice {
585
+ fn as_tlv_stream ( & self ) -> ( OfferTlvStreamRef , InvoiceTlvStreamRef , SignatureTlvStreamRef ) {
586
+ let ( offer_tlv_stream, invoice_tlv_stream) = self . contents . as_tlv_stream ( ) ;
587
+ (
588
+ offer_tlv_stream,
589
+ invoice_tlv_stream,
590
+ SignatureTlvStreamRef { signature : Some ( & self . signature ) } ,
591
+ )
592
+ }
593
+ }
594
+
584
595
fn blinded_path ( ) -> BlindedPath {
585
596
BlindedPath {
586
597
introduction_node : IntroductionNode :: NodeId ( pubkey ( 40 ) ) ,
@@ -642,14 +653,43 @@ mod tests {
642
653
assert ! ( invoice. fallbacks( ) . is_empty( ) ) ;
643
654
assert_eq ! ( invoice. invoice_features( ) , & Bolt12InvoiceFeatures :: empty( ) ) ;
644
655
645
- let keys_opt = offer. verify ( & expanded_key, & secp_ctx) . unwrap ( ) . 1 ;
656
+ let keys = offer. verify ( & expanded_key, & secp_ctx) . unwrap ( ) . 1 . unwrap ( ) ;
646
657
let message = TaggedHash :: from_valid_tlv_stream_bytes ( SIGNATURE_TAG , & invoice. bytes ) ;
647
- assert ! ( merkle:: verify_signature(
648
- & invoice. signature,
649
- & message,
650
- keys_opt. unwrap( ) . public_key( )
651
- )
652
- . is_ok( ) ) ;
658
+ assert ! ( merkle:: verify_signature( & invoice. signature, & message, keys. public_key( ) ) . is_ok( ) ) ;
659
+
660
+ let paths = vec ! [ blinded_path( ) ] ;
661
+ let metadata = vec ! [ 42 ; 16 ] ;
662
+ assert_eq ! (
663
+ invoice. as_tlv_stream( ) ,
664
+ (
665
+ OfferTlvStreamRef {
666
+ chains: None ,
667
+ metadata: Some ( & metadata) ,
668
+ currency: None ,
669
+ amount: None ,
670
+ description: None ,
671
+ features: None ,
672
+ absolute_expiry: None ,
673
+ paths: Some ( & paths) ,
674
+ issuer: None ,
675
+ quantity_max: None ,
676
+ node_id: Some ( & keys. public_key( ) ) ,
677
+ } ,
678
+ InvoiceTlvStreamRef {
679
+ paths: Some ( Iterable ( payment_paths. iter( ) . map( |( _, path) | path) ) ) ,
680
+ blindedpay: Some ( Iterable ( payment_paths. iter( ) . map( |( payinfo, _) | payinfo) ) ) ,
681
+ created_at: Some ( now. as_secs( ) ) ,
682
+ relative_expiry: None ,
683
+ payment_hash: None ,
684
+ amount: None ,
685
+ fallbacks: None ,
686
+ features: None ,
687
+ node_id: Some ( & keys. public_key( ) ) ,
688
+ message_paths: Some ( & paths) ,
689
+ } ,
690
+ SignatureTlvStreamRef { signature: Some ( & invoice. signature( ) ) } ,
691
+ )
692
+ ) ;
653
693
654
694
if let Err ( e) = StaticInvoice :: try_from ( buffer) {
655
695
panic ! ( "error parsing invoice: {:?}" , e) ;
0 commit comments