@@ -997,7 +997,7 @@ mod tests {
997
997
use crate :: ln:: features:: { InvoiceRequestFeatures , OfferFeatures } ;
998
998
use crate :: ln:: inbound_payment:: ExpandedKey ;
999
999
use crate :: ln:: msgs:: { DecodeError , MAX_VALUE_MSAT } ;
1000
- use crate :: offers:: invoice_request:: { ExperimentalInvoiceRequestTlvStreamRef , INVOICE_REQUEST_TYPES , InvoiceRequestTlvStreamRef } ;
1000
+ use crate :: offers:: invoice_request:: { EXPERIMENTAL_INVOICE_REQUEST_TYPES , ExperimentalInvoiceRequestTlvStreamRef , INVOICE_REQUEST_TYPES , InvoiceRequestTlvStreamRef } ;
1001
1001
use crate :: offers:: nonce:: Nonce ;
1002
1002
use crate :: offers:: offer:: { ExperimentalOfferTlvStreamRef , OfferTlvStreamRef } ;
1003
1003
use crate :: offers:: parse:: { Bolt12ParseError , Bolt12SemanticError } ;
@@ -1621,6 +1621,43 @@ mod tests {
1621
1621
}
1622
1622
}
1623
1623
1624
+ #[ test]
1625
+ fn parses_refund_with_experimental_tlv_records ( ) {
1626
+ const UNKNOWN_ODD_TYPE : u64 = EXPERIMENTAL_INVOICE_REQUEST_TYPES . start + 1 ;
1627
+ assert ! ( UNKNOWN_ODD_TYPE % 2 == 1 ) ;
1628
+
1629
+ let refund = RefundBuilder :: new ( vec ! [ 1 ; 32 ] , payer_pubkey ( ) , 1000 ) . unwrap ( )
1630
+ . build ( ) . unwrap ( ) ;
1631
+
1632
+ let mut encoded_refund = Vec :: new ( ) ;
1633
+ refund. write ( & mut encoded_refund) . unwrap ( ) ;
1634
+ BigSize ( UNKNOWN_ODD_TYPE ) . write ( & mut encoded_refund) . unwrap ( ) ;
1635
+ BigSize ( 32 ) . write ( & mut encoded_refund) . unwrap ( ) ;
1636
+ [ 42u8 ; 32 ] . write ( & mut encoded_refund) . unwrap ( ) ;
1637
+
1638
+ match Refund :: try_from ( encoded_refund. clone ( ) ) {
1639
+ Ok ( refund) => assert_eq ! ( refund. bytes, encoded_refund) ,
1640
+ Err ( e) => panic ! ( "error parsing refund: {:?}" , e) ,
1641
+ }
1642
+
1643
+ const UNKNOWN_EVEN_TYPE : u64 = EXPERIMENTAL_INVOICE_REQUEST_TYPES . start ;
1644
+ assert ! ( UNKNOWN_EVEN_TYPE % 2 == 0 ) ;
1645
+
1646
+ let refund = RefundBuilder :: new ( vec ! [ 1 ; 32 ] , payer_pubkey ( ) , 1000 ) . unwrap ( )
1647
+ . build ( ) . unwrap ( ) ;
1648
+
1649
+ let mut encoded_refund = Vec :: new ( ) ;
1650
+ refund. write ( & mut encoded_refund) . unwrap ( ) ;
1651
+ BigSize ( UNKNOWN_EVEN_TYPE ) . write ( & mut encoded_refund) . unwrap ( ) ;
1652
+ BigSize ( 32 ) . write ( & mut encoded_refund) . unwrap ( ) ;
1653
+ [ 42u8 ; 32 ] . write ( & mut encoded_refund) . unwrap ( ) ;
1654
+
1655
+ match Refund :: try_from ( encoded_refund) {
1656
+ Ok ( _) => panic ! ( "expected error" ) ,
1657
+ Err ( e) => assert_eq ! ( e, Bolt12ParseError :: Decode ( DecodeError :: UnknownRequiredFeature ) ) ,
1658
+ }
1659
+ }
1660
+
1624
1661
#[ test]
1625
1662
fn fails_parsing_refund_with_out_of_range_tlv_records ( ) {
1626
1663
let secp_ctx = Secp256k1 :: new ( ) ;
@@ -1638,5 +1675,16 @@ mod tests {
1638
1675
Ok ( _) => panic ! ( "expected error" ) ,
1639
1676
Err ( e) => assert_eq ! ( e, Bolt12ParseError :: Decode ( DecodeError :: InvalidValue ) ) ,
1640
1677
}
1678
+
1679
+ let mut encoded_refund = Vec :: new ( ) ;
1680
+ refund. write ( & mut encoded_refund) . unwrap ( ) ;
1681
+ BigSize ( EXPERIMENTAL_INVOICE_REQUEST_TYPES . end ) . write ( & mut encoded_refund) . unwrap ( ) ;
1682
+ BigSize ( 32 ) . write ( & mut encoded_refund) . unwrap ( ) ;
1683
+ [ 42u8 ; 32 ] . write ( & mut encoded_refund) . unwrap ( ) ;
1684
+
1685
+ match Refund :: try_from ( encoded_refund) {
1686
+ Ok ( _) => panic ! ( "expected error" ) ,
1687
+ Err ( e) => assert_eq ! ( e, Bolt12ParseError :: Decode ( DecodeError :: InvalidValue ) ) ,
1688
+ }
1641
1689
}
1642
1690
}
0 commit comments