From 59770968aedf3f512dcd514c45ee69c654ede927 Mon Sep 17 00:00:00 2001 From: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> Date: Thu, 22 Aug 2024 09:37:25 +0200 Subject: [PATCH] feat(iota): add IotaCommand::Start test and doc comment (#1546) * feat(iota): add IotaCommand::Start test and doc comment * dprint fmt * Update crates/iota/tests/cli_tests.rs Co-authored-by: DaughterOfMars * fmt and use result --------- Co-authored-by: DaughterOfMars Co-authored-by: Thibault Martinez --- crates/iota/src/iota_commands.rs | 2 ++ crates/iota/tests/cli_tests.rs | 47 ++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/crates/iota/src/iota_commands.rs b/crates/iota/src/iota_commands.rs index b9e83cf078c..8d6c4be8c34 100644 --- a/crates/iota/src/iota_commands.rs +++ b/crates/iota/src/iota_commands.rs @@ -58,6 +58,8 @@ pub enum IotaCommand { /// We can use any config dir that is generated by `iota genesis`. #[clap(short, long)] config_dir: Option, + /// Sets the fullnode_count in the SwarmBuilder to 0, so the JSON RPC + /// port stays unused. #[clap(long = "no-full-node")] no_full_node: bool, }, diff --git a/crates/iota/tests/cli_tests.rs b/crates/iota/tests/cli_tests.rs index d22ada9be04..c24ab755557 100644 --- a/crates/iota/tests/cli_tests.rs +++ b/crates/iota/tests/cli_tests.rs @@ -125,6 +125,53 @@ async fn test_genesis() -> Result<(), anyhow::Error> { Ok(()) } +#[sim_test] +async fn test_start() -> Result<(), anyhow::Error> { + let temp_dir = tempfile::tempdir()?; + let working_dir = temp_dir.path(); + + if let Ok(res) = tokio::time::timeout( + Duration::from_secs(10), + IotaCommand::Start { + config_dir: Some(working_dir.to_path_buf()), + no_full_node: false, + } + .execute(), + ) + .await + { + res.unwrap(); + }; + + // Get all the new file names + let files = read_dir(working_dir)? + .flat_map(|r| r.map(|file| file.file_name().to_str().unwrap().to_owned())) + .collect::>(); + assert_eq!(12, files.len()); + assert!(files.contains(&IOTA_CLIENT_CONFIG.to_string())); + assert!(files.contains(&IOTA_NETWORK_CONFIG.to_string())); + assert!(files.contains(&IOTA_FULLNODE_CONFIG.to_string())); + assert!(files.contains(&IOTA_GENESIS_FILENAME.to_string())); + assert!(files.contains(&IOTA_KEYSTORE_FILENAME.to_string())); + assert!(files.contains(&IOTA_KEYSTORE_ALIASES_FILENAME.to_string())); + + // Check network config + let network_conf = + PersistedConfig::::read(&working_dir.join(IOTA_NETWORK_CONFIG))?; + assert_eq!(4, network_conf.validator_configs().len()); + + // Check wallet config + let wallet_conf = + PersistedConfig::::read(&working_dir.join(IOTA_CLIENT_CONFIG))?; + + assert!(!wallet_conf.envs.is_empty()); + + assert_eq!(5, wallet_conf.keystore.addresses().len()); + + temp_dir.close()?; + Ok(()) +} + #[tokio::test] async fn test_addresses_command() -> Result<(), anyhow::Error> { let test_cluster = TestClusterBuilder::new().build().await;