From 25d6510c3b188a04310c3d4805c60fb0aed17a4d Mon Sep 17 00:00:00 2001 From: Hazel OHearn Date: Fri, 24 Jan 2025 17:47:42 -0400 Subject: [PATCH 1/5] format --- zainod/zindexer.toml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/zainod/zindexer.toml b/zainod/zindexer.toml index dbc05c0..4785c66 100644 --- a/zainod/zindexer.toml +++ b/zainod/zindexer.toml @@ -23,7 +23,7 @@ idle_worker_pool_size = 4 # Capacity of the Dashmaps used for the Mempool. # Also use by the BlockCache::NonFinalisedState when using the FetchService. -# +# # None by default. # map_capacity = None @@ -35,30 +35,30 @@ idle_worker_pool_size = 4 # # None by default. # map_shard_amount = None - + # Block Cache database file path. # # This is Zaino's Compact Block Cache db if using the FetchService or Zebra's RocksDB if using the StateService. # # None by default, this defaults to `$HOME/.cache/zaino/` # db_path = None - + # Block Cache database maximum size in gb. # # Only used by the FetchService. -# +# # None by default # db_size = None - + # Network chain type (Mainnet, Testnet, Regtest). network = "Testnet" - + # Disables internal sync and stops zaino waiting on server to sync with p2p network. # Useful for testing. no_sync = false - -# Disables the FinalisedState in the BlockCache -# + +# Disables the FinalisedState in the BlockCache +# # Only used by the FetchServic. # Used for testing. no_db = false @@ -69,4 +69,4 @@ no_db = false # # NOTE: Currently unimplemented as will require either a Tonic backend or a JsonRPC server. # no_state = false - + From 732327adc20962f404a711e37efee5a02f83d5dc Mon Sep 17 00:00:00 2001 From: Hazel OHearn Date: Wed, 22 Jan 2025 15:27:49 -0400 Subject: [PATCH 2/5] enable compiler optimization in tests --- Cargo.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 57debe4..0ecf934 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -78,3 +78,7 @@ jsonrpc-core = "18.0" jsonrpsee-types = "0.24" dashmap = "6.1" lmdb = "0.8" + +[profile.test] +opt-level = 3 +debug = true From d4d139475191ca9bde4cb2ca4b1230042398b968 Mon Sep 17 00:00:00 2001 From: Hazel OHearn Date: Wed, 22 Jan 2025 17:30:00 -0400 Subject: [PATCH 3/5] helperize test create fetch_service and subscriber --- zaino-state/src/fetch.rs | 1041 +++++--------------------------------- 1 file changed, 133 insertions(+), 908 deletions(-) diff --git a/zaino-state/src/fetch.rs b/zaino-state/src/fetch.rs index 28b6bb8..2939bca 100644 --- a/zaino-state/src/fetch.rs +++ b/zaino-state/src/fetch.rs @@ -1849,11 +1849,25 @@ mod tests { launch_fetch_service("zebrad", ZEBRAD_CHAIN_CACHE_BIN.clone()).await; } - async fn launch_fetch_service(validator: &str, chain_cache: Option) { - let mut test_manager = - TestManager::launch(validator, None, chain_cache, false, true, true, false) - .await - .unwrap(); + async fn create_test_manager_and_fetch_service( + validator: &str, + chain_cache: Option, + enable_zaino: bool, + zaino_no_sync: bool, + zaino_no_db: bool, + enable_clients: bool, + ) -> (TestManager, FetchService, FetchServiceSubscriber) { + let test_manager = TestManager::launch( + validator, + None, + chain_cache, + enable_zaino, + zaino_no_sync, + zaino_no_db, + enable_clients, + ) + .await + .unwrap(); let fetch_service = FetchService::spawn( FetchServiceConfig::new( @@ -1881,14 +1895,23 @@ mod tests { AtomicStatus::new(StatusType::Spawning.into()), ) .await - .unwrap() - .get_subscriber() - .inner(); + .unwrap(); + let subscriber = fetch_service.get_subscriber().inner(); + (test_manager, fetch_service, subscriber) + } - assert_eq!(fetch_service.status(), StatusType::Ready); - dbg!(fetch_service.data.clone()); - dbg!(fetch_service.get_info().await.unwrap()); - dbg!(fetch_service.get_blockchain_info().await.unwrap().blocks()); + async fn launch_fetch_service(validator: &str, chain_cache: Option) { + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, chain_cache, false, true, true, false) + .await; + assert_eq!(fetch_service_subscriber.status(), StatusType::Ready); + dbg!(fetch_service_subscriber.data.clone()); + dbg!(fetch_service_subscriber.get_info().await.unwrap()); + dbg!(fetch_service_subscriber + .get_blockchain_info() + .await + .unwrap() + .blocks()); test_manager.close().await; } @@ -1899,9 +1922,8 @@ mod tests { } async fn fetch_service_get_address_balance(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let clients = test_manager .clients @@ -1920,37 +1942,7 @@ mod tests { clients.recipient.do_sync(true).await.unwrap(); let recipient_balance = clients.recipient.do_balance().await; - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); - - let fetch_service_balance = fetch_service + let fetch_service_balance = fetch_service_subscriber .z_get_address_balance(AddressStrings::new_valid(vec![recipient_address]).unwrap()) .await .unwrap(); @@ -1973,41 +1965,10 @@ mod tests { } async fn fetch_service_get_block_raw(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, false, true, true, false) - .await - .unwrap(); - - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, false, true, true, false).await; - dbg!(fetch_service + dbg!(fetch_service_subscriber .z_get_block("1".to_string(), Some(0)) .await .unwrap()); @@ -2021,41 +1982,10 @@ mod tests { } async fn fetch_service_get_block_object(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, false, true, true, false) - .await - .unwrap(); - - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, false, true, true, false).await; - dbg!(fetch_service + dbg!(fetch_service_subscriber .z_get_block("1".to_string(), Some(1)) .await .unwrap()); @@ -2069,9 +1999,8 @@ mod tests { } async fn fetch_service_get_raw_mempool(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let clients = test_manager .clients .as_ref() @@ -2080,35 +2009,6 @@ mod tests { .parse::() .expect("Failed to convert URL to URI"); - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap(); - let fetch_service_subscriber = fetch_service.get_subscriber().inner(); - let json_service = JsonRpcConnector::new( zebra_uri, Some("xxxxxx".to_string()), @@ -2159,9 +2059,8 @@ mod tests { } async fn fetch_service_z_get_treestate(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let clients = test_manager .clients @@ -2182,37 +2081,7 @@ mod tests { test_manager.local_net.generate_blocks(1).await.unwrap(); - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); - - dbg!(fetch_service + dbg!(fetch_service_subscriber .z_get_treestate("2".to_string()) .await .unwrap()); @@ -2226,9 +2095,8 @@ mod tests { } async fn fetch_service_z_get_subtrees_by_index(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let clients = test_manager .clients @@ -2249,37 +2117,7 @@ mod tests { test_manager.local_net.generate_blocks(1).await.unwrap(); - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); - - dbg!(fetch_service + dbg!(fetch_service_subscriber .z_get_subtrees_by_index("orchard".to_string(), NoteCommitmentSubtreeIndex(0), None) .await .unwrap()); @@ -2293,9 +2131,8 @@ mod tests { } async fn fetch_service_get_raw_transaction(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let clients = test_manager .clients @@ -2316,37 +2153,7 @@ mod tests { test_manager.local_net.generate_blocks(1).await.unwrap(); - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); - - dbg!(fetch_service + dbg!(fetch_service_subscriber .get_raw_transaction(tx.first().to_string(), Some(1)) .await .unwrap()); @@ -2360,9 +2167,8 @@ mod tests { } async fn fetch_service_get_address_tx_ids(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let clients = test_manager .clients @@ -2379,37 +2185,7 @@ mod tests { .unwrap(); test_manager.local_net.generate_blocks(1).await.unwrap(); - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); - - let fetch_service_txids = fetch_service + let fetch_service_txids = fetch_service_subscriber .get_address_tx_ids(GetAddressTxIdsRequest::from_parts( vec![recipient_address], 0, @@ -2431,9 +2207,8 @@ mod tests { } async fn fetch_service_get_address_utxos(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let clients = test_manager .clients @@ -2451,37 +2226,7 @@ mod tests { test_manager.local_net.generate_blocks(1).await.unwrap(); clients.faucet.do_sync(true).await.unwrap(); - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); - - let fetch_service_utxos = fetch_service + let fetch_service_utxos = fetch_service_subscriber .z_get_address_utxos(AddressStrings::new_valid(vec![recipient_address]).unwrap()) .await .unwrap(); @@ -2500,39 +2245,8 @@ mod tests { } async fn fetch_service_get_latest_block(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); - - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap(); - - let fetch_service_subscriber = fetch_service.get_subscriber().inner(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let fetch_service_get_latest_block = dbg!(fetch_service_subscriber.get_latest_block().await.unwrap()); @@ -2548,47 +2262,18 @@ mod tests { } async fn fetch_service_get_block(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); - - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let block_id = BlockId { height: 1, hash: Vec::new(), }; - let fetch_service_get_block = - dbg!(fetch_service.get_block(block_id.clone()).await.unwrap()); + let fetch_service_get_block = dbg!(fetch_service_subscriber + .get_block(block_id.clone()) + .await + .unwrap()); assert_eq!(fetch_service_get_block.height, block_id.height); @@ -2601,46 +2286,15 @@ mod tests { } async fn fetch_service_get_block_nullifiers(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); - - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let block_id = BlockId { height: 1, hash: Vec::new(), }; - let fetch_service_get_block_nullifiers = dbg!(fetch_service + let fetch_service_get_block_nullifiers = dbg!(fetch_service_subscriber .get_block_nullifiers(block_id.clone()) .await .unwrap()); @@ -2656,41 +2310,10 @@ mod tests { } async fn fetch_service_get_block_range(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; test_manager.local_net.generate_blocks(10).await.unwrap(); - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); - let block_range = BlockRange { start: Some(BlockId { height: 1, @@ -2702,7 +2325,7 @@ mod tests { }), }; - let fetch_service_stream = fetch_service + let fetch_service_stream = fetch_service_subscriber .get_block_range(block_range.clone()) .await .unwrap(); @@ -2724,41 +2347,10 @@ mod tests { } async fn fetch_service_get_block_range_nullifiers(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; test_manager.local_net.generate_blocks(10).await.unwrap(); - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); - let block_range = BlockRange { start: Some(BlockId { height: 1, @@ -2770,7 +2362,7 @@ mod tests { }), }; - let fetch_service_stream = fetch_service + let fetch_service_stream = fetch_service_subscriber .get_block_range_nullifiers(block_range.clone()) .await .unwrap(); @@ -2792,45 +2384,14 @@ mod tests { } async fn fetch_service_get_transaction_mined(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let clients = test_manager .clients .as_ref() .expect("Clients are not initialized"); - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); - clients.faucet.do_sync(true).await.unwrap(); let tx = zingolib::testutils::lightclient::from_inputs::quick_send( @@ -2851,7 +2412,7 @@ mod tests { hash: tx.first().as_ref().to_vec(), }; - let fetch_service_get_transaction = dbg!(fetch_service + let fetch_service_get_transaction = dbg!(fetch_service_subscriber .get_transaction(tx_filter.clone()) .await .unwrap()); @@ -2867,45 +2428,14 @@ mod tests { } async fn fetch_service_get_transaction_mempool(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let clients = test_manager .clients .as_ref() .expect("Clients are not initialized"); - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); - clients.faucet.do_sync(true).await.unwrap(); let tx = zingolib::testutils::lightclient::from_inputs::quick_send( @@ -2925,7 +2455,7 @@ mod tests { hash: tx.first().as_ref().to_vec(), }; - let fetch_service_get_transaction = dbg!(fetch_service + let fetch_service_get_transaction = dbg!(fetch_service_subscriber .get_transaction(tx_filter.clone()) .await .unwrap()); @@ -2941,9 +2471,8 @@ mod tests { } async fn fetch_service_get_taddress_txids(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let clients = test_manager .clients @@ -2951,36 +2480,6 @@ mod tests { .expect("Clients are not initialized"); let recipient_address = clients.get_recipient_address("transparent").await; - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); - clients.faucet.do_sync(true).await.unwrap(); let tx = zingolib::testutils::lightclient::from_inputs::quick_send( &clients.faucet, @@ -3004,7 +2503,7 @@ mod tests { }), }; - let fetch_service_stream = fetch_service + let fetch_service_stream = fetch_service_subscriber .get_taddress_txids(block_filter.clone()) .await .unwrap(); @@ -3015,57 +2514,26 @@ mod tests { .filter_map(|result| result.ok()) .collect(); - dbg!(tx); - dbg!(&fetch_tx); - - test_manager.close().await; - } - - #[tokio::test] - async fn fetch_service_get_taddress_balance_zcashd() { - fetch_service_get_taddress_balance("zcashd").await; - } - - async fn fetch_service_get_taddress_balance(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); - - let clients = test_manager - .clients - .as_ref() - .expect("Clients are not initialized"); - let recipient_address = clients.get_recipient_address("transparent").await; - - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); + dbg!(tx); + dbg!(&fetch_tx); + + test_manager.close().await; + } + + #[tokio::test] + async fn fetch_service_get_taddress_balance_zcashd() { + fetch_service_get_taddress_balance("zcashd").await; + } + + async fn fetch_service_get_taddress_balance(validator: &str) { + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; + + let clients = test_manager + .clients + .as_ref() + .expect("Clients are not initialized"); + let recipient_address = clients.get_recipient_address("transparent").await; clients.faucet.do_sync(true).await.unwrap(); zingolib::testutils::lightclient::from_inputs::quick_send( @@ -3082,7 +2550,7 @@ mod tests { addresses: vec![recipient_address], }; - let fetch_service_balance = fetch_service + let fetch_service_balance = fetch_service_subscriber .get_taddress_balance(address_list.clone()) .await .unwrap(); @@ -3102,43 +2570,13 @@ mod tests { } async fn fetch_service_get_mempool_tx(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let clients = test_manager .clients .as_ref() .expect("Clients are not initialized"); - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap(); - let fetch_service_subscriber = fetch_service.get_subscriber().inner(); - test_manager.local_net.generate_blocks(1).await.unwrap(); clients.faucet.do_sync(true).await.unwrap(); @@ -3221,44 +2659,14 @@ mod tests { } async fn fetch_service_get_mempool_stream(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let clients = test_manager .clients .as_ref() .expect("Clients are not initialized"); - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap(); - let fetch_service_subscriber = fetch_service.get_subscriber().inner(); - test_manager.local_net.generate_blocks(1).await.unwrap(); clients.faucet.do_sync(true).await.unwrap(); @@ -3313,46 +2721,15 @@ mod tests { } async fn fetch_service_get_tree_state(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); - - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let block_id = BlockId { height: 1, hash: Vec::new(), }; - let fetch_service_get_tree_state = dbg!(fetch_service + let fetch_service_get_tree_state = dbg!(fetch_service_subscriber .get_tree_state(block_id.clone()) .await .unwrap()); @@ -3368,41 +2745,13 @@ mod tests { } async fn fetch_service_get_latest_tree_state(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); - - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; - dbg!(fetch_service.get_latest_tree_state().await.unwrap()); + dbg!(fetch_service_subscriber + .get_latest_tree_state() + .await + .unwrap()); test_manager.close().await; } @@ -3413,39 +2762,8 @@ mod tests { } async fn fetch_service_get_subtree_roots(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); - - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let subtree_roots_arg = GetSubtreeRootsArg { start_index: 0, @@ -3453,7 +2771,7 @@ mod tests { max_entries: 0, }; - let fetch_service_stream = fetch_service + let fetch_service_stream = fetch_service_subscriber .get_subtree_roots(subtree_roots_arg.clone()) .await .unwrap(); @@ -3475,9 +2793,8 @@ mod tests { } async fn fetch_service_get_taddress_utxos(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let clients = test_manager .clients @@ -3485,36 +2802,6 @@ mod tests { .expect("Clients are not initialized"); let recipient_address = clients.get_recipient_address("transparent").await; - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); - clients.faucet.do_sync(true).await.unwrap(); let tx = zingolib::testutils::lightclient::from_inputs::quick_send( &clients.faucet, @@ -3530,7 +2817,7 @@ mod tests { max_entries: 0, }; - let fetch_service_get_taddress_utxos = fetch_service + let fetch_service_get_taddress_utxos = fetch_service_subscriber .get_address_utxos(utxos_arg.clone()) .await .unwrap(); @@ -3547,9 +2834,8 @@ mod tests { } async fn fetch_service_get_taddress_utxos_stream(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; let clients = test_manager .clients @@ -3557,36 +2843,6 @@ mod tests { .expect("Clients are not initialized"); let recipient_address = clients.get_recipient_address("transparent").await; - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); - clients.faucet.do_sync(true).await.unwrap(); zingolib::testutils::lightclient::from_inputs::quick_send( &clients.faucet, @@ -3602,7 +2858,7 @@ mod tests { max_entries: 0, }; - let fetch_service_stream = fetch_service + let fetch_service_stream = fetch_service_subscriber .get_address_utxos_stream(utxos_arg.clone()) .await .unwrap(); @@ -3624,41 +2880,10 @@ mod tests { } async fn fetch_service_get_lightd_info(validator: &str) { - let mut test_manager = TestManager::launch(validator, None, None, true, true, true, true) - .await - .unwrap(); - - let fetch_service = FetchService::spawn( - FetchServiceConfig::new( - SocketAddr::new( - std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), - test_manager.zebrad_rpc_listen_port, - ), - None, - None, - None, - None, - None, - None, - test_manager - .local_net - .data_dir() - .path() - .to_path_buf() - .join("zaino"), - None, - Network::new_regtest(Some(1), Some(1)), - true, - true, - ), - AtomicStatus::new(StatusType::Spawning.into()), - ) - .await - .unwrap() - .get_subscriber() - .inner(); + let (mut test_manager, _fetch_service, fetch_service_subscriber) = + create_test_manager_and_fetch_service(validator, None, true, true, true, true).await; - dbg!(fetch_service.get_lightd_info().await.unwrap()); + dbg!(fetch_service_subscriber.get_lightd_info().await.unwrap()); test_manager.close().await; } From e4d7fa00572738f335af50069f116a94a0535d64 Mon Sep 17 00:00:00 2001 From: zancas Date: Fri, 24 Jan 2025 14:56:52 -0700 Subject: [PATCH 4/5] submit to clippy --- zaino-state/src/config.rs | 1 + zaino-state/src/local_cache/non_finalised_state.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/zaino-state/src/config.rs b/zaino-state/src/config.rs index 5b560d9..b35ed6d 100644 --- a/zaino-state/src/config.rs +++ b/zaino-state/src/config.rs @@ -80,6 +80,7 @@ pub struct FetchServiceConfig { impl FetchServiceConfig { /// Returns a new instance of [`FetchServiceConfig`]. + #[allow(clippy::too_many_arguments)] pub fn new( validator_rpc_address: std::net::SocketAddr, validator_rpc_user: Option, diff --git a/zaino-state/src/local_cache/non_finalised_state.rs b/zaino-state/src/local_cache/non_finalised_state.rs index 5feef89..26e4a66 100644 --- a/zaino-state/src/local_cache/non_finalised_state.rs +++ b/zaino-state/src/local_cache/non_finalised_state.rs @@ -439,7 +439,7 @@ impl NonFinalisedStateSubscriber { Ok(height) } - /// + /// Predicate checks for presence of Hash.. or Height? pub async fn contains_hash_or_height(&self, hash_or_height: HashOrHeight) -> bool { match hash_or_height { HashOrHeight::Height(height) => self.heights_to_hashes.contains_key(&height), From e4a168c538c08b75d9a40bea00a3ebaf67d061c2 Mon Sep 17 00:00:00 2001 From: zancas Date: Fri, 24 Jan 2025 15:07:15 -0700 Subject: [PATCH 5/5] finish the tidy --- zaino-testutils/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/zaino-testutils/src/lib.rs b/zaino-testutils/src/lib.rs index 3032bdc..6e010eb 100644 --- a/zaino-testutils/src/lib.rs +++ b/zaino-testutils/src/lib.rs @@ -92,6 +92,10 @@ pub enum ValidatorConfig { } /// Available zcash-local-net configurations. +#[allow( + clippy::large_enum_variant, + reason = "Maybe this issue: https://github.com/rust-lang/rust-clippy/issues/9798" +)] pub enum LocalNet { /// Zcash-local-net backed by Zcashd. Zcashd(