Repository: ChainSafe/forest (Rust)

Issue:
Avoid network access when testing `param-fetch`
**Issue summary**

Two tests in Forest verify the download location for proof-parameter files. Unfortunately, they work by actually downloading the proof files, which can be slow. An alternative would be to implement a `--dry-run` flag that prints out where the files would end up if they were downloaded.

Acceptance criteria:
- [x] The tests still verify that the download folder is correctly computed.
- [x] The tests do not require internet access.

**Other information and links**

Slow param-fetch tests:
- `test_download_location_of_proof_parameter_files_default`
- `test_download_location_of_proof_parameter_files_env`

<!-- Thank you 🙏 -->



Discussion:
`--dry-run` could just print out the folder structure and files to be downloaded, for example. 



Patch:
diff --git a/src/cli/cli/fetch_params_cmd.rs b/src/cli/cli/fetch_params_cmd.rs
index 66bbcd555ca6..436f1589a5ca 100644
--- a/src/cli/cli/fetch_params_cmd.rs
+++ b/src/cli/cli/fetch_params_cmd.rs
@@ -16,6 +16,9 @@ pub struct FetchCommands {
     /// Download only verification keys
     #[arg(short, long)]
     keys: bool,
+    /// Print out download location instead of downloading files
+    #[arg(short, long)]
+    dry_run: bool,
     /// Size in bytes
     params_size: Option<String>,
 }
@@ -36,7 +39,7 @@ impl FetchCommands {
             );
         };
 
-        get_params_default(&config.client.data_dir, sizes).await
+        get_params_default(&config.client.data_dir, sizes, self.dry_run).await
     }
 }
 
diff --git a/src/utils/proofs_api/paramfetch.rs b/src/utils/proofs_api/paramfetch.rs
index 734a813db488..0237f23b82cd 100644
--- a/src/utils/proofs_api/paramfetch.rs
+++ b/src/utils/proofs_api/paramfetch.rs
@@ -79,7 +79,7 @@ pub async fn ensure_params_downloaded() -> anyhow::Result<()> {
     if data_dir.is_empty() {
         anyhow::bail!("Proof parameter data dir is not set");
     }
-    get_params_default(Path::new(&data_dir), SectorSizeOpt::Keys).await?;
+    get_params_default(Path::new(&data_dir), SectorSizeOpt::Keys, false).await?;
 
     Ok(())
 }
@@ -90,7 +90,14 @@ pub async fn get_params(
     data_dir: &Path,
     param_json: &str,
     storage_size: SectorSizeOpt,
+    dry_run: bool,
 ) -> Result<(), anyhow::Error> {
+    // Just print out the parameters download directory path and exit.
+    if dry_run {
+        println!("{}", param_dir(data_dir).to_string_lossy());
+        return Ok(());
+    }
+
     fs::create_dir_all(param_dir(data_dir)).await?;
 
     let params: ParameterMap = serde_json::from_str(param_json)?;
@@ -144,8 +151,9 @@ pub async fn get_params(
 pub async fn get_params_default(
     data_dir: &Path,
     storage_size: SectorSizeOpt,
+    dry_run: bool,
 ) -> Result<(), anyhow::Error> {
-    get_params(data_dir, DEFAULT_PARAMETERS, storage_size).await
+    get_params(data_dir, DEFAULT_PARAMETERS, storage_size, dry_run).await
 }
 
 async fn fetch_verify_params(


Test patch:
diff --git a/tests/config.rs b/tests/config.rs
index 90739b71406d..7805607dfda1 100644
--- a/tests/config.rs
+++ b/tests/config.rs
@@ -1,6 +1,6 @@
 // Copyright 2019-2023 ChainSafe Systems
 // SPDX-License-Identifier: Apache-2.0, MIT
-use std::{fs::read_dir, io::Write, net::SocketAddr, path::PathBuf, str::FromStr};
+use std::{io::Write, net::SocketAddr, path::PathBuf, str::FromStr};
 
 use anyhow::*;
 use assert_cmd::Command;
@@ -136,12 +136,10 @@ fn test_download_location_of_proof_parameter_files_env() {
         .env("FIL_PROOFS_PARAMETER_CACHE", tmp_dir.path())
         .arg("fetch-params")
         .arg("--keys")
+        .arg("--dry-run")
         .assert()
+        .stdout(tmp_dir.into_path().to_string_lossy().into_owned() + "\n")
         .success();
-
-    let list_files = read_dir(tmp_dir.path()).unwrap();
-
-    assert!(list_files.count() > 0);
 }
 
 #[test]
@@ -166,10 +164,8 @@ fn test_download_location_of_proof_parameter_files_default() {
         .env("FOREST_CONFIG_PATH", config_file.path())
         .arg("fetch-params")
         .arg("--keys")
+        .arg("--dry-run")
         .assert()
+        .stdout(tmp_param_dir.to_string_lossy().into_owned() + "\n")
         .success();
-
-    let list_files = read_dir(tmp_param_dir).unwrap();
-
-    assert!(list_files.count() > 0);
 }