From ca1cd92a10b0f109e5e94b60804128725f7894e9 Mon Sep 17 00:00:00 2001 From: Alejandro Martinez <11448715+al3mart@users.noreply.github.com> Date: Fri, 3 Jan 2025 23:16:20 +0100 Subject: [PATCH] fix: check_contracts_node handles skip_confirm (#396) * fix: check_contracts_node_handles_skip_confirm * style: remove unused import --- crates/pop-cli/src/common/contracts.rs | 28 +++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/crates/pop-cli/src/common/contracts.rs b/crates/pop-cli/src/common/contracts.rs index a3b8f878..09d3ee5b 100644 --- a/crates/pop-cli/src/common/contracts.rs +++ b/crates/pop-cli/src/common/contracts.rs @@ -26,11 +26,14 @@ pub async fn check_contracts_node_and_prompt( let mut node_path = binary.path(); if !binary.exists() { cli.warning("⚠️ The substrate-contracts-node binary is not found.")?; - if cli - .confirm("📦 Would you like to source it automatically now?") - .initial_value(true) - .interact()? - { + let latest = if !skip_confirm { + cli.confirm("📦 Would you like to source it automatically now?") + .initial_value(true) + .interact()? + } else { + true + }; + if latest { let spinner = spinner(); spinner.start("📦 Sourcing substrate-contracts-node..."); @@ -174,6 +177,21 @@ mod tests { cli.verify() } + #[tokio::test] + async fn check_contracts_node_and_prompt_handles_skip_confirm() -> anyhow::Result<()> { + let cache_path = tempfile::tempdir().expect("Could create temp dir"); + let mut cli = + MockCli::new().expect_warning("⚠️ The substrate-contracts-node binary is not found."); + + let node_path = check_contracts_node_and_prompt(&mut cli, cache_path.path(), true).await?; + // Binary path is at least equal to the cache path + "substrate-contracts-node". + assert!(node_path + .to_str() + .unwrap() + .starts_with(&cache_path.path().join("substrate-contracts-node").to_str().unwrap())); + cli.verify() + } + #[tokio::test] async fn node_is_terminated() -> anyhow::Result<()> { let cache = tempfile::tempdir().expect("Could not create temp dir");