@@ -13,10 +13,14 @@ use tokio::task::JoinHandle;
1313use tonic:: transport:: { Channel , Server } ;
1414use tonic:: Request ;
1515
16+ use zcash_client_backend:: address:: RecipientAddress ;
17+ use zcash_primitives:: consensus:: MAIN_NETWORK ;
1618use zcash_primitives:: memo:: Memo ;
19+ use zcash_primitives:: merkle_tree:: { CommitmentTree , IncrementalWitness } ;
1720use zcash_primitives:: note_encryption:: SaplingNoteEncryption ;
1821use zcash_primitives:: primitives:: { Note , Rseed , ValueCommitment } ;
1922use zcash_primitives:: redjubjub:: Signature ;
23+ use zcash_primitives:: sapling:: Node ;
2024use zcash_primitives:: transaction:: components:: { OutputDescription , GROTH_PROOF_SIZE } ;
2125use zcash_primitives:: transaction:: TransactionData ;
2226
@@ -144,7 +148,7 @@ async fn z_incoming_z_outgoing() {
144148 // 2. Send an incoming tx to fill the wallet
145149 let extfvk1 = lc. wallet . keys ( ) . read ( ) . await . get_all_extfvks ( ) [ 0 ] . clone ( ) ;
146150 let value = 100_000 ;
147- let ( _nf , tx, _height) = fcbl. add_tx_paying ( & extfvk1, value) ;
151+ let ( tx, _height, _ ) = fcbl. add_tx_paying ( & extfvk1, value) ;
148152 mine_pending_blocks ( & mut fcbl, & data, & lc) . await ;
149153
150154 assert_eq ! ( lc. wallet. last_scanned_height( ) . await , 101 ) ;
@@ -404,7 +408,7 @@ async fn z_incoming_multiz_outgoing() {
404408 // 2. Send an incoming tx to fill the wallet
405409 let extfvk1 = lc. wallet . keys ( ) . read ( ) . await . get_all_extfvks ( ) [ 0 ] . clone ( ) ;
406410 let value = 100_000 ;
407- let ( _nf , _tx, _height) = fcbl. add_tx_paying ( & extfvk1, value) ;
411+ let ( _tx, _height, _ ) = fcbl. add_tx_paying ( & extfvk1, value) ;
408412 mine_pending_blocks ( & mut fcbl, & data, & lc) . await ;
409413 mine_random_blocks ( & mut fcbl, & data, & lc, 5 ) . await ;
410414
@@ -443,5 +447,65 @@ async fn z_incoming_multiz_outgoing() {
443447 h1. await . unwrap ( ) ;
444448}
445449
450+ #[ tokio:: test]
451+ async fn z_to_z_scan_together ( ) {
452+ // Create an incoming tx, and then send that tx, and scan everything together, to make sure it works.
453+ let ( data, config, ready_rx, stop_tx, h1) = create_test_server ( ) . await ;
454+
455+ ready_rx. await . unwrap ( ) ;
456+
457+ let lc = LightClient :: test_new ( & config, None ) . await . unwrap ( ) ;
458+ let mut fcbl = FakeCompactBlockList :: new ( 0 ) ;
459+
460+ // 1. Start with 100 blocks that are unmined
461+ fcbl. add_blocks ( 100 ) ;
462+
463+ // 2. Send an incoming tx to fill the wallet
464+ let extfvk1 = lc. wallet . keys ( ) . read ( ) . await . get_all_extfvks ( ) [ 0 ] . clone ( ) ;
465+ let value = 100_000 ;
466+ let ( tx, _height, note) = fcbl. add_tx_paying ( & extfvk1, value) ;
467+
468+ // Calculate witness so we can get the nullifier without it getting mined
469+ let tree = fcbl
470+ . blocks
471+ . iter ( )
472+ . fold ( CommitmentTree :: < Node > :: empty ( ) , |mut tree, fcb| {
473+ for tx in & fcb. block . vtx {
474+ for co in & tx. outputs {
475+ tree. append ( Node :: new ( co. cmu ( ) . unwrap ( ) . into ( ) ) ) . unwrap ( ) ;
476+ }
477+ }
478+
479+ tree
480+ } ) ;
481+ let witness = IncrementalWitness :: from_tree ( & tree) ;
482+ let nf = note. nf ( & extfvk1. fvk . vk , witness. position ( ) as u64 ) ;
483+
484+ let pa = if let Some ( RecipientAddress :: Shielded ( pa) ) = RecipientAddress :: decode ( & MAIN_NETWORK , EXT_ZADDR ) {
485+ pa
486+ } else {
487+ panic ! ( "Couldn't parse address" )
488+ } ;
489+ let spent_tx = fcbl. add_tx_spending ( & nf, 100 , & extfvk1. fvk . ovk , & pa) ;
490+
491+ // Mine the blocks and sync the lightwallet
492+ mine_pending_blocks ( & mut fcbl, & data, & lc) . await ;
493+
494+ let list = lc. do_list_transactions ( false ) . await ;
495+
496+ assert_eq ! ( list[ 0 ] [ "block_height" ] . as_u64( ) . unwrap( ) , 101 ) ;
497+ assert_eq ! ( list[ 0 ] [ "txid" ] , tx. txid( ) . to_string( ) ) ;
498+
499+ assert_eq ! ( list[ 1 ] [ "block_height" ] . as_u64( ) . unwrap( ) , 102 ) ;
500+ assert_eq ! ( list[ 1 ] [ "txid" ] , spent_tx. txid( ) . to_string( ) ) ;
501+ assert_eq ! ( list[ 1 ] [ "amount" ] . as_i64( ) . unwrap( ) , -( value as i64 ) ) ;
502+ assert_eq ! ( list[ 1 ] [ "outgoing_metadata" ] [ 0 ] [ "address" ] , EXT_ZADDR . to_string( ) ) ;
503+ assert_eq ! ( list[ 1 ] [ "outgoing_metadata" ] [ 0 ] [ "value" ] . as_u64( ) . unwrap( ) , 100 ) ;
504+
505+ // Shutdown everything cleanly
506+ stop_tx. send ( true ) . unwrap ( ) ;
507+ h1. await . unwrap ( ) ;
508+ }
509+
446510const EXT_ZADDR : & str = "zs1va5902apnzlhdu0pw9r9q7ca8s4vnsrp2alr6xndt69jnepn2v2qrj9vg3wfcnjyks5pg65g9dc" ;
447511const EXT_ZADDR2 : & str = "zs1fxgluwznkzm52ux7jkf4st5znwzqay8zyz4cydnyegt2rh9uhr9458z0nk62fdsssx0cqhy6lyv" ;
0 commit comments