@@ -190,8 +190,11 @@ fn do_channel_full_cycle<K: KVStore + Sync + Send>(
190190 node_a. send_payment_using_amount( & invoice, underpaid_amount)
191191 ) ;
192192
193+ println ! ( "\n B overpaid receive_payment" ) ;
193194 let invoice = node_b. receive_payment ( invoice_amount_2_msat, & "asdf" , 9217 ) . unwrap ( ) ;
194195 let overpaid_amount_msat = invoice_amount_2_msat + 100 ;
196+
197+ println ! ( "\n A overpaid send_payment" ) ;
195198 let payment_hash = node_a. send_payment_using_amount ( & invoice, overpaid_amount_msat) . unwrap ( ) ;
196199 expect_event ! ( node_a, PaymentSuccessful ) ;
197200 let received_amount = match node_b. wait_next_event ( ) {
@@ -213,9 +216,11 @@ fn do_channel_full_cycle<K: KVStore + Sync + Send>(
213216 assert_eq ! ( node_b. payment( & payment_hash) . unwrap( ) . amount_msat, Some ( overpaid_amount_msat) ) ;
214217
215218 // Test "zero-amount" invoice payment
219+ println ! ( "\n B receive_variable_amount_payment" ) ;
216220 let variable_amount_invoice = node_b. receive_variable_amount_payment ( & "asdf" , 9217 ) . unwrap ( ) ;
217221 let determined_amount_msat = 2345_678 ;
218222 assert_eq ! ( Err ( Error :: InvalidInvoice ) , node_a. send_payment( & variable_amount_invoice) ) ;
223+ println ! ( "\n A send_payment_using_amount" ) ;
219224 let payment_hash =
220225 node_a. send_payment_using_amount ( & variable_amount_invoice, determined_amount_msat) . unwrap ( ) ;
221226
@@ -238,6 +243,40 @@ fn do_channel_full_cycle<K: KVStore + Sync + Send>(
238243 assert_eq ! ( node_b. payment( & payment_hash) . unwrap( ) . direction, PaymentDirection :: Inbound ) ;
239244 assert_eq ! ( node_b. payment( & payment_hash) . unwrap( ) . amount_msat, Some ( determined_amount_msat) ) ;
240245
246+ // Test spontaneous/keysend payments
247+ println ! ( "\n A send_spontaneous_payment" ) ;
248+ let keysend_amount_msat = 2500_000 ;
249+ let keysend_payment_hash =
250+ node_a. send_spontaneous_payment ( keysend_amount_msat, node_b. node_id ( ) ) . unwrap ( ) ;
251+ expect_event ! ( node_a, PaymentSuccessful ) ;
252+ let received_keysend_amount = match node_b. wait_next_event ( ) {
253+ ref e @ Event :: PaymentReceived { amount_msat, .. } => {
254+ println ! ( "{} got event {:?}" , std:: stringify!( node_b) , e) ;
255+ node_b. event_handled ( ) ;
256+ amount_msat
257+ }
258+ ref e => {
259+ panic ! ( "{} got unexpected event!: {:?}" , std:: stringify!( node_b) , e) ;
260+ }
261+ } ;
262+ assert_eq ! ( received_keysend_amount, keysend_amount_msat) ;
263+ assert_eq ! ( node_a. payment( & keysend_payment_hash) . unwrap( ) . status, PaymentStatus :: Succeeded ) ;
264+ assert_eq ! (
265+ node_a. payment( & keysend_payment_hash) . unwrap( ) . direction,
266+ PaymentDirection :: Outbound
267+ ) ;
268+ assert_eq ! (
269+ node_a. payment( & keysend_payment_hash) . unwrap( ) . amount_msat,
270+ Some ( keysend_amount_msat)
271+ ) ;
272+ assert_eq ! ( node_b. payment( & keysend_payment_hash) . unwrap( ) . status, PaymentStatus :: Succeeded ) ;
273+ assert_eq ! ( node_b. payment( & keysend_payment_hash) . unwrap( ) . direction, PaymentDirection :: Inbound ) ;
274+ assert_eq ! (
275+ node_b. payment( & keysend_payment_hash) . unwrap( ) . amount_msat,
276+ Some ( keysend_amount_msat)
277+ ) ;
278+
279+ println ! ( "\n B close_channel" ) ;
241280 node_b. close_channel ( & channel_id, node_a. node_id ( ) ) . unwrap ( ) ;
242281 expect_event ! ( node_a, ChannelClosed ) ;
243282 expect_event ! ( node_b, ChannelClosed ) ;
@@ -248,8 +287,12 @@ fn do_channel_full_cycle<K: KVStore + Sync + Send>(
248287 node_a. sync_wallets ( ) . unwrap ( ) ;
249288 node_b. sync_wallets ( ) . unwrap ( ) ;
250289
251- let sum_of_all_payments_sat =
252- ( push_msat + invoice_amount_1_msat + overpaid_amount_msat + determined_amount_msat) / 1000 ;
290+ let sum_of_all_payments_sat = ( push_msat
291+ + invoice_amount_1_msat
292+ + overpaid_amount_msat
293+ + determined_amount_msat
294+ + keysend_amount_msat)
295+ / 1000 ;
253296 let node_a_upper_bound_sat =
254297 ( premine_amount_sat - funding_amount_sat) + ( funding_amount_sat - sum_of_all_payments_sat) ;
255298 let node_a_lower_bound_sat = node_a_upper_bound_sat - onchain_fee_buffer_sat;
0 commit comments