@@ -162,8 +162,11 @@ fn do_channel_full_cycle<K: KVStore + Sync + Send>(
162162 node_a. send_payment_using_amount( & invoice, underpaid_amount)
163163 ) ;
164164
165+ println ! ( "\n B overpaid receive_payment" ) ;
165166 let invoice = node_b. receive_payment ( invoice_amount_2_msat, & "asdf" , 9217 ) . unwrap ( ) ;
166167 let overpaid_amount_msat = invoice_amount_2_msat + 100 ;
168+
169+ println ! ( "\n A overpaid send_payment" ) ;
167170 let payment_hash = node_a. send_payment_using_amount ( & invoice, overpaid_amount_msat) . unwrap ( ) ;
168171 expect_event ! ( node_a, PaymentSuccessful ) ;
169172 let received_amount = match node_b. wait_next_event ( ) {
@@ -185,9 +188,11 @@ fn do_channel_full_cycle<K: KVStore + Sync + Send>(
185188 assert_eq ! ( node_b. payment( & payment_hash) . unwrap( ) . amount_msat, Some ( overpaid_amount_msat) ) ;
186189
187190 // Test "zero-amount" invoice payment
191+ println ! ( "\n B receive_variable_amount_payment" ) ;
188192 let variable_amount_invoice = node_b. receive_variable_amount_payment ( & "asdf" , 9217 ) . unwrap ( ) ;
189193 let determined_amount_msat = 2345_678 ;
190194 assert_eq ! ( Err ( Error :: InvalidInvoice ) , node_a. send_payment( & variable_amount_invoice) ) ;
195+ println ! ( "\n A send_payment_using_amount" ) ;
191196 let payment_hash =
192197 node_a. send_payment_using_amount ( & variable_amount_invoice, determined_amount_msat) . unwrap ( ) ;
193198
@@ -210,6 +215,40 @@ fn do_channel_full_cycle<K: KVStore + Sync + Send>(
210215 assert_eq ! ( node_b. payment( & payment_hash) . unwrap( ) . direction, PaymentDirection :: Inbound ) ;
211216 assert_eq ! ( node_b. payment( & payment_hash) . unwrap( ) . amount_msat, Some ( determined_amount_msat) ) ;
212217
218+ // Test spontaneous/keysend payments
219+ println ! ( "\n A send_spontaneous_payment" ) ;
220+ let keysend_amount_msat = 2500_000 ;
221+ let keysend_payment_hash =
222+ node_a. send_spontaneous_payment ( keysend_amount_msat, node_b. node_id ( ) ) . unwrap ( ) ;
223+ expect_event ! ( node_a, PaymentSuccessful ) ;
224+ let received_keysend_amount = match node_b. wait_next_event ( ) {
225+ ref e @ Event :: PaymentReceived { amount_msat, .. } => {
226+ println ! ( "{} got event {:?}" , std:: stringify!( node_b) , e) ;
227+ node_b. event_handled ( ) ;
228+ amount_msat
229+ }
230+ ref e => {
231+ panic ! ( "{} got unexpected event!: {:?}" , std:: stringify!( node_b) , e) ;
232+ }
233+ } ;
234+ assert_eq ! ( received_keysend_amount, keysend_amount_msat) ;
235+ assert_eq ! ( node_a. payment( & keysend_payment_hash) . unwrap( ) . status, PaymentStatus :: Succeeded ) ;
236+ assert_eq ! (
237+ node_a. payment( & keysend_payment_hash) . unwrap( ) . direction,
238+ PaymentDirection :: Outbound
239+ ) ;
240+ assert_eq ! (
241+ node_a. payment( & keysend_payment_hash) . unwrap( ) . amount_msat,
242+ Some ( keysend_amount_msat)
243+ ) ;
244+ assert_eq ! ( node_b. payment( & keysend_payment_hash) . unwrap( ) . status, PaymentStatus :: Succeeded ) ;
245+ assert_eq ! ( node_b. payment( & keysend_payment_hash) . unwrap( ) . direction, PaymentDirection :: Inbound ) ;
246+ assert_eq ! (
247+ node_b. payment( & keysend_payment_hash) . unwrap( ) . amount_msat,
248+ Some ( keysend_amount_msat)
249+ ) ;
250+
251+ println ! ( "\n B close_channel" ) ;
213252 node_b. close_channel ( & channel_id, node_a. node_id ( ) ) . unwrap ( ) ;
214253 expect_event ! ( node_a, ChannelClosed ) ;
215254 expect_event ! ( node_b, ChannelClosed ) ;
@@ -220,8 +259,12 @@ fn do_channel_full_cycle<K: KVStore + Sync + Send>(
220259 node_a. sync_wallets ( ) . unwrap ( ) ;
221260 node_b. sync_wallets ( ) . unwrap ( ) ;
222261
223- let sum_of_all_payments_sat =
224- ( push_msat + invoice_amount_1_msat + overpaid_amount_msat + determined_amount_msat) / 1000 ;
262+ let sum_of_all_payments_sat = ( push_msat
263+ + invoice_amount_1_msat
264+ + overpaid_amount_msat
265+ + determined_amount_msat
266+ + keysend_amount_msat)
267+ / 1000 ;
225268 let node_a_upper_bound_sat =
226269 ( premine_amount_sat - funding_amount_sat) + ( funding_amount_sat - sum_of_all_payments_sat) ;
227270 let node_a_lower_bound_sat = node_a_upper_bound_sat - onchain_fee_buffer_sat;
0 commit comments