@@ -2481,7 +2481,6 @@ mod tests {
2481
2481
. amount_msats ( 1000 )
2482
2482
. build ( ) . unwrap ( )
2483
2483
. request_invoice ( & expanded_key, nonce, & secp_ctx, payment_id) . unwrap ( )
2484
- . amount_msats ( 1000 ) . unwrap ( )
2485
2484
. build_and_sign ( ) . unwrap ( )
2486
2485
. respond_with_no_std ( payment_paths ( ) , payment_hash ( ) , now ( ) ) . unwrap ( )
2487
2486
. build ( ) . unwrap ( )
@@ -2501,33 +2500,6 @@ mod tests {
2501
2500
Ok ( _) => panic ! ( "expected error" ) ,
2502
2501
Err ( e) => assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: MissingAmount ) ) ,
2503
2502
}
2504
-
2505
- let mut tlv_stream = invoice. as_tlv_stream ( ) ;
2506
- tlv_stream. 3 . amount = Some ( 2000 ) ;
2507
-
2508
- match Bolt12Invoice :: try_from ( tlv_stream. to_bytes ( ) ) {
2509
- Ok ( _) => panic ! ( "expected error" ) ,
2510
- Err ( e) => assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: InvalidAmount ) ) ,
2511
- }
2512
-
2513
- let invoice = RefundBuilder :: new ( vec ! [ 1 ; 32 ] , payer_pubkey ( ) , 1000 ) . unwrap ( )
2514
- . build ( ) . unwrap ( )
2515
- . respond_using_derived_keys_no_std (
2516
- payment_paths ( ) , payment_hash ( ) , now ( ) , & expanded_key, & entropy
2517
- )
2518
- . unwrap ( )
2519
- . build_and_sign ( & secp_ctx) . unwrap ( ) ;
2520
-
2521
- let mut buffer = Vec :: new ( ) ;
2522
- invoice. write ( & mut buffer) . unwrap ( ) ;
2523
-
2524
- let mut tlv_stream = invoice. as_tlv_stream ( ) ;
2525
- tlv_stream. 3 . amount = Some ( 2000 ) ;
2526
-
2527
- match Bolt12Invoice :: try_from ( tlv_stream. to_bytes ( ) ) {
2528
- Ok ( _) => panic ! ( "expected error" ) ,
2529
- Err ( e) => assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: InvalidAmount ) ) ,
2530
- }
2531
2503
}
2532
2504
2533
2505
#[ test]
@@ -2748,6 +2720,69 @@ mod tests {
2748
2720
}
2749
2721
}
2750
2722
2723
+ #[ test]
2724
+ fn fails_parsing_invoice_with_wrong_amount ( ) {
2725
+ let expanded_key = ExpandedKey :: new ( & KeyMaterial ( [ 42 ; 32 ] ) ) ;
2726
+ let entropy = FixedEntropy { } ;
2727
+ let nonce = Nonce :: from_entropy_source ( & entropy) ;
2728
+ let secp_ctx = Secp256k1 :: new ( ) ;
2729
+ let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
2730
+
2731
+ let invoice = OfferBuilder :: new ( recipient_pubkey ( ) )
2732
+ . amount_msats ( 1000 )
2733
+ . build ( ) . unwrap ( )
2734
+ . request_invoice ( & expanded_key, nonce, & secp_ctx, payment_id) . unwrap ( )
2735
+ . build_and_sign ( ) . unwrap ( )
2736
+ . respond_with_no_std ( payment_paths ( ) , payment_hash ( ) , now ( ) ) . unwrap ( )
2737
+ . amount_msats_unchecked ( 2000 )
2738
+ . build ( ) . unwrap ( )
2739
+ . sign ( recipient_sign) . unwrap ( ) ;
2740
+
2741
+ let mut buffer = Vec :: new ( ) ;
2742
+ invoice. write ( & mut buffer) . unwrap ( ) ;
2743
+
2744
+ match Bolt12Invoice :: try_from ( buffer) {
2745
+ Ok ( _) => panic ! ( "expected error" ) ,
2746
+ Err ( e) => assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: InvalidAmount ) ) ,
2747
+ }
2748
+
2749
+ let invoice = OfferBuilder :: new ( recipient_pubkey ( ) )
2750
+ . amount_msats ( 1000 )
2751
+ . build ( ) . unwrap ( )
2752
+ . request_invoice ( & expanded_key, nonce, & secp_ctx, payment_id) . unwrap ( )
2753
+ . amount_msats ( 1000 ) . unwrap ( )
2754
+ . build_and_sign ( ) . unwrap ( )
2755
+ . respond_with_no_std ( payment_paths ( ) , payment_hash ( ) , now ( ) ) . unwrap ( )
2756
+ . amount_msats_unchecked ( 2000 )
2757
+ . build ( ) . unwrap ( )
2758
+ . sign ( recipient_sign) . unwrap ( ) ;
2759
+
2760
+ let mut buffer = Vec :: new ( ) ;
2761
+ invoice. write ( & mut buffer) . unwrap ( ) ;
2762
+
2763
+ match Bolt12Invoice :: try_from ( buffer) {
2764
+ Ok ( _) => panic ! ( "expected error" ) ,
2765
+ Err ( e) => assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: InvalidAmount ) ) ,
2766
+ }
2767
+
2768
+ let invoice = RefundBuilder :: new ( vec ! [ 1 ; 32 ] , payer_pubkey ( ) , 1000 ) . unwrap ( )
2769
+ . build ( ) . unwrap ( )
2770
+ . respond_using_derived_keys_no_std (
2771
+ payment_paths ( ) , payment_hash ( ) , now ( ) , & expanded_key, & entropy
2772
+ )
2773
+ . unwrap ( )
2774
+ . amount_msats_unchecked ( 2000 )
2775
+ . build_and_sign ( & secp_ctx) . unwrap ( ) ;
2776
+
2777
+ let mut buffer = Vec :: new ( ) ;
2778
+ invoice. write ( & mut buffer) . unwrap ( ) ;
2779
+
2780
+ match Bolt12Invoice :: try_from ( buffer) {
2781
+ Ok ( _) => panic ! ( "expected error" ) ,
2782
+ Err ( e) => assert_eq ! ( e, Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: InvalidAmount ) ) ,
2783
+ }
2784
+ }
2785
+
2751
2786
#[ test]
2752
2787
fn fails_parsing_invoice_without_signature ( ) {
2753
2788
let expanded_key = ExpandedKey :: new ( & KeyMaterial ( [ 42 ; 32 ] ) ) ;
0 commit comments