@@ -10,6 +10,7 @@ use common::{
1010use ldk_node:: payment:: PaymentKind ;
1111use ldk_node:: { Builder , Event , NodeError } ;
1212
13+ use lightning:: ln:: channelmanager:: PaymentId ;
1314use lightning:: util:: persist:: KVStore ;
1415
1516use bitcoin:: { Amount , Network } ;
@@ -385,7 +386,7 @@ fn simple_bolt12_send_receive() {
385386 ) ;
386387
387388 node_a. sync_wallets ( ) . unwrap ( ) ;
388- open_channel ( & node_a, & node_b, 1_000_000 , true , & electrsd) ;
389+ open_channel ( & node_a, & node_b, 4_000_000 , true , & electrsd) ;
389390
390391 generate_blocks_and_wait ( & bitcoind. client , & electrsd. client , 6 ) ;
391392
@@ -422,6 +423,7 @@ fn simple_bolt12_send_receive() {
422423 panic ! ( "Unexpected payment kind" ) ;
423424 } ,
424425 }
426+ assert_eq ! ( node_a_payments. first( ) . unwrap( ) . amount_msat, Some ( expected_amount_msat) ) ;
425427
426428 expect_payment_received_event ! ( node_b, expected_amount_msat) ;
427429 let node_b_payments = node_b. list_payments ( ) ;
@@ -437,4 +439,52 @@ fn simple_bolt12_send_receive() {
437439 panic ! ( "Unexpected payment kind" ) ;
438440 } ,
439441 }
442+ assert_eq ! ( node_b_payments. first( ) . unwrap( ) . amount_msat, Some ( expected_amount_msat) ) ;
443+
444+ // Test send_using_amount
445+ let offer_amount_msat = 100_000_000 ;
446+ let less_than_offer_amount = offer_amount_msat - 10_000 ;
447+ let expected_amount_msat = offer_amount_msat + 10_000 ;
448+ let offer = node_b. bolt12_payment ( ) . receive ( offer_amount_msat, "asdf" ) . unwrap ( ) ;
449+ assert ! ( node_a
450+ . bolt12_payment( )
451+ . send_using_amount( & offer, None , less_than_offer_amount)
452+ . is_err( ) ) ;
453+ let payment_id =
454+ node_a. bolt12_payment ( ) . send_using_amount ( & offer, None , expected_amount_msat) . unwrap ( ) ;
455+
456+ expect_payment_successful_event ! ( node_a, Some ( payment_id) , None ) ;
457+ let node_a_payments = node_a. list_payments_with_filter ( |p| p. id == payment_id) ;
458+ assert_eq ! ( node_a_payments. len( ) , 1 ) ;
459+ let payment_hash = match node_a_payments. first ( ) . unwrap ( ) . kind {
460+ PaymentKind :: Bolt12Offer { hash, preimage, secret : _, offer_id } => {
461+ assert ! ( hash. is_some( ) ) ;
462+ assert ! ( preimage. is_some( ) ) ;
463+ assert_eq ! ( offer_id, offer. id( ) ) ;
464+ //TODO: We should eventually set and assert the secret sender-side, too, but the BOLT12
465+ //API currently doesn't allow to do that.
466+ hash. unwrap ( )
467+ } ,
468+ _ => {
469+ panic ! ( "Unexpected payment kind" ) ;
470+ } ,
471+ } ;
472+ assert_eq ! ( node_a_payments. first( ) . unwrap( ) . amount_msat, Some ( expected_amount_msat) ) ;
473+
474+ expect_payment_received_event ! ( node_b, expected_amount_msat) ;
475+ let node_b_payment_id = PaymentId ( payment_hash. 0 ) ;
476+ let node_b_payments = node_b. list_payments_with_filter ( |p| p. id == node_b_payment_id) ;
477+ assert_eq ! ( node_b_payments. len( ) , 1 ) ;
478+ match node_b_payments. first ( ) . unwrap ( ) . kind {
479+ PaymentKind :: Bolt12Offer { hash, preimage, secret, offer_id } => {
480+ assert ! ( hash. is_some( ) ) ;
481+ assert ! ( preimage. is_some( ) ) ;
482+ assert ! ( secret. is_some( ) ) ;
483+ assert_eq ! ( offer_id, offer. id( ) ) ;
484+ } ,
485+ _ => {
486+ panic ! ( "Unexpected payment kind" ) ;
487+ } ,
488+ }
489+ assert_eq ! ( node_b_payments. first( ) . unwrap( ) . amount_msat, Some ( expected_amount_msat) ) ;
440490}
0 commit comments