From 60a2fb62d4f181e9007c233fcfb08e2c9be17742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Senovilla=20Polo?= Date: Tue, 20 Aug 2024 18:53:40 +0200 Subject: [PATCH 1/2] Refactor of ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d18ff599..0b6cf688 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v4 - name: Check formatting - run: cargo fmt --all -- --check + run: cargo +nightly fmt --all -- --check build: needs: lint From 5ec1388aa6625fb76ea63c16acf5efd1b5053a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Senovilla=20Polo?= Date: Tue, 20 Aug 2024 19:08:52 +0200 Subject: [PATCH 2/2] Updating all files to be formated with nightly --- .github/workflows/ci.yml | 8 ++++ crates/pop-cli/src/commands/build/contract.rs | 4 +- crates/pop-cli/src/commands/build/mod.rs | 3 +- crates/pop-cli/src/commands/build/spec.rs | 28 +++++++------- crates/pop-cli/src/commands/install/mod.rs | 5 +-- crates/pop-cli/src/commands/mod.rs | 6 ++- crates/pop-cli/src/commands/new/contract.rs | 2 +- crates/pop-cli/src/commands/new/parachain.rs | 12 +++--- crates/pop-cli/src/commands/up/contract.rs | 16 ++++---- crates/pop-cli/src/commands/up/parachain.rs | 21 +++++----- crates/pop-cli/src/common/contracts.rs | 3 +- crates/pop-cli/src/main.rs | 3 +- crates/pop-cli/tests/contract.rs | 3 +- crates/pop-cli/tests/parachain.rs | 3 +- crates/pop-common/src/helpers.rs | 8 ++-- crates/pop-common/src/lib.rs | 10 ++--- crates/pop-common/src/manifest.rs | 6 ++- crates/pop-common/src/sourcing/binary.rs | 36 +++++++++--------- crates/pop-common/src/sourcing/mod.rs | 21 +++++----- crates/pop-contracts/src/build.rs | 6 ++- crates/pop-contracts/src/call.rs | 4 -- crates/pop-contracts/src/new.rs | 6 ++- crates/pop-contracts/src/node/mod.rs | 9 ++--- crates/pop-contracts/src/test.rs | 3 +- crates/pop-contracts/src/up.rs | 3 +- crates/pop-contracts/src/utils/helpers.rs | 2 - crates/pop-parachains/src/build.rs | 19 ++++++---- crates/pop-parachains/src/lib.rs | 3 +- crates/pop-parachains/src/new_pallet.rs | 2 +- crates/pop-parachains/src/templates.rs | 6 ++- crates/pop-parachains/src/up/mod.rs | 38 +++++++++++-------- crates/pop-parachains/src/utils/helpers.rs | 4 +- 32 files changed, 167 insertions(+), 136 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b6cf688..71f4703c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,14 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install Rust nightly + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + profile: minimal + components: rustfmt + override: true + - name: Check formatting run: cargo +nightly fmt --all -- --check 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/spec.rs b/crates/pop-cli/src/commands/build/spec.rs index 0a1c8745..f8db513c 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; @@ -366,13 +370,13 @@ async fn guide_user_to_generate_spec(args: BuildSpecCommand) -> anyhow::Result { + ChainType::Live => for relay in RelayChain::VARIANTS { if !matches!( relay, - RelayChain::Westend - | RelayChain::Paseo | RelayChain::Kusama - | RelayChain::Polkadot + RelayChain::Westend | + RelayChain::Paseo | RelayChain::Kusama | + RelayChain::Polkadot ) { continue; } else { @@ -382,15 +386,14 @@ async fn guide_user_to_generate_spec(args: BuildSpecCommand) -> anyhow::Result { + }, + _ => for relay in RelayChain::VARIANTS { if matches!( relay, - RelayChain::Westend - | RelayChain::Paseo | RelayChain::Kusama - | RelayChain::Polkadot + RelayChain::Westend | + RelayChain::Paseo | RelayChain::Kusama | + RelayChain::Polkadot ) { continue; } else { @@ -400,8 +403,7 @@ async fn guide_user_to_generate_spec(args: BuildSpecCommand) -> anyhow::Result anyhow::Result<()> { async fn install_homebrew() -> anyhow::Result<()> { match cmd("which", vec!["brew"]).read() { Ok(output) => log::info(format!("ℹ️ Homebrew installed already at {}.", output))?, - Err(_) => { + Err(_) => run_external_script( "https://raw.githubusercontent.com/Homebrew/install/master/install.sh", ) - .await? - }, + .await?, } Ok(()) } 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..55e915d3 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)?; @@ -239,8 +241,8 @@ fn get_customization_value( decimals: Option, initial_endowment: Option, ) -> Result { - if !matches!(template, Parachain::Standard) - && (symbol.is_some() || decimals.is_some() || initial_endowment.is_some()) + if !matches!(template, Parachain::Standard) && + (symbol.is_some() || decimals.is_some() || initial_endowment.is_some()) { log::warning("Customization options are not available for this template")?; sleep(Duration::from_secs(3)) diff --git a/crates/pop-cli/src/commands/up/contract.rs b/crates/pop-cli/src/commands/up/contract.rs index bf24cf73..ccc1fc82 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; @@ -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, } @@ -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)) { @@ -324,8 +326,8 @@ pub fn has_contract_been_built(path: Option<&Path>) -> bool { Err(_) => return false, }; let contract_name = manifest.package().name(); - project_path.join("target/ink").exists() - && project_path.join(format!("target/ink/{}.contract", contract_name)).exists() + project_path.join("target/ink").exists() && + project_path.join(format!("target/ink/{}.contract", contract_name)).exists() } #[cfg(test)] diff --git a/crates/pop-cli/src/commands/up/parachain.rs b/crates/pop-cli/src/commands/up/parachain.rs index a59d8284..e68d20a1 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'). @@ -71,7 +71,7 @@ impl ZombienetCommand { .await { Ok(n) => n, - Err(e) => { + Err(e) => return match e { Error::Config(message) => { outro_cancel(format!("🚫 A configuration error occurred: `{message}`"))?; @@ -82,8 +82,7 @@ impl ZombienetCommand { Ok(()) }, _ => Err(e.into()), - } - }, + }, }; // Source any missing/stale binaries 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..04768fe2 100644 --- a/crates/pop-cli/tests/contract.rs +++ b/crates/pop-cli/tests/contract.rs @@ -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 a261fd89..4cc06342 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/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..1d036769 100644 --- a/crates/pop-common/src/lib.rs +++ b/crates/pop-common/src/lib.rs @@ -33,18 +33,16 @@ pub fn target() -> Result<&'static str, Error> { } match ARCH { - "aarch64" => { + "aarch64" => return match OS { "macos" => Ok("aarch64-apple-darwin"), _ => Ok("aarch64-unknown-linux-gnu"), - } - }, - "x86_64" | "x86" => { + }, + "x86_64" | "x86" => return match OS { "macos" => Ok("x86_64-apple-darwin"), _ => Ok("x86_64-unknown-linux-gnu"), - } - }, + }, &_ => {}, } Err(Error::UnsupportedPlatform { arch: ARCH, os: OS }) 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..ae9bd5f9 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, }; @@ -43,13 +45,12 @@ impl Binary { pub fn latest(&self) -> Option<&str> { match self { Self::Local { .. } => None, - Self::Source { source, .. } => { + Self::Source { source, .. } => if let GitHub(ReleaseArchive { latest, .. }) = source { latest.as_deref() } else { None - } - }, + }, } } @@ -85,13 +86,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 +122,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( @@ -131,18 +134,15 @@ impl Binary { ) -> Result<(), Error> { match self { Self::Local { name, path, manifest, .. } => match manifest { - None => { + None => return Err(Error::MissingBinary(format!( "The {path:?} binary cannot be sourced automatically." - ))) - }, - Some(manifest) => { - from_local_package(manifest, name, release, status, verbose).await - }, - }, - Self::Source { source, cache, .. } => { - source.source(cache, release, status, verbose).await + ))), + Some(manifest) => + from_local_package(manifest, name, release, status, verbose).await, }, + Self::Source { source, cache, .. } => + source.source(cache, release, status, verbose).await, } } diff --git a/crates/pop-common/src/sourcing/mod.rs b/crates/pop-common/src/sourcing/mod.rs index ea925ef4..81d0bc3f 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( @@ -208,9 +210,8 @@ impl GitHub { let artifacts: Vec<_> = artifacts .iter() .map(|name| match reference { - Some(reference) => { - (name.as_str(), cache.join(&format!("{name}-{reference}"))) - }, + Some(reference) => + (name.as_str(), cache.join(&format!("{name}-{reference}"))), None => (name.as_str(), cache.join(&name)), }) .collect(); @@ -377,13 +378,13 @@ async fn from_github_archive( // Prepare archive contents for build let entries: Vec<_> = read_dir(&working_dir)?.take(2).filter_map(|x| x.ok()).collect(); match entries.len() { - 0 => { + 0 => return Err(Error::ArchiveError( "The downloaded archive does not contain any entries.".into(), - )) - }, + )), 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-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..d2eb881b 100644 --- a/crates/pop-contracts/src/call.rs +++ b/crates/pop-contracts/src/call.rs @@ -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, diff --git a/crates/pop-contracts/src/new.rs b/crates/pop-contracts/src/new.rs index 13232a74..09410a91 100644 --- a/crates/pop-contracts/src/new.rs +++ b/crates/pop-contracts/src/new.rs @@ -9,8 +9,10 @@ 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 std::{ + collections::HashMap, + path::{Path, PathBuf}, +}; use url::Url; /// Create a new smart contract. diff --git a/crates/pop-contracts/src/node/mod.rs b/crates/pop-contracts/src/node/mod.rs index 8353d158..9ecb6c14 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 { @@ -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>, diff --git a/crates/pop-contracts/src/test.rs b/crates/pop-contracts/src/test.rs index 5bc9a968..dfbf97a5 100644 --- a/crates/pop-contracts/src/test.rs +++ b/crates/pop-contracts/src/test.rs @@ -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..9faf94c8 100644 --- a/crates/pop-contracts/src/up.rs +++ b/crates/pop-contracts/src/up.rs @@ -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..e29f5a9b 100644 --- a/crates/pop-contracts/src/utils/helpers.rs +++ b/crates/pop-contracts/src/utils/helpers.rs @@ -38,7 +38,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 @@ -52,7 +51,6 @@ pub fn canonicalized_path(target: &Path) -> Result { /// /// * `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)? { diff --git a/crates/pop-parachains/src/build.rs b/crates/pop-parachains/src/build.rs index dc899af8..f161ff1d 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, @@ -39,15 +41,16 @@ pub fn build_parachain( /// 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 const DEPENDENCIES: [&str; 4] = ["cumulus-client-collator", "cumulus-primitives-core", "parachains-common", "polkadot-sdk"]; Ok(DEPENDENCIES.into_iter().any(|d| { - manifest.dependencies.contains_key(d) - || manifest.workspace.as_ref().map_or(false, |w| w.dependencies.contains_key(d)) + manifest.dependencies.contains_key(d) || + manifest.workspace.as_ref().map_or(false, |w| w.dependencies.contains_key(d)) })) } @@ -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( 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..441db4f7 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, 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..192da7ff 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( @@ -244,13 +252,12 @@ impl Zombienet { if let Some(command) = NetworkConfiguration::command(node).and_then(|c| c.as_str()) { match &relay { - Some(relay) => { + Some(relay) => if command.to_lowercase() != relay.binary.name() { return Err(Error::UnsupportedCommand(format!( "the relay chain command is unsupported: {command}", ))); - } - }, + }, None => { relay = Some( relay::from(command, version, runtime_version, chain, cache) @@ -524,7 +531,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 +652,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 +1441,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..1348158b 100644 --- a/crates/pop-parachains/src/utils/helpers.rs +++ b/crates/pop-parachains/src/utils/helpers.rs @@ -30,8 +30,8 @@ pub(crate) fn sanitize(target: &Path) -> Result<(), Error> { /// /// * `initial_endowment` - initial endowment amount to be checked for validity. pub fn is_initial_endowment_valid(initial_endowment: &str) -> bool { - initial_endowment.parse::().is_ok() - || is_valid_bitwise_left_shift(initial_endowment).is_ok() + initial_endowment.parse::().is_ok() || + is_valid_bitwise_left_shift(initial_endowment).is_ok() } // Auxiliar method to check if the endowment input with a shift left (1u64 << 60) format is valid. // Parse the self << rhs format and check the shift left operation is valid.