diff --git a/CHANGELOG.md b/CHANGELOG.md index 83f26802..baee5a89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ All notable changes to this project will be documented in this file. - Handle IO error if rename fails (#241) - Readme commands (#243) -- Remove unused folders after download contracts node binary (#240) +- Remove unused directories after download contracts node binary (#240) - Check if contracts needs to be build before deploy (#246) ### 🚜 Refactor @@ -163,7 +163,7 @@ All notable changes to this project will be documented in this file. - Structure for call command - Call a smart contract - Execute call flag -- *(pop-cli)* Pallets folder for new ones +- *(pop-cli)* Pallets directory for new ones - *(up-parachain)* Improve ux - Init git repo (#65) - *(up-parachain)* Enable optional verbose output (#79) diff --git a/crates/pop-cli/src/commands/build/contract.rs b/crates/pop-cli/src/commands/build/contract.rs index a410bd66..ca0cdd73 100644 --- a/crates/pop-cli/src/commands/build/contract.rs +++ b/crates/pop-cli/src/commands/build/contract.rs @@ -12,8 +12,8 @@ pub struct BuildContractCommand { /// Path for the contract project [default: current directory] #[arg(long)] pub(crate) path: Option, - /// The default compilation includes debug functionality, increasing contract size and gas usage. - /// For production, always build in release mode to exclude debug features. + /// The default compilation includes debug functionality, increasing contract size and gas + /// usage. For production, always build in release mode to exclude debug features. #[clap(short, long)] pub(crate) release: bool, // Deprecation flag, used to specify whether the deprecation warning is shown. diff --git a/crates/pop-cli/src/commands/build/mod.rs b/crates/pop-cli/src/commands/build/mod.rs index 32871d27..08af079b 100644 --- a/crates/pop-cli/src/commands/build/mod.rs +++ b/crates/pop-cli/src/commands/build/mod.rs @@ -44,7 +44,8 @@ pub(crate) enum Command { #[cfg(feature = "parachain")] #[clap(alias = "p")] Parachain(BuildParachainCommand), - /// [DEPRECATED] Build a contract, generate metadata, bundle together in a `.contract` file + /// [DEPRECATED] Build a contract, generate metadata, bundle together in a `.contract` + /// file #[cfg(feature = "contract")] #[clap(alias = "c")] Contract(BuildContractCommand), diff --git a/crates/pop-cli/src/commands/build/parachain.rs b/crates/pop-cli/src/commands/build/parachain.rs index 5debc0e4..c071b7a3 100644 --- a/crates/pop-cli/src/commands/build/parachain.rs +++ b/crates/pop-cli/src/commands/build/parachain.rs @@ -83,7 +83,7 @@ mod tests { use duct::cmd; use std::{fs, io::Write, path::Path}; - // Function that generates a Cargo.toml inside node folder for testing. + // Function that generates a Cargo.toml inside node directory for testing. fn generate_mock_node(temp_dir: &Path) -> anyhow::Result<()> { // Create a node directory let target_dir = temp_dir.join("node"); diff --git a/crates/pop-cli/src/commands/build/spec.rs b/crates/pop-cli/src/commands/build/spec.rs index 0a1c8745..768b467a 100644 --- a/crates/pop-cli/src/commands/build/spec.rs +++ b/crates/pop-cli/src/commands/build/spec.rs @@ -1,6 +1,10 @@ // SPDX-License-Identifier: GPL-3.0 -use crate::{cli, cli::traits::Cli as _, cli::Cli, style::style}; +use crate::{ + cli, + cli::{traits::Cli as _, Cli}, + style::style, +}; use clap::{Args, ValueEnum}; use cliclack::{confirm, input}; use pop_common::Profile; @@ -221,7 +225,7 @@ impl BuildSpecCommand { // Locate binary, if it doesn't exist trigger build. let mode: Profile = self.release.into(); let cwd = current_dir().unwrap_or(PathBuf::from("./")); - let binary_path = match binary_path(&mode.target_folder(&cwd), &cwd.join("node")) { + let binary_path = match binary_path(&mode.target_directory(&cwd), &cwd.join("node")) { Ok(binary_path) => binary_path, _ => { cli.info("Node was not found. The project will be built locally.".to_string())?; diff --git a/crates/pop-cli/src/commands/call/contract.rs b/crates/pop-cli/src/commands/call/contract.rs index 63084544..d43689c9 100644 --- a/crates/pop-cli/src/commands/call/contract.rs +++ b/crates/pop-cli/src/commands/call/contract.rs @@ -13,7 +13,7 @@ use std::path::PathBuf; #[derive(Args)] pub struct CallContractCommand { - /// Path to the contract build folder. + /// Path to the contract build directory. #[arg(short = 'p', long)] path: Option, /// The address of the contract to call. diff --git a/crates/pop-cli/src/commands/mod.rs b/crates/pop-cli/src/commands/mod.rs index 77c77db3..34c2f10b 100644 --- a/crates/pop-cli/src/commands/mod.rs +++ b/crates/pop-cli/src/commands/mod.rs @@ -73,12 +73,14 @@ impl Command { }, #[cfg(feature = "parachain")] new::Command::Pallet(cmd) => { - // When more contract selections are added the tel data will likely need to go deeper in the stack + // When more contract selections are added the tel data will likely need to go + // deeper in the stack cmd.execute().await.map(|_| json!("template")) }, #[cfg(feature = "contract")] new::Command::Contract(cmd) => { - // When more contract selections are added, the tel data will likely need to go deeper in the stack + // When more contract selections are added, the tel data will likely need to go + // deeper in the stack cmd.execute().await.map(|_| json!("default")) }, }, diff --git a/crates/pop-cli/src/commands/new/contract.rs b/crates/pop-cli/src/commands/new/contract.rs index 5f201c23..a17eea54 100644 --- a/crates/pop-cli/src/commands/new/contract.rs +++ b/crates/pop-cli/src/commands/new/contract.rs @@ -72,7 +72,7 @@ impl NewContractCommand { let contract_type = &contract_config.contract_type.clone().unwrap_or_default(); let template = match &contract_config.template { Some(template) => template.clone(), - None => contract_type.default_template().expect("contract types have defaults; qed."), // Default contract type + None => contract_type.default_template().expect("contract types have defaults; qed."), /* Default contract type */ }; is_template_supported(contract_type, &template)?; diff --git a/crates/pop-cli/src/commands/new/parachain.rs b/crates/pop-cli/src/commands/new/parachain.rs index ef3ae0f1..ba69ea44 100644 --- a/crates/pop-cli/src/commands/new/parachain.rs +++ b/crates/pop-cli/src/commands/new/parachain.rs @@ -1,7 +1,9 @@ // SPDX-License-Identifier: GPL-3.0 -use crate::cli::{traits::Cli as _, Cli}; -use crate::style::style; +use crate::{ + cli::{traits::Cli as _, Cli}, + style::style, +}; use anyhow::Result; use clap::{ builder::{PossibleValue, PossibleValuesParser, TypedValueParser}, @@ -78,7 +80,7 @@ impl NewParachainCommand { let provider = ¶chain_config.provider.clone().unwrap_or_default(); let template = match ¶chain_config.template { Some(template) => template.clone(), - None => provider.default_template().expect("parachain templates have defaults; qed."), // Each provider has a template by default + None => provider.default_template().expect("parachain templates have defaults; qed."), /* Each provider has a template by default */ }; is_template_supported(provider, &template)?; @@ -313,7 +315,6 @@ async fn choose_release(template: &Parachain) -> Result> { async fn get_latest_3_releases(repo: &GitHub) -> Result> { let mut latest_3_releases: Vec = repo.releases().await?.into_iter().filter(|r| !r.prerelease).take(3).collect(); - repo.get_repo_license().await?; // Get the commit sha for the releases for release in latest_3_releases.iter_mut() { let commit = repo.get_commit_sha_from_release(&release.tag_name).await?; diff --git a/crates/pop-cli/src/commands/up/contract.rs b/crates/pop-cli/src/commands/up/contract.rs index bf24cf73..5541ec3a 100644 --- a/crates/pop-cli/src/commands/up/contract.rs +++ b/crates/pop-cli/src/commands/up/contract.rs @@ -16,10 +16,9 @@ use pop_contracts::{ }; use sp_core::Bytes; use sp_weights::Weight; -use std::process::Child; use std::{ path::{Path, PathBuf}, - process::Command, + process::{Child, Command}, }; use tempfile::NamedTempFile; use url::Url; @@ -30,7 +29,7 @@ const FAILED: &str = "🚫 Deployment failed."; #[derive(Args, Clone)] pub struct UpContractCommand { - /// Path to the contract build folder. + /// Path to the contract build directory. #[arg(short = 'p', long)] path: Option, /// The name of the contract constructor to call. @@ -71,7 +70,8 @@ pub struct UpContractCommand { /// Uploads the contract only, without instantiation. #[clap(short('u'), long)] upload_only: bool, - /// Automatically source or update the needed binary required without prompting for confirmation. + /// Automatically source or update the needed binary required without prompting for + /// confirmation. #[clap(short('y'), long)] skip_confirm: bool, } @@ -81,7 +81,7 @@ impl UpContractCommand { pub(crate) async fn execute(mut self) -> anyhow::Result<()> { Cli.intro("Deploy a smart contract")?; - // Check if build exists in the specified "Contract build folder" + // Check if build exists in the specified "Contract build directory" if !has_contract_been_built(self.path.as_deref()) { // Build the contract in release mode Cli.warning("NOTE: contract has not yet been built.")?; @@ -313,10 +313,12 @@ impl From for UpOpts { } } -/// Checks if a contract has been built by verifying the existence of the build directory and the .contract file. +/// Checks if a contract has been built by verifying the existence of the build directory and the +/// .contract file. /// /// # Arguments -/// * `path` - An optional path to the project directory. If no path is provided, the current directory is used. +/// * `path` - An optional path to the project directory. If no path is provided, the current +/// directory is used. pub fn has_contract_been_built(path: Option<&Path>) -> bool { let project_path = path.unwrap_or_else(|| Path::new("./")); let manifest = match from_path(Some(project_path)) { diff --git a/crates/pop-cli/src/commands/up/parachain.rs b/crates/pop-cli/src/commands/up/parachain.rs index a59d8284..fe1bbc1a 100644 --- a/crates/pop-cli/src/commands/up/parachain.rs +++ b/crates/pop-cli/src/commands/up/parachain.rs @@ -18,21 +18,21 @@ pub(crate) struct ZombienetCommand { /// The Zombienet network configuration file to be used. #[arg(short, long)] file: String, - /// The version of the binary to be used for the relay chain, as per the release tag (e.g. "v1.13.0"). - /// See https://github.com/paritytech/polkadot-sdk/releases for more details. + /// The version of the binary to be used for the relay chain, as per the release tag (e.g. + /// "v1.13.0"). See https://github.com/paritytech/polkadot-sdk/releases for more details. #[arg(short, long)] relay_chain: Option, - /// The version of the runtime to be used for the relay chain, as per the release tag (e.g. "v1.2.7"). - /// See https://github.com/polkadot-fellows/runtimes/releases for more details. + /// The version of the runtime to be used for the relay chain, as per the release tag (e.g. + /// "v1.2.7"). See https://github.com/polkadot-fellows/runtimes/releases for more details. #[arg(short = 'R', long)] relay_chain_runtime: Option, - /// The version of the binary to be used for system parachains, as per the release tag (e.g. "v1.13.0"). - /// Defaults to the relay chain version if not specified. + /// The version of the binary to be used for system parachains, as per the release tag (e.g. + /// "v1.13.0"). Defaults to the relay chain version if not specified. /// See https://github.com/paritytech/polkadot-sdk/releases for more details. #[arg(short, long)] system_parachain: Option, - /// The version of the runtime to be used for system parachains, as per the release tag (e.g. "v1.2.7"). - /// See https://github.com/polkadot-fellows/runtimes/releases for more details. + /// The version of the runtime to be used for system parachains, as per the release tag (e.g. + /// "v1.2.7"). See https://github.com/polkadot-fellows/runtimes/releases for more details. #[arg(short = 'S', long)] system_parachain_runtime: Option, /// The url of the git repository of a parachain to be used, with branch/release tag/commit specified as #fragment (e.g. 'https://github.com/org/repository#ref'). diff --git a/crates/pop-cli/src/common/contracts.rs b/crates/pop-cli/src/common/contracts.rs index 02e6b838..aa7a541e 100644 --- a/crates/pop-cli/src/common/contracts.rs +++ b/crates/pop-cli/src/common/contracts.rs @@ -4,7 +4,8 @@ use cliclack::{confirm, log::warning, spinner}; use pop_contracts::contracts_node_generator; use std::path::PathBuf; -/// Checks the status of the `substrate-contracts-node` binary, sources it if necessary, and prompts the user to update it if the existing binary is not the latest version. +/// Checks the status of the `substrate-contracts-node` binary, sources it if necessary, and +/// prompts the user to update it if the existing binary is not the latest version. /// /// # Arguments /// * `skip_confirm`: A boolean indicating whether to skip confirmation prompts. diff --git a/crates/pop-cli/src/main.rs b/crates/pop-cli/src/main.rs index bccefae3..9a41fd7c 100644 --- a/crates/pop-cli/src/main.rs +++ b/crates/pop-cli/src/main.rs @@ -30,7 +30,8 @@ async fn main() -> Result<()> { #[cfg(feature = "telemetry")] if let Some(tel) = maybe_tel.clone() { - // `args` is guaranteed to have at least 3 elements as clap will display help message if not set. + // `args` is guaranteed to have at least 3 elements as clap will display help message if not + // set. let (command, subcommand) = parse_args(args().collect()); if let Ok(sub_data) = &res { diff --git a/crates/pop-cli/tests/contract.rs b/crates/pop-cli/tests/contract.rs index 07dbcda4..eec67e7d 100644 --- a/crates/pop-cli/tests/contract.rs +++ b/crates/pop-cli/tests/contract.rs @@ -35,7 +35,7 @@ async fn contract_lifecycle() -> Result<()> { .args(&["build", "--path", "./test_contract", "--release"]) .assert() .success(); - // Verify that the folder target has been created + // Verify that the directory target has been created assert!(temp_dir.join("test_contract/target").exists()); // Verify that all the artifacts has been generated assert!(temp_dir.join("test_contract/target/ink/test_contract.contract").exists()); @@ -71,7 +71,8 @@ async fn contract_lifecycle() -> Result<()> { ]) .assert() .success(); - // Using methods from the pop_contracts crate to instantiate it to get the Contract Address for the call + // Using methods from the pop_contracts crate to instantiate it to get the Contract Address for + // the call let instantiate_exec = set_up_deployment(UpOpts { path: Some(temp_dir.join("test_contract")), constructor: "new".to_string(), diff --git a/crates/pop-cli/tests/parachain.rs b/crates/pop-cli/tests/parachain.rs index 497bb238..9aa6c060 100644 --- a/crates/pop-cli/tests/parachain.rs +++ b/crates/pop-cli/tests/parachain.rs @@ -46,7 +46,8 @@ async fn parachain_lifecycle() -> Result<()> { assert!(temp_dir.join("test_parachain/target").exists()); let temp_parachain_dir = temp_dir.join("test_parachain"); - // pop build spec --output ./target/pop/test-spec.json --id 2222 --type development --relay paseo-local --protocol-id pop-protocol" + // pop build spec --output ./target/pop/test-spec.json --id 2222 --type development --relay + // paseo-local --protocol-id pop-protocol" Command::cargo_bin("pop") .unwrap() .current_dir(&temp_parachain_dir) diff --git a/crates/pop-common/src/build.rs b/crates/pop-common/src/build.rs index d50b4ba3..bfe658b9 100644 --- a/crates/pop-common/src/build.rs +++ b/crates/pop-common/src/build.rs @@ -13,8 +13,8 @@ pub enum Profile { } impl Profile { - /// Returns the corresponding path to the target folder. - pub fn target_folder(&self, path: &Path) -> PathBuf { + /// Returns the corresponding path to the target directory. + pub fn target_directory(&self, path: &Path) -> PathBuf { match self { Profile::Release => path.join("target/release"), Profile::Debug => path.join("target/debug"), diff --git a/crates/pop-common/src/helpers.rs b/crates/pop-common/src/helpers.rs index 9f03f13f..08a20369 100644 --- a/crates/pop-common/src/helpers.rs +++ b/crates/pop-common/src/helpers.rs @@ -13,9 +13,8 @@ use std::{ /// # Arguments /// /// * `file_path` - A `PathBuf` specifying the path to the file to be modified. -/// * `replacements` - A `HashMap` where each key-value pair represents -/// a target string and its corresponding replacement string. -/// +/// * `replacements` - A `HashMap` where each key-value pair represents a target string and its +/// corresponding replacement string. pub fn replace_in_file(file_path: PathBuf, replacements: HashMap<&str, &str>) -> Result<(), Error> { // Read the file content let mut file_content = String::new(); @@ -31,7 +30,8 @@ pub fn replace_in_file(file_path: PathBuf, replacements: HashMap<&str, &str>) -> Ok(()) } -/// Gets the last component (name of a project) of a path or returns a default value if the path has no valid last component. +/// Gets the last component (name of a project) of a path or returns a default value if the path has +/// no valid last component. /// /// # Arguments /// * `path` - Location path of the project. diff --git a/crates/pop-common/src/lib.rs b/crates/pop-common/src/lib.rs index f4a08bf7..cf375654 100644 --- a/crates/pop-common/src/lib.rs +++ b/crates/pop-common/src/lib.rs @@ -10,6 +10,7 @@ pub use build::Profile; pub use errors::Error; pub use git::{Git, GitHub, Release}; pub use helpers::{get_project_name_from_path, replace_in_file}; +pub use templates::extractor::extract_template_files; static APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")); diff --git a/crates/pop-common/src/manifest.rs b/crates/pop-common/src/manifest.rs index 11500fd1..5ceb31e4 100644 --- a/crates/pop-common/src/manifest.rs +++ b/crates/pop-common/src/manifest.rs @@ -12,7 +12,8 @@ use toml_edit::{value, DocumentMut, Item, Value}; /// Parses the contents of a `Cargo.toml` manifest. /// /// # Arguments -/// * `path` - The optional path to the manifest, defaulting to the current directory if not specified. +/// * `path` - The optional path to the manifest, defaulting to the current directory if not +/// specified. pub fn from_path(path: Option<&Path>) -> Result { // Resolve manifest path let path = match path { @@ -28,7 +29,8 @@ pub fn from_path(path: Option<&Path>) -> Result { Ok(Manifest::from_path(path.canonicalize()?)?) } -/// This function is used to determine if a Path is contained inside a workspace, and returns a PathBuf to the workspace Cargo.toml if found +/// This function is used to determine if a Path is contained inside a workspace, and returns a +/// PathBuf to the workspace Cargo.toml if found /// /// # Arguments /// * `target_dir` - A directory that may be contained inside a workspace diff --git a/crates/pop-common/src/sourcing/binary.rs b/crates/pop-common/src/sourcing/binary.rs index 705fae63..a8063616 100644 --- a/crates/pop-common/src/sourcing/binary.rs +++ b/crates/pop-common/src/sourcing/binary.rs @@ -2,8 +2,10 @@ use crate::{ sourcing::{ - from_local_package, Error, GitHub::ReleaseArchive, GitHub::SourceCodeArchive, Source, - Source::Archive, Source::Git, Source::GitHub, + from_local_package, Error, + GitHub::{ReleaseArchive, SourceCodeArchive}, + Source, + Source::{Archive, Git, GitHub}, }, Status, }; @@ -85,13 +87,14 @@ impl Binary { } } - /// Attempts to resolve a version of a binary based on whether one is specified, an existing version - /// can be found cached locally, or uses the latest version. + /// Attempts to resolve a version of a binary based on whether one is specified, an existing + /// version can be found cached locally, or uses the latest version. /// /// # Arguments /// * `name` - The name of the binary. /// * `specified` - If available, a version explicitly specified. - /// * `available` - The available versions, used to check for those cached locally or the latest otherwise. + /// * `available` - The available versions, used to check for those cached locally or the latest + /// otherwise. /// * `cache` - The location used for caching binaries. pub fn resolve_version( name: &str, @@ -120,7 +123,8 @@ impl Binary { /// Sources the binary. /// /// # Arguments - /// * `release` - Whether any binaries needing to be built should be done so using the release profile. + /// * `release` - Whether any binaries needing to be built should be done so using the release + /// profile. /// * `status` - Used to observe status updates. /// * `verbose` - Whether verbose output is required. pub async fn source( diff --git a/crates/pop-common/src/sourcing/mod.rs b/crates/pop-common/src/sourcing/mod.rs index ea925ef4..0ba28a02 100644 --- a/crates/pop-common/src/sourcing/mod.rs +++ b/crates/pop-common/src/sourcing/mod.rs @@ -7,12 +7,12 @@ use crate::{Git, Status, APP_USER_AGENT}; use duct::cmd; use flate2::read::GzDecoder; use reqwest::StatusCode; -use std::time::Duration; use std::{ fs::{copy, metadata, read_dir, rename, File}, io::{BufRead, Seek, SeekFrom, Write}, os::unix::fs::PermissionsExt, path::{Path, PathBuf}, + time::Duration, }; use tar::Archive; use tempfile::{tempdir, tempfile}; @@ -77,7 +77,8 @@ impl Source { /// # Arguments /// /// * `cache` - the cache to be used. - /// * `release` - whether any binaries needing to be built should be done so using the release profile. + /// * `release` - whether any binaries needing to be built should be done so using the release + /// profile. /// * `status` - used to observe status updates. /// * `verbose` - whether verbose output is required. pub(super) async fn source( @@ -164,7 +165,8 @@ impl GitHub { /// # Arguments /// /// * `cache` - the cache to be used. - /// * `release` - whether any binaries needing to be built should be done so using the release profile. + /// * `release` - whether any binaries needing to be built should be done so using the release + /// profile. /// * `status` - used to observe status updates. /// * `verbose` - whether verbose output is required. async fn source( @@ -383,7 +385,8 @@ async fn from_github_archive( )) }, 1 => working_dir = entries[0].path(), // Automatically switch to top level directory - _ => {}, // Assume that downloaded archive does not have a top level directory + _ => {}, /* Assume that downloaded archive does not have a + * top level directory */ } // Build binaries status.update("Starting build of binary..."); diff --git a/crates/pop-common/src/templates/extractor.rs b/crates/pop-common/src/templates/extractor.rs new file mode 100644 index 00000000..b0d1f47f --- /dev/null +++ b/crates/pop-common/src/templates/extractor.rs @@ -0,0 +1,100 @@ +// SPDX-License-Identifier: GPL-3.0 + +use anyhow::Result; +use std::{fs, io, path::Path}; + +/// Extracts the specified template files from the repository directory to the target directory. +/// +/// # Arguments +/// * `template_name` - The name of the template to extract. +/// * `repo_directory` - The path to the repository directory containing the template. +/// * `target_directory` - The destination path where the template files should be copied. +/// * `ignore_directories` - A vector of directory names to ignore during the extraction. If empty, +/// no directories are ignored. +pub fn extract_template_files( + template_name: String, + repo_directory: &Path, + target_directory: &Path, + ignore_directories: Option>, +) -> Result<()> { + let template_directory = repo_directory.join(template_name); + // Recursively copy all directories and files within. Ignores the specified ones. + copy_dir_all( + &template_directory, + target_directory, + &ignore_directories.unwrap_or_else(|| vec![]), + )?; + Ok(()) +} + +/// Recursively copy a directory and its files. +/// +/// # Arguments +/// * `src`: - The source path of the directory to be copied. +/// * `dst`: - The destination path where the directory and its contents will be copied. +/// * `ignore_directories` - directories to ignore during the copy process. +fn copy_dir_all( + src: impl AsRef, + dst: impl AsRef, + ignore_directories: &Vec, +) -> io::Result<()> { + fs::create_dir_all(&dst)?; + for entry in fs::read_dir(src)? { + let entry = entry?; + let ty = entry.file_type()?; + if ty.is_dir() + && ignore_directories.contains(&entry.file_name().to_string_lossy().to_string()) + { + continue; + } else if ty.is_dir() { + copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()), ignore_directories)?; + } else { + fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?; + } + } + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + use anyhow::{Error, Result}; + use std::fs; + + fn generate_testing_contract(template: &str) -> Result { + let temp_dir = tempfile::tempdir()?; + let template_directory = temp_dir.path().join(template.to_string()); + fs::create_dir(&template_directory)?; + fs::File::create(&template_directory.join("lib.rs"))?; + fs::File::create(&template_directory.join("Cargo.toml"))?; + fs::create_dir(&temp_dir.path().join("noise_directory"))?; + fs::create_dir(&template_directory.join("frontend"))?; + Ok(temp_dir) + } + #[test] + fn extract_template_files_works() -> Result<(), Error> { + // Contract + let mut temp_dir = generate_testing_contract("erc20")?; + let mut output_dir = tempfile::tempdir()?; + extract_template_files("erc20".to_string(), temp_dir.path(), output_dir.path(), None)?; + assert!(output_dir.path().join("lib.rs").exists()); + assert!(output_dir.path().join("Cargo.toml").exists()); + assert!(output_dir.path().join("frontend").exists()); + assert!(!output_dir.path().join("noise_directory").exists()); + // ignore the frontend directory + temp_dir = generate_testing_contract("erc721")?; + output_dir = tempfile::tempdir()?; + extract_template_files( + "erc721".to_string(), + temp_dir.path(), + output_dir.path(), + Some(vec!["frontend".to_string()]), + )?; + assert!(output_dir.path().join("lib.rs").exists()); + assert!(output_dir.path().join("Cargo.toml").exists()); + assert!(!output_dir.path().join("frontend").exists()); + assert!(!output_dir.path().join("noise_directory").exists()); + + Ok(()) + } +} diff --git a/crates/pop-common/src/templates.rs b/crates/pop-common/src/templates/mod.rs similarity index 99% rename from crates/pop-common/src/templates.rs rename to crates/pop-common/src/templates/mod.rs index f3cd14e8..e4f7604a 100644 --- a/crates/pop-common/src/templates.rs +++ b/crates/pop-common/src/templates/mod.rs @@ -3,6 +3,8 @@ use strum::{EnumMessage, EnumProperty, VariantArray}; pub use thiserror::Error; +pub mod extractor; + #[derive(Error, Debug)] pub enum Error { #[error("The `Repository` property is missing from the template variant")] diff --git a/crates/pop-contracts/src/build.rs b/crates/pop-contracts/src/build.rs index bfbe8e8b..9ce70dfe 100644 --- a/crates/pop-contracts/src/build.rs +++ b/crates/pop-contracts/src/build.rs @@ -8,7 +8,8 @@ use std::path::Path; /// Build the smart contract located at the specified `path` in `build_release` mode. /// /// # Arguments -/// * `path` - The optional path to the smart contract manifest, defaulting to the current directory if not specified. +/// * `path` - The optional path to the smart contract manifest, defaulting to the current directory +/// if not specified. /// * `release` - Whether the smart contract should be built without any debugging functionality. /// * `verbosity` - The build output verbosity. pub fn build_smart_contract( @@ -33,7 +34,8 @@ pub fn build_smart_contract( /// Determines whether the manifest at the supplied path is a supported smart contract project. /// /// # Arguments -/// * `path` - The optional path to the manifest, defaulting to the current directory if not specified. +/// * `path` - The optional path to the manifest, defaulting to the current directory if not +/// specified. pub fn is_supported(path: Option<&Path>) -> Result { Ok(pop_common::manifest::from_path(path)?.dependencies.contains_key("ink")) } diff --git a/crates/pop-contracts/src/call.rs b/crates/pop-contracts/src/call.rs index 451e8a09..88a3a65b 100644 --- a/crates/pop-contracts/src/call.rs +++ b/crates/pop-contracts/src/call.rs @@ -22,7 +22,7 @@ use url::Url; /// Attributes for the `call` command. pub struct CallOpts { - /// Path to the contract build folder. + /// Path to the contract build directory. pub path: Option, /// The address of the contract to call. pub contract: String, @@ -49,7 +49,6 @@ pub struct CallOpts { /// # Arguments /// /// * `call_opts` - options for the `call` command. -/// pub async fn set_up_call( call_opts: CallOpts, ) -> anyhow::Result> { @@ -83,7 +82,6 @@ pub async fn set_up_call( /// # Arguments /// /// * `call_exec` - struct with the call to be executed. -/// pub async fn dry_run_call( call_exec: &CallExec, ) -> Result { @@ -109,7 +107,6 @@ pub async fn dry_run_call( /// # Arguments /// /// * `call_exec` - the preprocessed data to call a contract. -/// pub async fn dry_run_gas_estimate_call( call_exec: &CallExec, ) -> Result { @@ -138,7 +135,6 @@ pub async fn dry_run_gas_estimate_call( /// * `call_exec` - struct with the call to be executed. /// * `gas_limit` - maximum amount of gas to be used for this call. /// * `url` - endpoint of the node which to send the call to. -/// pub async fn call_smart_contract( call_exec: CallExec, gas_limit: Weight, @@ -237,7 +233,7 @@ mod tests { Ok(()) } #[tokio::test] - async fn test_set_up_call_fails_no_smart_contract_folder() -> Result<()> { + async fn test_set_up_call_fails_no_smart_contract_directory() -> Result<()> { let call_opts = CallOpts { path: None, contract: "5CLPm1CeUvJhZ8GCDZCR7nWZ2m3XXe4X5MtAQK69zEjut36A".to_string(), diff --git a/crates/pop-contracts/src/new.rs b/crates/pop-contracts/src/new.rs index 13232a74..0bf4c054 100644 --- a/crates/pop-contracts/src/new.rs +++ b/crates/pop-contracts/src/new.rs @@ -1,16 +1,14 @@ // SPDX-License-Identifier: GPL-3.0 -use crate::{ - errors::Error, - utils::helpers::{canonicalized_path, copy_dir_all}, - Contract, -}; +use crate::{errors::Error, utils::helpers::canonicalized_path, Contract}; use anyhow::Result; use contract_build::new_contract_project; use heck::ToUpperCamelCase; -use pop_common::{replace_in_file, templates::Template, Git}; -use std::collections::HashMap; -use std::path::{Path, PathBuf}; +use pop_common::{extract_template_files, replace_in_file, templates::Template, Git}; +use std::{ + collections::HashMap, + path::{Path, PathBuf}, +}; use url::Url; /// Create a new smart contract. @@ -67,12 +65,18 @@ fn create_template_contract( // Retrieve only the template contract files. if template == &Contract::PSP22 || template == &Contract::PSP34 { // Different template structure requires extracting different path - extract_contract_files(String::from(""), temp_dir.path(), canonicalized_path.as_path())?; + extract_template_files( + String::from(""), + temp_dir.path(), + canonicalized_path.as_path(), + None, + )?; } else { - extract_contract_files( + extract_template_files( template.to_string(), temp_dir.path(), canonicalized_path.as_path(), + Some(vec!["frontend".to_string()]), )?; } @@ -81,17 +85,6 @@ fn create_template_contract( Ok(()) } -fn extract_contract_files( - contract_name: String, - repo_folder: &Path, - target_folder: &Path, -) -> Result<()> { - let contract_folder = repo_folder.join(contract_name); - // Recursively copy all folders and files within. Ignores frontend folders. - copy_dir_all(&contract_folder, target_folder)?; - Ok(()) -} - pub fn rename_contract(name: &str, path: PathBuf, template: &Contract) -> Result<()> { let template_name = template.to_string().to_lowercase(); // Replace name in the Cargo.toml file. @@ -170,86 +163,7 @@ mod tests { Ok(()) } - fn generate_testing_files_and_folders(template: Contract) -> Result { - let temp_dir = tempfile::tempdir()?; - let contract_folder = temp_dir.path().join(template.to_string()); - fs::create_dir(&contract_folder)?; - fs::File::create(&contract_folder.join("lib.rs"))?; - fs::File::create(&contract_folder.join("Cargo.toml"))?; - fs::create_dir(&temp_dir.path().join("noise_folder"))?; - Ok(temp_dir) - } - - #[test] - fn test_extract_contract_files() -> Result<(), Error> { - // ERC-20 - let mut temp_dir = generate_testing_files_and_folders(Contract::ERC20)?; - let mut output_dir = tempfile::tempdir()?; - extract_contract_files(Contract::ERC20.to_string(), temp_dir.path(), output_dir.path())?; - assert!(output_dir.path().join("lib.rs").exists()); - assert!(output_dir.path().join("Cargo.toml").exists()); - assert!(!output_dir.path().join("noise_folder").exists()); - assert!(!output_dir.path().join("frontend").exists()); - // ERC-721 - temp_dir = generate_testing_files_and_folders(Contract::ERC721)?; - output_dir = tempfile::tempdir()?; - extract_contract_files(Contract::ERC721.to_string(), temp_dir.path(), output_dir.path())?; - assert!(output_dir.path().join("lib.rs").exists()); - assert!(output_dir.path().join("Cargo.toml").exists()); - assert!(!output_dir.path().join("noise_folder").exists()); - assert!(!output_dir.path().join("frontend").exists()); - // ERC-1155 - temp_dir = generate_testing_files_and_folders(Contract::ERC1155)?; - output_dir = tempfile::tempdir()?; - extract_contract_files(Contract::ERC1155.to_string(), temp_dir.path(), output_dir.path())?; - assert!(output_dir.path().join("lib.rs").exists()); - assert!(output_dir.path().join("Cargo.toml").exists()); - assert!(!output_dir.path().join("noise_folder").exists()); - assert!(!output_dir.path().join("frontend").exists()); - // PSP22 - temp_dir = generate_testing_files_and_folders(Contract::PSP22)?; - output_dir = tempfile::tempdir()?; - extract_contract_files(Contract::PSP22.to_string(), temp_dir.path(), output_dir.path())?; - assert!(output_dir.path().join("lib.rs").exists()); - assert!(output_dir.path().join("Cargo.toml").exists()); - assert!(!output_dir.path().join("noise_folder").exists()); - // PSP34 - temp_dir = generate_testing_files_and_folders(Contract::PSP34)?; - output_dir = tempfile::tempdir()?; - extract_contract_files(Contract::PSP34.to_string(), temp_dir.path(), output_dir.path())?; - assert!(output_dir.path().join("lib.rs").exists()); - assert!(output_dir.path().join("Cargo.toml").exists()); - assert!(!output_dir.path().join("noise_folder").exists()); - // DNS - temp_dir = generate_testing_files_and_folders(Contract::DNS)?; - output_dir = tempfile::tempdir()?; - extract_contract_files(Contract::DNS.to_string(), temp_dir.path(), output_dir.path())?; - assert!(output_dir.path().join("lib.rs").exists()); - assert!(output_dir.path().join("Cargo.toml").exists()); - assert!(!output_dir.path().join("noise_folder").exists()); - // CrossContract - temp_dir = generate_testing_files_and_folders(Contract::CrossContract)?; - output_dir = tempfile::tempdir()?; - extract_contract_files( - Contract::CrossContract.to_string(), - temp_dir.path(), - output_dir.path(), - )?; - assert!(output_dir.path().join("lib.rs").exists()); - assert!(output_dir.path().join("Cargo.toml").exists()); - assert!(!output_dir.path().join("noise_folder").exists()); - // Multisig - temp_dir = generate_testing_files_and_folders(Contract::Multisig)?; - output_dir = tempfile::tempdir()?; - extract_contract_files(Contract::Multisig.to_string(), temp_dir.path(), output_dir.path())?; - assert!(output_dir.path().join("lib.rs").exists()); - assert!(output_dir.path().join("Cargo.toml").exists()); - assert!(!output_dir.path().join("noise_folder").exists()); - - Ok(()) - } - - fn generate_contract_folder() -> Result { + fn generate_contract_directory() -> Result { let temp_dir = tempfile::tempdir()?; let config = temp_dir.path().join("Cargo.toml"); let mut config_file = fs::File::create(config.clone())?; @@ -277,7 +191,7 @@ mod tests { } #[test] fn test_rename_contract() -> Result<(), Error> { - let temp_dir = generate_contract_folder()?; + let temp_dir = generate_contract_directory()?; rename_contract("my_contract", temp_dir.path().to_owned(), &Contract::ERC20)?; let generated_cargo = fs::read_to_string(temp_dir.path().join("Cargo.toml")).expect("Could not read file"); diff --git a/crates/pop-contracts/src/node/mod.rs b/crates/pop-contracts/src/node/mod.rs index 14c8bcb5..1c61c4cf 100644 --- a/crates/pop-contracts/src/node/mod.rs +++ b/crates/pop-contracts/src/node/mod.rs @@ -28,7 +28,6 @@ const BIN_NAME: &str = "substrate-contracts-node"; /// # Arguments /// /// * `url` - Endpoint of the node. -/// pub async fn is_chain_alive(url: url::Url) -> Result { let request = RpcRequest::new(&url).await; match request { @@ -65,7 +64,7 @@ impl TryInto for Chain { /// * `latest` - If applicable, some specifier used to determine the latest source. fn try_into(&self, tag: Option, latest: Option) -> Result { let archive = archive_name_by_target()?; - let archive_bin_path = release_folder_by_target()?; + let archive_bin_path = release_directory_by_target()?; Ok(match self { &Chain::ContractsNode => { // Source from GitHub release asset @@ -86,12 +85,13 @@ impl TryInto for Chain { impl pop_common::sourcing::traits::Source for Chain {} -/// Retrieves the latest release of the contracts node binary, resolves its version, and constructs a `Binary::Source` -/// with the specified cache path. +/// Retrieves the latest release of the contracts node binary, resolves its version, and constructs +/// a `Binary::Source` with the specified cache path. /// /// # Arguments /// * `cache` - The cache directory path. -/// * `version` - The specific version used for the substrate-contracts-node (`None` will use the latest available version). +/// * `version` - The specific version used for the substrate-contracts-node (`None` will use the +/// latest available version). pub async fn contracts_node_generator( cache: PathBuf, version: Option<&str>, @@ -118,7 +118,6 @@ pub async fn contracts_node_generator( /// /// * `binary_path` - The path where the binary is stored. Can be the binary name itself if in PATH. /// * `output` - The optional log file for node output. -/// pub async fn run_contracts_node( binary_path: PathBuf, output: Option<&File>, @@ -145,7 +144,7 @@ fn archive_name_by_target() -> Result { } } -fn release_folder_by_target() -> Result<&'static str, Error> { +fn release_directory_by_target() -> Result<&'static str, Error> { match OS { "macos" => Ok("artifacts/substrate-contracts-node-mac/substrate-contracts-node"), "linux" => Ok("artifacts/substrate-contracts-node-linux/substrate-contracts-node"), @@ -160,7 +159,7 @@ mod tests { use std::process::Command; #[tokio::test] - async fn folder_path_by_target() -> Result<()> { + async fn directory_path_by_target() -> Result<()> { let archive = archive_name_by_target(); if cfg!(target_os = "macos") { assert_eq!(archive?, "substrate-contracts-node-mac-universal.tar.gz"); @@ -189,7 +188,7 @@ mod tests { let version = "v0.40.0"; let binary = contracts_node_generator(cache.clone(), Some(version)).await?; let archive = archive_name_by_target()?; - let archive_bin_path = release_folder_by_target()?; + let archive_bin_path = release_directory_by_target()?; assert!(matches!(binary, Binary::Source { name, source, cache} if name == expected.binary() && source == Source::GitHub(ReleaseArchive { diff --git a/crates/pop-contracts/src/test.rs b/crates/pop-contracts/src/test.rs index 5bc9a968..911b2ef8 100644 --- a/crates/pop-contracts/src/test.rs +++ b/crates/pop-contracts/src/test.rs @@ -52,7 +52,7 @@ mod tests { } #[test] - fn test_smart_contract_wrong_folder() -> Result<(), Error> { + fn test_smart_contract_wrong_directory() -> Result<(), Error> { let temp_dir = tempfile::tempdir()?; assert!(matches!( test_smart_contract(Some(&temp_dir.path().join(""))), @@ -65,7 +65,8 @@ mod tests { fn test_e2e_smart_contract_set_env_variable() -> Result<(), Error> { let temp_dir = tempfile::tempdir()?; cmd("cargo", ["new", "test_contract", "--bin"]).dir(temp_dir.path()).run()?; - // Ignore 2e2 testing in this scenario, will fail. Only test if the environment variable CONTRACTS_NODE is set. + // Ignore 2e2 testing in this scenario, will fail. Only test if the environment variable + // CONTRACTS_NODE is set. let err = test_e2e_smart_contract(Some(&temp_dir.path().join("test_contract")), None); assert!(err.is_err()); // The environment variable `CONTRACTS_NODE` should not be set. diff --git a/crates/pop-contracts/src/up.rs b/crates/pop-contracts/src/up.rs index e6ac04d1..ac4d22e4 100644 --- a/crates/pop-contracts/src/up.rs +++ b/crates/pop-contracts/src/up.rs @@ -20,7 +20,7 @@ use subxt_signer::sr25519::Keypair; /// Attributes for the `up` command #[derive(Debug, PartialEq)] pub struct UpOpts { - /// Path to the contract build folder. + /// Path to the contract build directory. pub path: Option, /// The name of the contract constructor to call. pub constructor: String, @@ -96,7 +96,8 @@ pub async fn set_up_upload( return Ok(upload_exec); } -/// Estimate the gas required for instantiating a contract without modifying the state of the blockchain. +/// Estimate the gas required for instantiating a contract without modifying the state of the +/// blockchain. /// /// # Arguments /// diff --git a/crates/pop-contracts/src/utils/helpers.rs b/crates/pop-contracts/src/utils/helpers.rs index e89a80a8..89a80ed7 100644 --- a/crates/pop-contracts/src/utils/helpers.rs +++ b/crates/pop-contracts/src/utils/helpers.rs @@ -5,7 +5,6 @@ use contract_build::ManifestPath; use contract_extrinsics::BalanceVariant; use ink_env::{DefaultEnvironment, Environment}; use std::{ - fs, io, path::{Path, PathBuf}, str::FromStr, }; @@ -38,7 +37,6 @@ pub fn parse_account(account: &str) -> Result<::Account /// # Arguments /// /// * `target` - A reference to the `Path` to be canonicalized. -/// pub fn canonicalized_path(target: &Path) -> Result { // Canonicalize the target path to ensure consistency and resolve any symbolic links. target @@ -46,29 +44,6 @@ pub fn canonicalized_path(target: &Path) -> Result { // If an I/O error occurs during canonicalization, convert it into an Error enum variant. .map_err(|e| Error::IO(e)) } -/// Recursively copy a directory and its files. -/// -/// # Arguments -/// -/// * `src`: - Path to copy from -/// * `dst`: - Path to copy to -/// -pub fn copy_dir_all(src: impl AsRef, dst: impl AsRef) -> io::Result<()> { - fs::create_dir_all(&dst)?; - for entry in fs::read_dir(src)? { - let entry = entry?; - let ty = entry.file_type()?; - // Ignore frontend folder in templates - if ty.is_dir() && entry.file_name() == "frontend" { - continue; - } else if ty.is_dir() { - copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?; - } else { - fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?; - } - } - Ok(()) -} #[cfg(test)] mod tests { @@ -99,8 +74,8 @@ mod tests { fn test_canonicalized_path() -> Result<(), Error> { let temp_dir = tempfile::tempdir()?; // Error case - let error_folder = canonicalized_path(&temp_dir.path().join("my_folder")); - assert!(error_folder.is_err()); + let error_directory = canonicalized_path(&temp_dir.path().join("my_directory")); + assert!(error_directory.is_err()); // Success case canonicalized_path(temp_dir.path())?; Ok(()) diff --git a/crates/pop-parachains/src/build.rs b/crates/pop-parachains/src/build.rs index dc899af8..669ed1e8 100644 --- a/crates/pop-parachains/src/build.rs +++ b/crates/pop-parachains/src/build.rs @@ -14,10 +14,12 @@ use std::{ /// Build the parachain and returns the path to the binary. /// /// # Arguments -/// * `path` - The optional path to the parachain manifest, defaulting to the current directory if not specified. +/// * `path` - The optional path to the parachain manifest, defaulting to the current directory if +/// not specified. /// * `package` - The optional package to be built. /// * `release` - Whether the parachain should be built without any debugging functionality. -/// * `node_path` - An optional path to the node directory. Defaults to the `node` subdirectory of the project path if not provided. +/// * `node_path` - An optional path to the node directory. Defaults to the `node` subdirectory of +/// the project path if not provided. pub fn build_parachain( path: &Path, package: Option, @@ -33,13 +35,14 @@ pub fn build_parachain( args.push("--release"); } cmd("cargo", args).dir(path).run()?; - binary_path(&profile.target_folder(path), node_path.unwrap_or(&path.join("node"))) + binary_path(&profile.target_directory(path), node_path.unwrap_or(&path.join("node"))) } /// Determines whether the manifest at the supplied path is a supported parachain project. /// /// # Arguments -/// * `path` - The optional path to the manifest, defaulting to the current directory if not specified. +/// * `path` - The optional path to the manifest, defaulting to the current directory if not +/// specified. pub fn is_supported(path: Option<&Path>) -> Result { let manifest = from_path(path)?; // Simply check for a parachain dependency @@ -51,7 +54,7 @@ pub fn is_supported(path: Option<&Path>) -> Result { })) } -/// Constructs the node binary path based on the target path and the node folder path. +/// Constructs the node binary path based on the target path and the node directory path. /// /// # Arguments /// * `target_path` - The path where the binaries are expected to be found. @@ -121,7 +124,8 @@ pub fn generate_raw_chain_spec( /// Export the WebAssembly runtime for the parachain. /// /// # Arguments -/// * `binary_path` - The path to the node binary executable that contains the `export-genesis-wasm` command. +/// * `binary_path` - The path to the node binary executable that contains the `export-genesis-wasm` +/// command. /// * `chain_spec` - Location of the raw chain specification file. /// * `wasm_file_name` - The name of the wasm runtime file to be generated. pub fn export_wasm_file( @@ -152,7 +156,8 @@ pub fn export_wasm_file( /// Generate the parachain genesis state. /// /// # Arguments -/// * `binary_path` - The path to the node binary executable that contains the `export-genesis-state` command. +/// * `binary_path` - The path to the node binary executable that contains the +/// `export-genesis-state` command. /// * `chain_spec` - Location of the raw chain specification file. /// * `genesis_file_name` - The name of the genesis state file to be generated. pub fn generate_genesis_state_file( @@ -348,7 +353,7 @@ mod tests { Ok(()) } - // Function that generates a Cargo.toml inside node folder for testing. + // Function that generates a Cargo.toml inside node directory for testing. fn generate_mock_node(temp_dir: &Path) -> Result<(), Error> { // Create a node directory let target_dir = temp_dir.join("node"); @@ -414,12 +419,12 @@ default_command = "pop-node" cmd("cargo", ["new", name, "--bin"]).dir(temp_dir.path()).run()?; generate_mock_node(&temp_dir.path().join(name))?; let binary = build_parachain(&temp_dir.path().join(name), None, &Profile::Release, None)?; - let target_folder = temp_dir.path().join(name).join("target/release"); - assert!(target_folder.exists()); - assert!(target_folder.join("parachain_template_node").exists()); + let target_directory = temp_dir.path().join(name).join("target/release"); + assert!(target_directory.exists()); + assert!(target_directory.join("parachain_template_node").exists()); assert_eq!( binary.display().to_string(), - target_folder.join("parachain_template_node").display().to_string() + target_directory.join("parachain_template_node").display().to_string() ); Ok(()) } diff --git a/crates/pop-parachains/src/errors.rs b/crates/pop-parachains/src/errors.rs index a97c5eff..58b59c58 100644 --- a/crates/pop-parachains/src/errors.rs +++ b/crates/pop-parachains/src/errors.rs @@ -5,7 +5,7 @@ use zombienet_sdk::OrchestratorError; #[derive(Error, Debug)] pub enum Error { - #[error("User aborted due to existing target folder.")] + #[error("User aborted due to existing target directory.")] Aborted, #[error("Anyhow error: {0}")] AnyhowError(#[from] anyhow::Error), diff --git a/crates/pop-parachains/src/lib.rs b/crates/pop-parachains/src/lib.rs index 86192db5..dc23fcc9 100644 --- a/crates/pop-parachains/src/lib.rs +++ b/crates/pop-parachains/src/lib.rs @@ -20,7 +20,6 @@ pub use new_pallet::{create_pallet_template, TemplatePalletConfig}; pub use new_parachain::instantiate_template_dir; pub use templates::{Config, Parachain, Provider}; pub use up::Zombienet; -pub use utils::helpers::is_initial_endowment_valid; -pub use utils::pallet_helpers::resolve_pallet_path; +pub use utils::{helpers::is_initial_endowment_valid, pallet_helpers::resolve_pallet_path}; /// Information about the Node. External export from Zombienet-SDK. pub use zombienet_sdk::NetworkNode; diff --git a/crates/pop-parachains/src/new_pallet.rs b/crates/pop-parachains/src/new_pallet.rs index 00b4e8ab..a16c7689 100644 --- a/crates/pop-parachains/src/new_pallet.rs +++ b/crates/pop-parachains/src/new_pallet.rs @@ -2,8 +2,8 @@ use std::{fs, path::PathBuf}; -use crate::errors::Error; use crate::{ + errors::Error, generator::pallet::{ PalletBenchmarking, PalletCargoToml, PalletItem, PalletLib, PalletMock, PalletTests, PalletWeights, @@ -39,7 +39,7 @@ pub fn create_pallet_template( Ok(()) } -/// Generate a pallet folder and file structure +/// Generate a pallet directory and file structure fn generate_pallet_structure(target: &PathBuf, pallet_name: &str) -> Result<(), Error> { use fs::{create_dir, File}; let (pallet, src) = (target.join(pallet_name), target.join(pallet_name.to_string() + "/src")); @@ -100,8 +100,8 @@ mod tests { // Assert that the pallet structure is generated let pallet_path = temp_dir.path().join(pallet_name); - assert!(pallet_path.exists(), "Pallet folder should be created"); - assert!(pallet_path.join("src").exists(), "src folder should be created"); + assert!(pallet_path.exists(), "Pallet directory should be created"); + assert!(pallet_path.join("src").exists(), "src directory should be created"); assert!(pallet_path.join("Cargo.toml").exists(), "Cargo.toml should be created"); assert!(pallet_path.join("src").join("lib.rs").exists(), "lib.rs should be created"); assert!( diff --git a/crates/pop-parachains/src/templates.rs b/crates/pop-parachains/src/templates.rs index 242ef7a2..83342308 100644 --- a/crates/pop-parachains/src/templates.rs +++ b/crates/pop-parachains/src/templates.rs @@ -104,7 +104,8 @@ pub enum Parachain { ) )] Contracts, - /// Parachain configured with Frontier, enabling compatibility with the Ethereum Virtual Machine (EVM). + /// Parachain configured with Frontier, enabling compatibility with the Ethereum Virtual + /// Machine (EVM). #[strum( serialize = "evm", message = "EVM", @@ -195,7 +196,8 @@ impl Parachain { } pub fn is_supported_version(&self, version: &str) -> bool { - // if `SupportedVersion` is None, then all versions are supported. Otherwise, ensure version is present. + // if `SupportedVersion` is None, then all versions are supported. Otherwise, ensure version + // is present. self.supported_versions().map_or(true, |versions| versions.contains(&version)) } diff --git a/crates/pop-parachains/src/up/mod.rs b/crates/pop-parachains/src/up/mod.rs index be1e618c..390e990a 100644 --- a/crates/pop-parachains/src/up/mod.rs +++ b/crates/pop-parachains/src/up/mod.rs @@ -39,10 +39,14 @@ impl Zombienet { /// # Arguments /// * `cache` - The location used for caching binaries. /// * `network_config` - The configuration file to be used to launch a network. - /// * `relay_chain_version` - The specific binary version used for the relay chain (`None` will use the latest available version). - /// * `relay_chain_runtime_version` - The specific runtime version used for the relay chain runtime (`None` will use the latest available version). - /// * `system_parachain_version` - The specific binary version used for system parachains (`None` will use the latest available version). - /// * `system_parachain_runtime_version` - The specific runtime version used for system parachains (`None` will use the latest available version). + /// * `relay_chain_version` - The specific binary version used for the relay chain (`None` will + /// use the latest available version). + /// * `relay_chain_runtime_version` - The specific runtime version used for the relay chain + /// runtime (`None` will use the latest available version). + /// * `system_parachain_version` - The specific binary version used for system parachains + /// (`None` will use the latest available version). + /// * `system_parachain_runtime_version` - The specific runtime version used for system + /// parachains (`None` will use the latest available version). /// * `parachains` - The parachain(s) specified. pub async fn new( cache: &Path, @@ -100,8 +104,10 @@ impl Zombienet { /// /// # Arguments /// * `relay_chain` - The configuration required to launch the relay chain. - /// * `system_parachain_version` - The specific binary version used for system parachains (`None` will use the latest available version). - /// * `system_parachain_runtime_version` - The specific runtime version used for system parachains (`None` will use the latest available version). + /// * `system_parachain_version` - The specific binary version used for system parachains + /// (`None` will use the latest available version). + /// * `system_parachain_runtime_version` - The specific runtime version used for system + /// parachains (`None` will use the latest available version). /// * `parachains` - The parachain repositories specified. /// * `network_config` - The network configuration to be used to launch a network. /// * `cache` - The location used for caching binaries. @@ -203,8 +209,10 @@ impl Zombienet { /// Determines relay chain configuration based on specified version and network configuration. /// /// # Arguments - /// * `version` - The specific binary version used for the relay chain (`None` will use the latest available version). - /// * `runtime_version` - The specific runtime version used for the relay chain runtime (`None` will use the latest available version). + /// * `version` - The specific binary version used for the relay chain (`None` will use the + /// latest available version). + /// * `runtime_version` - The specific runtime version used for the relay chain runtime (`None` + /// will use the latest available version). /// * `network_config` - The network configuration to be used to launch a network. /// * `cache` - The location used for caching binaries. async fn relay_chain( @@ -524,7 +532,8 @@ impl Parachain { }) } - /// Initializes the configuration required to launch a parachain using a binary sourced from the specified repository. + /// Initializes the configuration required to launch a parachain using a binary sourced from the + /// specified repository. /// /// # Arguments /// * `id` - The parachain identifier on the local network. @@ -644,8 +653,7 @@ fn resolve_manifest(package: &str, path: &Path) -> Result, Error mod tests { use super::*; use anyhow::Result; - use std::env::current_dir; - use std::{fs::File, io::Write}; + use std::{env::current_dir, fs::File, io::Write}; use tempfile::tempdir; mod zombienet { @@ -1434,10 +1442,9 @@ validator = true mod network_config { use super::*; - use std::io::Read; use std::{ fs::{create_dir_all, File}, - io::Write, + io::{Read, Write}, path::PathBuf, }; use tempfile::{tempdir, Builder}; diff --git a/crates/pop-parachains/src/utils/helpers.rs b/crates/pop-parachains/src/utils/helpers.rs index 5e735762..7a27b87e 100644 --- a/crates/pop-parachains/src/utils/helpers.rs +++ b/crates/pop-parachains/src/utils/helpers.rs @@ -9,7 +9,7 @@ use std::{ pub(crate) fn sanitize(target: &Path) -> Result<(), Error> { if target.exists() { - print!("\"{}\" folder exists. Do you want to clean it? [y/n]: ", target.display()); + print!("\"{}\" directory exists. Do you want to clean it? [y/n]: ", target.display()); stdout().flush()?; let mut input = String::new();