diff --git a/integration-tests/tests/integrations.rs b/integration-tests/tests/integrations.rs index 81e653a..33c34dd 100644 --- a/integration-tests/tests/integrations.rs +++ b/integration-tests/tests/integrations.rs @@ -4,9 +4,9 @@ #![forbid(unsafe_code)] use std::sync::{atomic::AtomicBool, Arc}; -use zingoproxy_testutils::{drop_test_manager, TestManager}; - use zingo_netutils::GrpcConnector; +use zingolib::lightclient::LightClient; +use zingoproxy_testutils::{drop_test_manager, TestManager}; mod wallet_basic { use super::*; @@ -402,9 +402,56 @@ mod wallet_basic { .await; } - // TODO: Add test for get_mempool_stream: lightclient::start_mempool_monitor. - // #[tokio::test] - // async fn monitor_mempool() {} + #[tokio::test] + async fn monitor_unverified_mempool() { + let online = Arc::new(AtomicBool::new(true)); + let (test_manager, regtest_handler, _proxy_handler) = + TestManager::launch(online.clone()).await; + let zingo_client = test_manager.build_lightclient().await; + + test_manager.regtest_manager.generate_n_blocks(1).unwrap(); + zingo_client.do_sync(false).await.unwrap(); + zingo_client + .do_send(vec![( + &zingolib::get_base_address!(zingo_client, "sapling"), + 250_000, + None, + )]) + .await + .unwrap(); + + let zingo_client_saved = zingo_client.export_save_buffer_async().await.unwrap(); + let zingo_client_loaded = std::sync::Arc::new( + LightClient::read_wallet_from_buffer_async( + zingo_client.config(), + &zingo_client_saved[..], + ) + .await + .unwrap(), + ); + LightClient::start_mempool_monitor(zingo_client_loaded.clone()); + // This seems to be long enough for the mempool monitor to kick in. + // One second is insufficient. Even if this fails, this can only ever be + // a false negative, giving us a balance of 100_000. Still, could be improved. + tokio::time::sleep(std::time::Duration::from_secs(5)).await; + + let balance = zingo_client.do_balance().await; + println!("@zingoproxytest: zingo_client balance: \n{:#?}.", balance); + assert_eq!(balance.unverified_sapling_balance.unwrap(), 250_000); + + test_manager.regtest_manager.generate_n_blocks(1).unwrap(); + zingo_client.do_sync(false).await.unwrap(); + let balance = zingo_client.do_balance().await; + println!("@zingoproxytest: zingo_client balance: \n{:#?}.", balance); + assert_eq!(balance.verified_sapling_balance.unwrap(), 250_000); + + drop_test_manager( + Some(test_manager.temp_conf_dir.path().to_path_buf()), + regtest_handler, + online, + ) + .await; + } } mod nym {