@@ -724,6 +724,64 @@ mod test {
724724 assert_eq ! ( events. len( ) , 2 ) ;
725725 }
726726
727+ fn make_route_hints_override_test_params (
728+ route_hints_override : Option < Vec < RouteHint > > ,
729+ ) -> Bolt11InvoiceParameters {
730+ Bolt11InvoiceParameters {
731+ amount_msats : Some ( 10_000 ) ,
732+ description : Bolt11InvoiceDescription :: Direct (
733+ Description :: new ( "test" . to_string ( ) ) . unwrap ( ) ,
734+ ) ,
735+ invoice_expiry_delta_secs : Some ( 3600 ) ,
736+ route_hints_override,
737+ ..Default :: default ( )
738+ }
739+ }
740+
741+ #[ test]
742+ fn test_create_bolt11_invoice_route_hints_override ( ) {
743+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
744+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
745+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
746+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
747+ create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100_000 , 10_001 ) ;
748+
749+ let invoice = nodes[ 1 ]
750+ . node
751+ . create_bolt11_invoice ( make_route_hints_override_test_params ( None ) )
752+ . unwrap ( ) ;
753+ let chan = & nodes[ 1 ] . node . list_usable_channels ( ) [ 0 ] ;
754+ assert_eq ! ( invoice. route_hints( ) . len( ) , 1 ) ;
755+ assert_eq ! (
756+ invoice. route_hints( ) [ 0 ] . 0 [ 0 ] . short_channel_id,
757+ chan. inbound_scid_alias. unwrap( )
758+ ) ;
759+ assert_eq ! ( invoice. route_hints( ) [ 0 ] . 0 [ 0 ] . htlc_minimum_msat, chan. inbound_htlc_minimum_msat) ;
760+ assert_eq ! ( invoice. route_hints( ) [ 0 ] . 0 [ 0 ] . htlc_maximum_msat, chan. inbound_htlc_maximum_msat) ;
761+
762+ let invoice = nodes[ 1 ]
763+ . node
764+ . create_bolt11_invoice ( make_route_hints_override_test_params ( Some ( vec ! [ ] ) ) )
765+ . unwrap ( ) ;
766+ assert ! ( invoice. route_hints( ) . is_empty( ) ) ;
767+
768+ let custom_hint = RouteHint ( vec ! [ RouteHintHop {
769+ src_node_id: nodes[ 0 ] . node. get_our_node_id( ) ,
770+ short_channel_id: 42 ,
771+ fees: RoutingFees { base_msat: 1000 , proportional_millionths: 500 } ,
772+ cltv_expiry_delta: MIN_CLTV_EXPIRY_DELTA ,
773+ htlc_minimum_msat: Some ( 1 ) ,
774+ htlc_maximum_msat: Some ( 1_000_000 ) ,
775+ } ] ) ;
776+ let invoice = nodes[ 1 ]
777+ . node
778+ . create_bolt11_invoice ( make_route_hints_override_test_params ( Some ( vec ! [
779+ custom_hint. clone( )
780+ ] ) ) )
781+ . unwrap ( ) ;
782+ assert_eq ! ( invoice. route_hints( ) , vec![ custom_hint] ) ;
783+ }
784+
727785 fn do_create_invoice_min_final_cltv_delta ( with_custom_delta : bool ) {
728786 let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
729787 let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
0 commit comments