@@ -1180,7 +1180,7 @@ impl Readable for InvoiceRequestFields {
1180
1180
1181
1181
#[ cfg( test) ]
1182
1182
mod tests {
1183
- use super :: { InvoiceRequest , InvoiceRequestTlvStreamRef , SIGNATURE_TAG , UnsignedInvoiceRequest } ;
1183
+ use super :: { InvoiceRequest , InvoiceRequestFields , InvoiceRequestTlvStreamRef , SIGNATURE_TAG , UnsignedInvoiceRequest } ;
1184
1184
1185
1185
use bitcoin:: blockdata:: constants:: ChainHash ;
1186
1186
use bitcoin:: network:: constants:: Network ;
@@ -1209,7 +1209,7 @@ mod tests {
1209
1209
use crate :: offers:: payer:: PayerTlvStreamRef ;
1210
1210
use crate :: offers:: test_utils:: * ;
1211
1211
use crate :: util:: ser:: { BigSize , Writeable } ;
1212
- use crate :: util:: string:: PrintableString ;
1212
+ use crate :: util:: string:: { PrintableString , UntrustedString } ;
1213
1213
1214
1214
#[ test]
1215
1215
fn builds_invoice_request_with_defaults ( ) {
@@ -2245,4 +2245,48 @@ mod tests {
2245
2245
Err ( e) => assert_eq ! ( e, Bolt12ParseError :: Decode ( DecodeError :: InvalidValue ) ) ,
2246
2246
}
2247
2247
}
2248
+
2249
+ #[ test]
2250
+ fn copies_verified_invoice_request_fields ( ) {
2251
+ let desc = "foo" . to_string ( ) ;
2252
+ let node_id = recipient_pubkey ( ) ;
2253
+ let expanded_key = ExpandedKey :: new ( & KeyMaterial ( [ 42 ; 32 ] ) ) ;
2254
+ let entropy = FixedEntropy { } ;
2255
+ let secp_ctx = Secp256k1 :: new ( ) ;
2256
+
2257
+ #[ cfg( c_bindings) ]
2258
+ use super :: OfferWithDerivedMetadataBuilder as OfferBuilder ;
2259
+ let offer = OfferBuilder
2260
+ :: deriving_signing_pubkey ( desc, node_id, & expanded_key, & entropy, & secp_ctx)
2261
+ . chain ( Network :: Testnet )
2262
+ . amount_msats ( 1000 )
2263
+ . supported_quantity ( Quantity :: Unbounded )
2264
+ . build ( ) . unwrap ( ) ;
2265
+ assert_eq ! ( offer. signing_pubkey( ) , node_id) ;
2266
+
2267
+ let invoice_request = offer. request_invoice ( vec ! [ 1 ; 32 ] , payer_pubkey ( ) ) . unwrap ( )
2268
+ . chain ( Network :: Testnet ) . unwrap ( )
2269
+ . amount_msats ( 1001 ) . unwrap ( )
2270
+ . quantity ( 1 ) . unwrap ( )
2271
+ . payer_note ( "0" . repeat ( 1024 ) )
2272
+ . build ( ) . unwrap ( )
2273
+ . sign ( payer_sign) . unwrap ( ) ;
2274
+ match invoice_request. verify ( & expanded_key, & secp_ctx) {
2275
+ Ok ( invoice_request) => {
2276
+ assert_eq ! ( invoice_request. offer_id, offer. id( ) ) ;
2277
+ assert_eq ! (
2278
+ invoice_request. fields( ) ,
2279
+ InvoiceRequestFields {
2280
+ payer_id: payer_pubkey( ) ,
2281
+ chain: Some ( ChainHash :: using_genesis_block( Network :: Testnet ) ) ,
2282
+ amount_msats: Some ( 1001 ) ,
2283
+ features: InvoiceRequestFeatures :: empty( ) ,
2284
+ quantity: Some ( 1 ) ,
2285
+ payer_note: Some ( UntrustedString ( "0" . repeat( 512 ) ) ) ,
2286
+ }
2287
+ ) ;
2288
+ } ,
2289
+ Err ( _) => panic ! ( "unexpected error" ) ,
2290
+ }
2291
+ }
2248
2292
}
0 commit comments