diff --git a/crates/pop-cli/src/commands/build/spec.rs b/crates/pop-cli/src/commands/build/spec.rs index a19c0e57..0e179bb6 100644 --- a/crates/pop-cli/src/commands/build/spec.rs +++ b/crates/pop-cli/src/commands/build/spec.rs @@ -423,7 +423,7 @@ async fn guide_user_to_generate_spec( let default_bootnode = match chain_type { ChainType::Development => true, _ => cli - .confirm("Would you like to use local host as a bootnode ?".to_string()) + .confirm("Would you like to use local host as a bootnode?".to_string()) .interact()?, }; @@ -441,20 +441,20 @@ async fn guide_user_to_generate_spec( // Prompt for genesis state let genesis_state = cli - .confirm("Should the genesis state file be generated ?".to_string()) + .confirm("Should the genesis state file be generated?".to_string()) .initial_value(true) .interact()?; // Prompt for genesis code let genesis_code = cli - .confirm("Should the genesis code file be generated ?".to_string()) + .confirm("Should the genesis code file be generated?".to_string()) .initial_value(true) .interact()?; // Only check user to check their profile selection if a live spec is being built on debug mode. let profile = if !args.release && matches!(chain_type, ChainType::Live) { cli.confirm( - "Using Debug profile to build a Live specification. Should Release be used instead ?", + "Using Debug profile to build a Live specification. Should Release be used instead?", ) .initial_value(true) .interact()? @@ -483,11 +483,11 @@ mod tests { use std::path::PathBuf; #[tokio::test] - async fn guide_user_to_generate_spec_works() -> anyhow::Result<()> { + async fn guide_user_to_generate_spec_development_works() -> anyhow::Result<()> { let mut cli = MockCli::new() .expect_intro("Generate your chain spec") - .expect_confirm("Should the genesis code file be generated ?", true) - .expect_confirm("Should the genesis state file be generated ?", true) + .expect_confirm("Should the genesis code file be generated?", true) + .expect_confirm("Should the genesis state file be generated?", true) .expect_input( "Enter the protocol ID that will identify your network:", "protocol".into(), @@ -565,8 +565,121 @@ mod tests { assert!(user_prompt.genesis_state); assert!(user_prompt.genesis_code); - cli.verify()?; - Ok(()) + cli.verify() + } + + #[tokio::test] + async fn guide_user_to_generate_spec_live_works() -> anyhow::Result<()> { + let mut cli = MockCli::new() + .expect_intro("Generate your chain spec") + .expect_confirm("Using Debug profile to build a Live specification. Should Release be used instead?", true) // Because args.release is false + .expect_confirm("Should the genesis code file be generated?", true) + .expect_confirm("Should the genesis state file be generated?", true) + .expect_input( + "Enter the protocol ID that will identify your network:", + "protocol".into(), + ) + .expect_select::( + "Choose the relay chain your chain will be connecting to: ", + Some(false), + true, + Some(vec![ + ( + RelayChain::Paseo.get_message().unwrap().into(), + RelayChain::Paseo.get_detailed_message().unwrap().into(), + ), + ( + RelayChain::Westend.get_message().unwrap().into(), + RelayChain::Westend.get_detailed_message().unwrap().into(), + ), + ( + RelayChain::Kusama.get_message().unwrap().into(), + RelayChain::Kusama.get_detailed_message().unwrap().into(), + ), + ( + RelayChain::Polkadot.get_message().unwrap().into(), + RelayChain::Polkadot.get_detailed_message().unwrap().into(), + ), + + ]), + 3, // "Polkadot Local" + ) + .expect_select::( + "Choose the chain type: ", + Some(false), + true, + Some(vec![ + ( + ChainType::Development.get_message().unwrap().into(), + ChainType::Development.get_detailed_message().unwrap().into(), + ), + (ChainType::Local.get_message().unwrap().into(), ChainType::Local.get_detailed_message().unwrap().into()), + (ChainType::Live.get_message().unwrap().into(), ChainType::Live.get_detailed_message().unwrap().into()), + ]), + 3, // "Live" + ) + .expect_confirm("Would you like to use local host as a bootnode?", false) + .expect_input( + "What parachain ID should be used?", + "2002".into(), + ) + .expect_input( + "Name of the plain chain spec file. If a path is given, the necessary directories will be created:", + "./my-chain-spec.json".into(), + ); + + let user_prompt = guide_user_to_generate_spec( + BuildSpecCommand { + output_file: None, + release: false, + id: None, + default_bootnode: true, + chain_type: None, + relay: None, + protocol_id: None, + genesis_state: true, + genesis_code: true, + }, + &mut cli, + ) + .await?; + assert_eq!(user_prompt.output_file, Some(PathBuf::from("./my-chain-spec.json"))); + assert_eq!(user_prompt.id, Some(2002)); + assert!(user_prompt.release); + assert!(!user_prompt.default_bootnode); + assert_eq!(user_prompt.chain_type, Some(ChainType::Live)); + assert_eq!(user_prompt.relay, Some(RelayChain::Polkadot)); + assert_eq!(user_prompt.protocol_id, Some("protocol".into())); + assert!(user_prompt.genesis_state); + assert!(user_prompt.genesis_code); + + cli.verify() + } + + #[tokio::test] + async fn build_fails_no_parachain() -> anyhow::Result<()> { + let mut cli = MockCli::new() + .expect_intro(format!("Building your chain spec")) + .expect_warning( + "NOTE: this command defaults to DEBUG builds for development chain types. Please use `--release` (or simply `-r` for a release build...)", + ); + assert!(matches!( + BuildSpecCommand { + output_file: None, + release: false, + id: Some(2002), + default_bootnode: true, + chain_type: None, + relay: None, + protocol_id: None, + genesis_state: true, + genesis_code: true + } + .build(&mut cli), + anyhow::Result::Err(message) if message.to_string().contains("Failed to get manifest path:"), + )); + + cli.verify() } #[tokio::test] @@ -592,7 +705,6 @@ mod tests { "spec" ); - cli.verify()?; - Ok(()) + cli.verify() } } diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index f6b874fc..37826b41 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -342,89 +342,65 @@ async fn run_external_script(script_url: &str) -> anyhow::Result<()> { mod tests { use super::*; use crate::cli::MockCli; - use anyhow::Ok; #[tokio::test] async fn intro_works() -> anyhow::Result<()> { let mut cli = MockCli::new().expect_intro("Install dependencies for development"); - assert!(matches!(Command { cli: &mut cli, args: InstallArgs { skip_confirm: false } } .execute() .await,anyhow::Result::Err(message) if message.to_string() == "🚫 You have cancelled the installation process." )); - - cli.verify()?; - Ok(()) + cli.verify() } - #[tokio::test] async fn install_mac_works() -> anyhow::Result<()> { let mut cli = MockCli::new().expect_info("More information about the packages to be installed here: https://docs.substrate.io/install/macos/").expect_confirm("📦 Do you want to proceed with the installation of the following packages: homebrew, protobuf, openssl, rustup and cmake ?", false); - assert!(matches!( install_mac(&mut Command { cli: &mut cli, args: InstallArgs { skip_confirm: false } }) .await, anyhow::Result::Err(message) if message.to_string() == "🚫 You have cancelled the installation process." )); - - cli.verify()?; - Ok(()) + cli.verify() } - #[tokio::test] async fn install_arch_works() -> anyhow::Result<()> { let mut cli = MockCli::new().expect_info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/").expect_confirm("📦 Do you want to proceed with the installation of the following packages: curl, git, clang, make, openssl and rustup ?", false); - assert!(matches!( install_arch(&mut Command { cli: &mut cli, args: InstallArgs { skip_confirm: false } }) .await, anyhow::Result::Err(message) if message.to_string() == "🚫 You have cancelled the installation process." )); - - cli.verify()?; - Ok(()) + cli.verify() } - #[tokio::test] async fn install_ubuntu_works() -> anyhow::Result<()> { let mut cli = MockCli::new().expect_info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/").expect_confirm("📦 Do you want to proceed with the installation of the following packages: git, clang, curl, libssl-dev, protobuf-compiler and rustup ?", false); - assert!(matches!( install_ubuntu(&mut Command { cli: &mut cli, args: InstallArgs { skip_confirm: false } }) .await, anyhow::Result::Err(message) if message.to_string() == "🚫 You have cancelled the installation process." )); - - cli.verify()?; - Ok(()) + cli.verify() } - #[tokio::test] async fn install_debian_works() -> anyhow::Result<()> { let mut cli = MockCli::new().expect_info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/").expect_confirm("📦 Do you want to proceed with the installation of the following packages: cmake, pkg-config, libssl-dev, git, gcc, build-essential, protobuf-compiler, clang, libclang-dev and rustup ?", false); - assert!(matches!( install_debian(&mut Command { cli: &mut cli, args: InstallArgs { skip_confirm: false } }) .await, anyhow::Result::Err(message) if message.to_string() == "🚫 You have cancelled the installation process." )); - - cli.verify()?; - Ok(()) + cli.verify() } - #[tokio::test] async fn install_redhat_works() -> anyhow::Result<()> { let mut cli = MockCli::new().expect_info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/").expect_confirm("📦 Do you want to proceed with the installation of the following packages: cmake, openssl-devel, git, protobuf, protobuf-compiler, clang, clang-devel and rustup ?", false); - assert!(matches!( install_redhat(&mut Command { cli: &mut cli, args: InstallArgs { skip_confirm: false } }) .await, anyhow::Result::Err(message) if message.to_string() == "🚫 You have cancelled the installation process." )); - - cli.verify()?; - Ok(()) + cli.verify() } #[tokio::test] async fn not_supported_message_works() -> anyhow::Result<()> { @@ -433,10 +409,7 @@ mod tests { .expect_warning( "⚠️ Please refer to https://docs.substrate.io/install/ for setup information.", ); - not_supported_message(&mut cli)?; - - cli.verify()?; - Ok(()) + cli.verify() } } diff --git a/crates/pop-cli/src/commands/new/contract.rs b/crates/pop-cli/src/commands/new/contract.rs index 45e352b3..be2d16de 100644 --- a/crates/pop-cli/src/commands/new/contract.rs +++ b/crates/pop-cli/src/commands/new/contract.rs @@ -286,8 +286,7 @@ mod tests { assert_eq!(user_input.contract_type, Some(ContractType::Erc)); assert_eq!(user_input.template, Some(ContractTemplate::ERC20)); - cli.verify()?; - Ok(()) + cli.verify() } #[test] @@ -318,8 +317,7 @@ mod tests { &ContractTemplate::ERC20, &mut cli, )?; - cli.verify()?; - Ok(()) + cli.verify() } #[test] diff --git a/crates/pop-cli/src/commands/new/pallet.rs b/crates/pop-cli/src/commands/new/pallet.rs index 8fcacf28..02796c55 100644 --- a/crates/pop-cli/src/commands/new/pallet.rs +++ b/crates/pop-cli/src/commands/new/pallet.rs @@ -228,8 +228,7 @@ mod tests { } .generate_pallet(&mut cli) .await?; - cli.verify()?; - Ok(()) + cli.verify() } #[tokio::test] async fn generate_advanced_pallet_works() -> anyhow::Result<()> { @@ -257,8 +256,7 @@ mod tests { } .generate_pallet(&mut cli) .await?; - cli.verify()?; - Ok(()) + cli.verify() } #[tokio::test] @@ -278,7 +276,6 @@ mod tests { } .generate_pallet(&mut cli) .await, anyhow::Result::Err(message) if message.to_string() == "Specify at least a config common type to use default config.")); - cli.verify()?; - Ok(()) + cli.verify() } } diff --git a/crates/pop-cli/src/commands/new/parachain.rs b/crates/pop-cli/src/commands/new/parachain.rs index 86a80788..b4d1ebf9 100644 --- a/crates/pop-cli/src/commands/new/parachain.rs +++ b/crates/pop-cli/src/commands/new/parachain.rs @@ -499,8 +499,7 @@ mod tests { assert_eq!(user_input.decimals, Some(6)); assert_eq!(user_input.initial_endowment, Some(DEFAULT_INITIAL_ENDOWMENT.into())); - cli.verify()?; - Ok(()) + cli.verify() } #[tokio::test] @@ -545,8 +544,7 @@ mod tests { &mut cli, ) .await?; - cli.verify()?; - Ok(()) + cli.verify() } #[test] diff --git a/crates/pop-cli/src/commands/up/contract.rs b/crates/pop-cli/src/commands/up/contract.rs index 5fcf0fc4..cbabf4e3 100644 --- a/crates/pop-cli/src/commands/up/contract.rs +++ b/crates/pop-cli/src/commands/up/contract.rs @@ -376,6 +376,36 @@ mod tests { }; use url::Url; + #[tokio::test] + async fn up_contract_dry_run_works() -> anyhow::Result<()> { + let temp_dir = generate_smart_contract_test_environment()?; + let mut current_dir = env::current_dir().expect("Failed to get current directory"); + current_dir.pop(); + mock_build_process( + temp_dir.path().join("testing"), + current_dir.join("pop-contracts/tests/files/testing.contract"), + current_dir.join("pop-contracts/tests/files/testing.json"), + )?; + // Upload only + UpContractCommand { + path: Some(temp_dir.path().join("testing")), + constructor: "new".to_string(), + args: vec!["false".to_string()].to_vec(), + value: "0".to_string(), + gas_limit: None, + proof_size: None, + salt: None, + url: Url::parse("wss://rpc2.paseo.popnetwork.xyz")?, + suri: "//Alice".to_string(), + dry_run: true, + upload_only: true, + skip_confirm: false, + } + .execute() + .await?; + Ok(()) + } + #[test] fn conversion_up_contract_command_to_up_opts_works() -> anyhow::Result<()> { let command = UpContractCommand { @@ -515,38 +545,6 @@ mod tests { cli.verify() } - #[tokio::test] - async fn up_contract_dry_run_works() -> anyhow::Result<()> { - let temp_dir = generate_smart_contract_test_environment()?; - let mut current_dir = env::current_dir().expect("Failed to get current directory"); - current_dir.pop(); - mock_build_process( - temp_dir.path().join("testing"), - current_dir.join("pop-contracts/tests/files/testing.contract"), - current_dir.join("pop-contracts/tests/files/testing.json"), - )?; - // Upload only - let mut command = UpContractCommand { - path: Some(temp_dir.path().join("testing")), - constructor: "new".to_string(), - args: vec!["false".to_string()].to_vec(), - value: "0".to_string(), - gas_limit: None, - proof_size: None, - salt: None, - url: Url::parse("wss://rpc2.paseo.popnetwork.xyz")?, - suri: "//Alice".to_string(), - dry_run: true, - upload_only: true, - skip_confirm: false, - }; - let mut cli = MockCli::new().expect_intro("Deploy a smart contract").expect_outro(COMPLETE); - let process = command.set_up_environment(&mut cli).await?; - UpContractCommand::finish_process(process, true, None, &mut cli)?; - - cli.verify() - } - #[test] fn has_contract_been_built_works() -> anyhow::Result<()> { let temp_dir = tempfile::tempdir()?; diff --git a/crates/pop-cli/src/commands/up/parachain.rs b/crates/pop-cli/src/commands/up/parachain.rs index 8b030494..6126aba0 100644 --- a/crates/pop-cli/src/commands/up/parachain.rs +++ b/crates/pop-cli/src/commands/up/parachain.rs @@ -406,7 +406,7 @@ impl Status for VerboseReporter { #[cfg(test)] mod tests { use cli::MockCli; - use std::io::Write; + use std::{io::Write, path::PathBuf}; use tempfile::Builder; use super::*; diff --git a/crates/pop-cli/src/common/helpers.rs b/crates/pop-cli/src/common/helpers.rs index 7b3807a1..63e27cfb 100644 --- a/crates/pop-cli/src/common/helpers.rs +++ b/crates/pop-cli/src/common/helpers.rs @@ -175,7 +175,6 @@ mod tests { ) )); - cli.verify()?; - Ok(()) + cli.verify() } }