@@ -327,9 +327,9 @@ async fn multiple_incoming_same_tx() {
327327 ctx. outputs . push ( cout) ;
328328
329329 td. shielded_outputs . push ( od) ;
330- td. binding_sig = Signature :: read ( & vec ! [ 0u8 ; 64 ] [ ..] ) . ok ( ) ;
331330 }
332331
332+ td. binding_sig = Signature :: read ( & vec ! [ 0u8 ; 64 ] [ ..] ) . ok ( ) ;
333333 let tx = td. freeze ( ) . unwrap ( ) ;
334334 ctx. hash = tx. txid ( ) . clone ( ) . 0 . to_vec ( ) ;
335335
@@ -341,6 +341,7 @@ async fn multiple_incoming_same_tx() {
341341
342342 // 2. Check the notes - that we recieved 4 notes
343343 let notes = lc. do_list_notes ( true ) . await ;
344+ let txns = lc. do_list_transactions ( false ) . await ;
344345 for i in 0 ..4 {
345346 assert_eq ! ( notes[ "unspent_notes" ] [ i] [ "created_in_block" ] . as_u64( ) . unwrap( ) , 101 ) ;
346347 assert_eq ! ( notes[ "unspent_notes" ] [ i] [ "value" ] . as_u64( ) . unwrap( ) , value + i as u64 ) ;
@@ -349,6 +350,14 @@ async fn multiple_incoming_same_tx() {
349350 notes[ "unspent_notes" ] [ i] [ "address" ] ,
350351 lc. wallet. keys( ) . read( ) . await . get_all_zaddresses( ) [ 0 ]
351352 ) ;
353+
354+ assert_eq ! ( txns[ i] [ "txid" ] , tx. txid( ) . to_string( ) ) ;
355+ assert_eq ! ( txns[ i] [ "block_height" ] . as_u64( ) . unwrap( ) , 101 ) ;
356+ assert_eq ! (
357+ txns[ i] [ "address" ] ,
358+ lc. wallet. keys( ) . read( ) . await . get_all_zaddresses( ) [ 0 ]
359+ ) ;
360+ assert_eq ! ( txns[ i] [ "amount" ] . as_u64( ) . unwrap( ) , value + i as u64 ) ;
352361 }
353362
354363 // 3. Send a big tx, so all the value is spent
@@ -360,18 +369,79 @@ async fn multiple_incoming_same_tx() {
360369 fcbl. add_pending_sends ( & data) . await ;
361370 mine_pending_blocks ( & mut fcbl, & data, & lc) . await ;
362371
363- println ! ( "{}" , lc. do_list_notes( true ) . await . pretty( 2 ) ) ;
364-
365- // 5. Check the notes - that we recieved 4 notes
372+ // 5. Check the notes - that we spent all 4 notes
366373 let notes = lc. do_list_notes ( true ) . await ;
374+ let txns = lc. do_list_transactions ( false ) . await ;
367375 for i in 0 ..4 {
368376 assert_eq ! ( notes[ "spent_notes" ] [ i] [ "spent" ] , sent_txid) ;
369377 assert_eq ! ( notes[ "spent_notes" ] [ i] [ "spent_at_height" ] . as_u64( ) . unwrap( ) , 107 ) ;
370378 }
379+ assert_eq ! ( txns[ 4 ] [ "txid" ] , sent_txid) ;
380+ assert_eq ! ( txns[ 4 ] [ "block_height" ] , 107 ) ;
381+ assert_eq ! ( txns[ 4 ] [ "amount" ] . as_i64( ) . unwrap( ) , -( sent_value as i64 ) - 1000 ) ;
382+ assert_eq ! ( txns[ 4 ] [ "outgoing_metadata" ] [ 0 ] [ "address" ] , EXT_ZADDR . to_string( ) ) ;
383+ assert_eq ! ( txns[ 4 ] [ "outgoing_metadata" ] [ 0 ] [ "value" ] . as_u64( ) . unwrap( ) , sent_value) ;
384+ assert_eq ! ( txns[ 4 ] [ "outgoing_metadata" ] [ 0 ] [ "memo" ] . is_null( ) , true ) ;
385+
386+ // Shutdown everything cleanly
387+ stop_tx. send ( true ) . unwrap ( ) ;
388+ h1. await . unwrap ( ) ;
389+ }
390+
391+ #[ tokio:: test]
392+ async fn z_incoming_multiz_outgoing ( ) {
393+ let ( data, config, ready_rx, stop_tx, h1) = create_test_server ( ) . await ;
394+
395+ ready_rx. await . unwrap ( ) ;
396+
397+ let lc = LightClient :: test_new ( & config, None ) . await . unwrap ( ) ;
398+ let mut fcbl = FakeCompactBlockList :: new ( 0 ) ;
399+
400+ // 1. Mine 100 blocks
401+ mine_random_blocks ( & mut fcbl, & data, & lc, 100 ) . await ;
402+ assert_eq ! ( lc. wallet. last_scanned_height( ) . await , 100 ) ;
403+
404+ // 2. Send an incoming tx to fill the wallet
405+ let extfvk1 = lc. wallet . keys ( ) . read ( ) . await . get_all_extfvks ( ) [ 0 ] . clone ( ) ;
406+ let value = 100_000 ;
407+ let ( _nf, _tx, _height) = fcbl. add_tx_paying ( & extfvk1, value) ;
408+ mine_pending_blocks ( & mut fcbl, & data, & lc) . await ;
409+ mine_random_blocks ( & mut fcbl, & data, & lc, 5 ) . await ;
410+
411+ // 3. send a txn to multiple addresses
412+ let tos = vec ! [
413+ ( EXT_ZADDR , 1 , Some ( "ext1-1" . to_string( ) ) ) ,
414+ ( EXT_ZADDR , 2 , Some ( "ext1-2" . to_string( ) ) ) ,
415+ ( EXT_ZADDR2 , 20 , Some ( "ext2-20" . to_string( ) ) ) ,
416+ ] ;
417+ let sent_txid = lc. test_do_send ( tos. clone ( ) ) . await . unwrap ( ) ;
418+ fcbl. add_pending_sends ( & data) . await ;
419+ mine_pending_blocks ( & mut fcbl, & data, & lc) . await ;
420+
421+ // 4. Check the outgoing txn list
422+ let list = lc. do_list_transactions ( false ) . await ;
423+
424+ assert_eq ! ( list[ 1 ] [ "block_height" ] . as_u64( ) . unwrap( ) , 107 ) ;
425+ assert_eq ! ( list[ 1 ] [ "txid" ] , sent_txid) ;
426+ assert_eq ! (
427+ list[ 1 ] [ "amount" ] . as_i64( ) . unwrap( ) ,
428+ -1000 - ( tos. iter( ) . map( |( _, a, _) | * a) . sum:: <u64 >( ) as i64 )
429+ ) ;
430+
431+ for ( addr, amt, memo) in & tos {
432+ // Find the correct value, since the outgoing metadata can be shuffled
433+ let jv = list[ 1 ] [ "outgoing_metadata" ]
434+ . members ( )
435+ . find ( |j| j[ "value" ] . as_u64 ( ) . unwrap ( ) == * amt)
436+ . unwrap ( ) ;
437+ assert_eq ! ( jv[ "memo" ] , * memo. as_ref( ) . unwrap( ) ) ;
438+ assert_eq ! ( jv[ "address" ] , addr. to_string( ) ) ;
439+ }
371440
372441 // Shutdown everything cleanly
373442 stop_tx. send ( true ) . unwrap ( ) ;
374443 h1. await . unwrap ( ) ;
375444}
376445
377446const EXT_ZADDR : & str = "zs1va5902apnzlhdu0pw9r9q7ca8s4vnsrp2alr6xndt69jnepn2v2qrj9vg3wfcnjyks5pg65g9dc" ;
447+ const EXT_ZADDR2 : & str = "zs1fxgluwznkzm52ux7jkf4st5znwzqay8zyz4cydnyegt2rh9uhr9458z0nk62fdsssx0cqhy6lyv" ;
0 commit comments