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