From ec6a319012b0b4fcee33cdb6df829b4101d95334 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 3 Dec 2024 10:46:38 +0900 Subject: [PATCH 01/14] pop -p arg --- crates/pop-cli/src/commands/build/mod.rs | 2 +- crates/pop-cli/src/commands/build/parachain.rs | 2 +- crates/pop-cli/src/commands/call/contract.rs | 2 +- crates/pop-cli/src/commands/up/contract.rs | 2 +- crates/pop-cli/tests/contract.rs | 11 ++++++++++- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/pop-cli/src/commands/build/mod.rs b/crates/pop-cli/src/commands/build/mod.rs index 08af079bd..814805d79 100644 --- a/crates/pop-cli/src/commands/build/mod.rs +++ b/crates/pop-cli/src/commands/build/mod.rs @@ -26,7 +26,7 @@ pub(crate) struct BuildArgs { #[arg(long)] pub(crate) path: Option, /// The package to be built. - #[arg(short = 'p', long)] + #[arg(short = 'p', long, default_value = None)] pub(crate) package: Option, /// For production, always build in release mode to exclude debug features. #[clap(short, long)] diff --git a/crates/pop-cli/src/commands/build/parachain.rs b/crates/pop-cli/src/commands/build/parachain.rs index a6e47c677..3c0ca66f9 100644 --- a/crates/pop-cli/src/commands/build/parachain.rs +++ b/crates/pop-cli/src/commands/build/parachain.rs @@ -14,7 +14,7 @@ pub struct BuildParachainCommand { #[arg(long)] pub(crate) path: Option, /// The package to be built. - #[arg(short = 'p', long)] + #[arg(short = 'p', long, default_value = None)] pub(crate) package: Option, /// For production, always build in release mode to exclude debug features. #[clap(short, long, default_value = "true")] diff --git a/crates/pop-cli/src/commands/call/contract.rs b/crates/pop-cli/src/commands/call/contract.rs index 4e00e37b5..1730e8125 100644 --- a/crates/pop-cli/src/commands/call/contract.rs +++ b/crates/pop-cli/src/commands/call/contract.rs @@ -42,7 +42,7 @@ pub struct CallContractCommand { gas_limit: Option, /// Maximum proof size for this command. /// If not specified it will perform a dry-run to estimate the proof size required. - #[arg(short = 'P', long)] + #[arg(short = 'P', long, default_value = None)] proof_size: Option, /// Websocket endpoint of a node. #[arg(name = "url", short, long, value_parser, default_value = DEFAULT_URL)] diff --git a/crates/pop-cli/src/commands/up/contract.rs b/crates/pop-cli/src/commands/up/contract.rs index 3b7353b35..a7c19787e 100644 --- a/crates/pop-cli/src/commands/up/contract.rs +++ b/crates/pop-cli/src/commands/up/contract.rs @@ -29,7 +29,7 @@ const FAILED: &str = "🚫 Deployment failed."; #[derive(Args, Clone)] pub struct UpContractCommand { /// Path to the contract build directory. - #[arg(short = 'p', long)] + #[arg(short = 'p', long, default_value = None)] path: Option, /// The name of the contract constructor to call. #[clap(name = "constructor", long, default_value = "new")] diff --git a/crates/pop-cli/tests/contract.rs b/crates/pop-cli/tests/contract.rs index 3a51f1223..1fec718a3 100644 --- a/crates/pop-cli/tests/contract.rs +++ b/crates/pop-cli/tests/contract.rs @@ -29,12 +29,21 @@ async fn contract_lifecycle() -> Result<()> { assert!(temp_dir.join("test_contract").exists()); // pop build --path ./test_contract --release - Command::cargo_bin("pop") + /*Command::cargo_bin("pop") .unwrap() .current_dir(&temp_dir) .args(&["build", "--path", "./test_contract", "--release"]) .assert() + .success();*/ + + // pop build ./test_contract --release + Command::cargo_bin("pop") + .unwrap() + .current_dir(&temp_dir) + .args(&["build", "./test_contract", "--release"]) + .assert() .success(); + // Verify that the directory target has been created assert!(temp_dir.join("test_contract/target").exists()); // Verify that all the artifacts has been generated From a32b326ac50ed68334b7db999185a1e96ffc3fd5 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 3 Dec 2024 22:13:17 +0900 Subject: [PATCH 02/14] pop build & pop up completed --- crates/pop-cli/src/commands/build/contract.rs | 18 +++++++++++--- crates/pop-cli/src/commands/build/mod.rs | 21 ++++++++++++---- crates/pop-cli/src/commands/up/contract.rs | 24 +++++++++++++------ crates/pop-cli/tests/contract.rs | 10 ++++---- 4 files changed, 55 insertions(+), 18 deletions(-) diff --git a/crates/pop-cli/src/commands/build/contract.rs b/crates/pop-cli/src/commands/build/contract.rs index ca0cdd739..f0f63ee67 100644 --- a/crates/pop-cli/src/commands/build/contract.rs +++ b/crates/pop-cli/src/commands/build/contract.rs @@ -10,8 +10,11 @@ use std::{thread::sleep, time::Duration}; #[derive(Args)] pub struct BuildContractCommand { /// Path for the contract project [default: current directory] - #[arg(long)] + /// Directory path for your project [default: current directory] + #[arg(long,required = false)] pub(crate) path: Option, + #[arg(value_name = "PATH",required = false)] + pub(crate) path1: Option, /// 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)] @@ -42,8 +45,17 @@ impl BuildContractCommand { } // Build contract. + println!("what we have:{:?}",std::env::args().nth(2)); + let contract_path = match self.path { + Some(ref path) if path.to_str().unwrap_or("null").contains("./")=> path, + _ => { + // If no path is provided, assume it's the first positional argument + + &self.path1.unwrap_or("null".into()) + } + }; let build_result = - build_smart_contract(self.path.as_deref(), self.release, Verbosity::Default)?; + build_smart_contract(Some(contract_path).as_deref().map(|v| &**v), self.release, Verbosity::Default)?; cli.success(build_result.display())?; cli.outro("Build completed successfully!")?; Ok("contract") @@ -76,7 +88,7 @@ mod tests { } assert_eq!( - BuildContractCommand { path: Some(path.join(name)), release, valid } + BuildContractCommand { path: Some(path.join(name)), path1: Some(path.join(name)), release, valid } .build(&mut cli)?, "contract" ); diff --git a/crates/pop-cli/src/commands/build/mod.rs b/crates/pop-cli/src/commands/build/mod.rs index 814805d79..4c7dedb6c 100644 --- a/crates/pop-cli/src/commands/build/mod.rs +++ b/crates/pop-cli/src/commands/build/mod.rs @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0 use crate::cli::{self, Cli}; +use anyhow::ensure; use clap::{Args, Subcommand}; #[cfg(feature = "contract")] use contract::BuildContractCommand; @@ -23,10 +24,12 @@ pub(crate) struct BuildArgs { #[command(subcommand)] pub command: Option, /// Directory path for your project [default: current directory] - #[arg(long)] + #[arg(long,required = false)] pub(crate) path: Option, + #[arg(value_name = "PATH",required = false)] + pub(crate) path1: Option, /// The package to be built. - #[arg(short = 'p', long, default_value = None)] + #[arg(short = 'p', long)] pub(crate) package: Option, /// For production, always build in release mode to exclude debug features. #[clap(short, long)] @@ -59,10 +62,19 @@ impl Command { /// Executes the command. pub(crate) fn execute(args: BuildArgs) -> anyhow::Result<&'static str> { // If only contract feature enabled, build as contract + let path0 = args.path.clone(); + let path1 = args.path1.clone(); + let project_path = match path0 { + Some(ref path) if path.to_str().unwrap().contains("./")=> Some(path.to_owned()), + _ => { + ensure!(path1.is_some()); + path1 + } + }; #[cfg(feature = "contract")] - if pop_contracts::is_supported(args.path.as_deref())? { + if pop_contracts::is_supported(project_path.as_deref())? { // All commands originating from root command are valid - BuildContractCommand { path: args.path, release: args.release, valid: true } + BuildContractCommand { path: project_path.clone(), path1:project_path, release: args.release, valid: true } .execute()?; return Ok("contract"); } @@ -139,6 +151,7 @@ mod tests { BuildArgs { command: None, path: Some(path.join(name)), + path1: Some(path.join(name)), package: package.clone(), release, id: None, diff --git a/crates/pop-cli/src/commands/up/contract.rs b/crates/pop-cli/src/commands/up/contract.rs index a7c19787e..ab0c2f4c2 100644 --- a/crates/pop-cli/src/commands/up/contract.rs +++ b/crates/pop-cli/src/commands/up/contract.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0 use crate::{ - cli::{traits::Cli as _, Cli}, + cli::{traits::Cli as _, Cli}, common::contracts::{check_contracts_node_and_prompt, has_contract_been_built}, style::style, }; @@ -29,8 +29,10 @@ const FAILED: &str = "🚫 Deployment failed."; #[derive(Args, Clone)] pub struct UpContractCommand { /// Path to the contract build directory. - #[arg(short = 'p', long, default_value = None)] - path: Option, + #[arg(long,required = false)] + pub(crate) path: Option, + #[arg(value_name = "PATH",required = false)] + pub(crate) path1: Option, /// The name of the contract constructor to call. #[clap(name = "constructor", long, default_value = "new")] constructor: String, @@ -79,14 +81,21 @@ impl UpContractCommand { /// Executes the command. pub(crate) async fn execute(mut self) -> anyhow::Result<()> { Cli.intro("Deploy a smart contract")?; - + let path0 = self.path.clone(); + let path1 = self.path1.clone(); + let contract_path = match path0 { + Some(ref path) if path.to_str().unwrap().contains("./") => Some(path.to_owned()), + _ => { + path1 + } + }; // Check if build exists in the specified "Contract build directory" - if !has_contract_been_built(self.path.as_deref()) { + if !has_contract_been_built(contract_path.clone().as_deref()) { // Build the contract in release mode Cli.warning("NOTE: contract has not yet been built.")?; let spinner = spinner(); spinner.start("Building contract in RELEASE mode..."); - let result = match build_smart_contract(self.path.as_deref(), true, Verbosity::Quiet) { + let result = match build_smart_contract(contract_path.clone().as_deref(), true, Verbosity::Quiet) { Ok(result) => result, Err(e) => { Cli.outro_cancel(format!("🚫 An error occurred building your contract: {e}\nUse `pop build` to retry with build output."))?; @@ -179,7 +188,7 @@ impl UpContractCommand { // Otherwise instantiate. let instantiate_exec = match set_up_deployment(UpOpts { - path: self.path.clone(), + path: contract_path.clone(), constructor: self.constructor.clone(), args: self.args.clone(), value: self.value.clone(), @@ -338,6 +347,7 @@ mod tests { fn conversion_up_contract_command_to_up_opts_works() -> anyhow::Result<()> { let command = UpContractCommand { path: None, + path1: None, constructor: "new".to_string(), args: vec![], value: "0".to_string(), diff --git a/crates/pop-cli/tests/contract.rs b/crates/pop-cli/tests/contract.rs index 1fec718a3..b4d4af4e3 100644 --- a/crates/pop-cli/tests/contract.rs +++ b/crates/pop-cli/tests/contract.rs @@ -29,20 +29,22 @@ async fn contract_lifecycle() -> Result<()> { assert!(temp_dir.join("test_contract").exists()); // pop build --path ./test_contract --release - /*Command::cargo_bin("pop") + Command::cargo_bin("pop") .unwrap() .current_dir(&temp_dir) .args(&["build", "--path", "./test_contract", "--release"]) .assert() - .success();*/ + .success(); // pop build ./test_contract --release - Command::cargo_bin("pop") + /*Command::cargo_bin("pop") .unwrap() .current_dir(&temp_dir) .args(&["build", "./test_contract", "--release"]) .assert() - .success(); + .success();*/ + + println!("Contract built!!"); // Verify that the directory target has been created assert!(temp_dir.join("test_contract/target").exists()); From bf47993174a5f393215c57bfa871c7bf599137ec Mon Sep 17 00:00:00 2001 From: ndkazu Date: Fri, 6 Dec 2024 13:42:29 +0900 Subject: [PATCH 03/14] re-starting from scratch --- crates/pop-cli/src/commands/build/contract.rs | 18 +++------------ crates/pop-cli/src/commands/build/mod.rs | 19 +++------------- .../pop-cli/src/commands/build/parachain.rs | 2 +- crates/pop-cli/src/commands/call/contract.rs | 2 +- crates/pop-cli/src/commands/up/contract.rs | 22 +++++-------------- 5 files changed, 14 insertions(+), 49 deletions(-) diff --git a/crates/pop-cli/src/commands/build/contract.rs b/crates/pop-cli/src/commands/build/contract.rs index f0f63ee67..ca0cdd739 100644 --- a/crates/pop-cli/src/commands/build/contract.rs +++ b/crates/pop-cli/src/commands/build/contract.rs @@ -10,11 +10,8 @@ use std::{thread::sleep, time::Duration}; #[derive(Args)] pub struct BuildContractCommand { /// Path for the contract project [default: current directory] - /// Directory path for your project [default: current directory] - #[arg(long,required = false)] + #[arg(long)] pub(crate) path: Option, - #[arg(value_name = "PATH",required = false)] - pub(crate) path1: Option, /// 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)] @@ -45,17 +42,8 @@ impl BuildContractCommand { } // Build contract. - println!("what we have:{:?}",std::env::args().nth(2)); - let contract_path = match self.path { - Some(ref path) if path.to_str().unwrap_or("null").contains("./")=> path, - _ => { - // If no path is provided, assume it's the first positional argument - - &self.path1.unwrap_or("null".into()) - } - }; let build_result = - build_smart_contract(Some(contract_path).as_deref().map(|v| &**v), self.release, Verbosity::Default)?; + build_smart_contract(self.path.as_deref(), self.release, Verbosity::Default)?; cli.success(build_result.display())?; cli.outro("Build completed successfully!")?; Ok("contract") @@ -88,7 +76,7 @@ mod tests { } assert_eq!( - BuildContractCommand { path: Some(path.join(name)), path1: Some(path.join(name)), release, valid } + BuildContractCommand { path: Some(path.join(name)), release, valid } .build(&mut cli)?, "contract" ); diff --git a/crates/pop-cli/src/commands/build/mod.rs b/crates/pop-cli/src/commands/build/mod.rs index 4c7dedb6c..08af079bd 100644 --- a/crates/pop-cli/src/commands/build/mod.rs +++ b/crates/pop-cli/src/commands/build/mod.rs @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0 use crate::cli::{self, Cli}; -use anyhow::ensure; use clap::{Args, Subcommand}; #[cfg(feature = "contract")] use contract::BuildContractCommand; @@ -24,10 +23,8 @@ pub(crate) struct BuildArgs { #[command(subcommand)] pub command: Option, /// Directory path for your project [default: current directory] - #[arg(long,required = false)] + #[arg(long)] pub(crate) path: Option, - #[arg(value_name = "PATH",required = false)] - pub(crate) path1: Option, /// The package to be built. #[arg(short = 'p', long)] pub(crate) package: Option, @@ -62,19 +59,10 @@ impl Command { /// Executes the command. pub(crate) fn execute(args: BuildArgs) -> anyhow::Result<&'static str> { // If only contract feature enabled, build as contract - let path0 = args.path.clone(); - let path1 = args.path1.clone(); - let project_path = match path0 { - Some(ref path) if path.to_str().unwrap().contains("./")=> Some(path.to_owned()), - _ => { - ensure!(path1.is_some()); - path1 - } - }; #[cfg(feature = "contract")] - if pop_contracts::is_supported(project_path.as_deref())? { + if pop_contracts::is_supported(args.path.as_deref())? { // All commands originating from root command are valid - BuildContractCommand { path: project_path.clone(), path1:project_path, release: args.release, valid: true } + BuildContractCommand { path: args.path, release: args.release, valid: true } .execute()?; return Ok("contract"); } @@ -151,7 +139,6 @@ mod tests { BuildArgs { command: None, path: Some(path.join(name)), - path1: Some(path.join(name)), package: package.clone(), release, id: None, diff --git a/crates/pop-cli/src/commands/build/parachain.rs b/crates/pop-cli/src/commands/build/parachain.rs index 3c0ca66f9..a6e47c677 100644 --- a/crates/pop-cli/src/commands/build/parachain.rs +++ b/crates/pop-cli/src/commands/build/parachain.rs @@ -14,7 +14,7 @@ pub struct BuildParachainCommand { #[arg(long)] pub(crate) path: Option, /// The package to be built. - #[arg(short = 'p', long, default_value = None)] + #[arg(short = 'p', long)] pub(crate) package: Option, /// For production, always build in release mode to exclude debug features. #[clap(short, long, default_value = "true")] diff --git a/crates/pop-cli/src/commands/call/contract.rs b/crates/pop-cli/src/commands/call/contract.rs index 1730e8125..4e00e37b5 100644 --- a/crates/pop-cli/src/commands/call/contract.rs +++ b/crates/pop-cli/src/commands/call/contract.rs @@ -42,7 +42,7 @@ pub struct CallContractCommand { gas_limit: Option, /// Maximum proof size for this command. /// If not specified it will perform a dry-run to estimate the proof size required. - #[arg(short = 'P', long, default_value = None)] + #[arg(short = 'P', long)] proof_size: Option, /// Websocket endpoint of a node. #[arg(name = "url", short, long, value_parser, default_value = DEFAULT_URL)] diff --git a/crates/pop-cli/src/commands/up/contract.rs b/crates/pop-cli/src/commands/up/contract.rs index ab0c2f4c2..f00950140 100644 --- a/crates/pop-cli/src/commands/up/contract.rs +++ b/crates/pop-cli/src/commands/up/contract.rs @@ -29,10 +29,8 @@ const FAILED: &str = "🚫 Deployment failed."; #[derive(Args, Clone)] pub struct UpContractCommand { /// Path to the contract build directory. - #[arg(long,required = false)] - pub(crate) path: Option, - #[arg(value_name = "PATH",required = false)] - pub(crate) path1: Option, + #[arg(short = 'p', long)] + path: Option, /// The name of the contract constructor to call. #[clap(name = "constructor", long, default_value = "new")] constructor: String, @@ -81,21 +79,14 @@ impl UpContractCommand { /// Executes the command. pub(crate) async fn execute(mut self) -> anyhow::Result<()> { Cli.intro("Deploy a smart contract")?; - let path0 = self.path.clone(); - let path1 = self.path1.clone(); - let contract_path = match path0 { - Some(ref path) if path.to_str().unwrap().contains("./") => Some(path.to_owned()), - _ => { - path1 - } - }; + // Check if build exists in the specified "Contract build directory" - if !has_contract_been_built(contract_path.clone().as_deref()) { + if !has_contract_been_built(self.path.as_deref()) { // Build the contract in release mode Cli.warning("NOTE: contract has not yet been built.")?; let spinner = spinner(); spinner.start("Building contract in RELEASE mode..."); - let result = match build_smart_contract(contract_path.clone().as_deref(), true, Verbosity::Quiet) { + let result = match build_smart_contract(self.path.as_deref(), true, Verbosity::Quiet) { Ok(result) => result, Err(e) => { Cli.outro_cancel(format!("🚫 An error occurred building your contract: {e}\nUse `pop build` to retry with build output."))?; @@ -188,7 +179,7 @@ impl UpContractCommand { // Otherwise instantiate. let instantiate_exec = match set_up_deployment(UpOpts { - path: contract_path.clone(), + path: self.path.clone(), constructor: self.constructor.clone(), args: self.args.clone(), value: self.value.clone(), @@ -347,7 +338,6 @@ mod tests { fn conversion_up_contract_command_to_up_opts_works() -> anyhow::Result<()> { let command = UpContractCommand { path: None, - path1: None, constructor: "new".to_string(), args: vec![], value: "0".to_string(), From 509ef3cc94ef4b896ae62d1e3243a99de421a512 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 7 Dec 2024 15:20:14 +0900 Subject: [PATCH 04/14] Cleaner version of first proposal --- crates/pop-cli/src/commands/build/mod.rs | 27 +++++++++++++++----- crates/pop-cli/src/commands/build/spec.rs | 4 +-- crates/pop-cli/src/commands/install/mod.rs | 5 ++-- crates/pop-cli/src/commands/new/pallet.rs | 10 ++++---- crates/pop-cli/src/commands/new/parachain.rs | 4 +-- crates/pop-cli/src/commands/up/contract.rs | 2 +- crates/pop-cli/src/commands/up/parachain.rs | 9 ++++--- crates/pop-cli/tests/contract.rs | 4 +-- 8 files changed, 41 insertions(+), 24 deletions(-) diff --git a/crates/pop-cli/src/commands/build/mod.rs b/crates/pop-cli/src/commands/build/mod.rs index f1a69c9c2..db8fd1115 100644 --- a/crates/pop-cli/src/commands/build/mod.rs +++ b/crates/pop-cli/src/commands/build/mod.rs @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-3.0 use crate::cli::{self, Cli}; -use clap::{Args, Subcommand}; +use anyhow::ensure; +use clap::{Args, Parser, Subcommand}; #[cfg(feature = "contract")] use contract::BuildContractCommand; use duct::cmd; @@ -23,9 +24,12 @@ pub(crate) mod spec; pub(crate) struct BuildArgs { #[command(subcommand)] pub command: Option, - /// Directory path for your project [default: current directory] + /// Directory path with flag for your project [default: current directory] #[arg(long)] pub(crate) path: Option, + /// Directory path without flag for your project [default: current directory] + #[arg(value_name = "PATH", required_unless_present = "path")] + pub(crate) path_pos: Option, /// The package to be built. #[arg(short = 'p', long)] pub(crate) package: Option, @@ -63,27 +67,37 @@ impl Command { /// Executes the command. pub(crate) fn execute(args: BuildArgs) -> anyhow::Result<&'static str> { // If only contract feature enabled, build as contract + let path_flag = args.path.clone(); + let path_pos = args.path_pos.clone(); + let project_path = match path_flag { + Some(ref path) if path.to_str().unwrap().contains("./") => Some(path.to_owned()), + _ => { + ensure!(path_pos.is_some(), "Failed to get directory!"); + path_pos + }, + }; + #[cfg(feature = "contract")] - if pop_contracts::is_supported(args.path.as_deref())? { + if pop_contracts::is_supported(project_path.as_deref())? { // All commands originating from root command are valid let release = match args.profile { Some(profile) => profile.into(), None => args.release, }; - BuildContractCommand { path: args.path, release, valid: true }.execute()?; + BuildContractCommand { path: project_path, release, valid: true }.execute()?; return Ok("contract"); } // If only parachain feature enabled, build as parachain #[cfg(feature = "parachain")] - if pop_parachains::is_supported(args.path.as_deref())? { + if pop_parachains::is_supported(project_path.as_deref())? { let profile = match args.profile { Some(profile) => profile, None => args.release.into(), }; // All commands originating from root command are valid BuildParachainCommand { - path: args.path, + path: project_path, package: args.package, profile: Some(profile), id: args.id, @@ -157,6 +171,7 @@ mod tests { BuildArgs { command: None, path: Some(project_path.clone()), + path_pos: Some(project_path.clone()), package: package.clone(), release, profile: Some(profile.clone()), diff --git a/crates/pop-cli/src/commands/build/spec.rs b/crates/pop-cli/src/commands/build/spec.rs index 3cde4c61e..0216f559b 100644 --- a/crates/pop-cli/src/commands/build/spec.rs +++ b/crates/pop-cli/src/commands/build/spec.rs @@ -226,8 +226,8 @@ impl BuildSpecCommand { // Output file. let maybe_chain_spec_file = PathBuf::from(&chain); // Check if the provided chain specification is a file. - let (output_file, prompt) = if maybe_chain_spec_file.exists() && - maybe_chain_spec_file.is_file() + let (output_file, prompt) = if maybe_chain_spec_file.exists() + && maybe_chain_spec_file.is_file() { if output_file.is_some() { cli.warning("NOTE: If an existing chain spec file is provided it will be used for the output path.")?; diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index 19b9fd3a2..fd6be9591 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -299,11 +299,12 @@ async fn install_rustup() -> 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/new/pallet.rs b/crates/pop-cli/src/commands/new/pallet.rs index ba47d49a4..338f1ef6c 100644 --- a/crates/pop-cli/src/commands/new/pallet.rs +++ b/crates/pop-cli/src/commands/new/pallet.rs @@ -84,11 +84,11 @@ impl NewPalletCommand { let mut pallet_custom_origin = false; if let Some(Mode::Advanced(advanced_mode_args)) = &self.mode { - if advanced_mode_args.config_common_types.is_empty() && - advanced_mode_args.storage.is_empty() && - !(advanced_mode_args.genesis_config || - advanced_mode_args.default_config || - advanced_mode_args.custom_origin) + if advanced_mode_args.config_common_types.is_empty() + && advanced_mode_args.storage.is_empty() + && !(advanced_mode_args.genesis_config + || advanced_mode_args.default_config + || advanced_mode_args.custom_origin) { Cli.info("Generate the pallet's config trait.")?; diff --git a/crates/pop-cli/src/commands/new/parachain.rs b/crates/pop-cli/src/commands/new/parachain.rs index e65035cfc..c33457ad7 100644 --- a/crates/pop-cli/src/commands/new/parachain.rs +++ b/crates/pop-cli/src/commands/new/parachain.rs @@ -268,8 +268,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 aefd267a2..964237642 100644 --- a/crates/pop-cli/src/commands/up/contract.rs +++ b/crates/pop-cli/src/commands/up/contract.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0 use crate::{ - cli::{traits::Cli as _, Cli}, + cli::{traits::Cli as _, Cli}, common::contracts::{check_contracts_node_and_prompt, has_contract_been_built}, style::style, }; diff --git a/crates/pop-cli/src/commands/up/parachain.rs b/crates/pop-cli/src/commands/up/parachain.rs index 2a8da10af..46f1940a7 100644 --- a/crates/pop-cli/src/commands/up/parachain.rs +++ b/crates/pop-cli/src/commands/up/parachain.rs @@ -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,7 +82,8 @@ impl ZombienetCommand { Ok(()) }, _ => Err(e.into()), - }, + } + }, }; // Source any missing/stale binaries @@ -201,8 +202,8 @@ impl ZombienetCommand { )) .dim() .to_string(); - if !skip_confirm && - !confirm(format!( + if !skip_confirm + && !confirm(format!( "📦 Would you like to source them automatically now? It may take some time...\n {list}")) .initial_value(true) .interact()? diff --git a/crates/pop-cli/tests/contract.rs b/crates/pop-cli/tests/contract.rs index c3a3d1078..d1d166303 100644 --- a/crates/pop-cli/tests/contract.rs +++ b/crates/pop-cli/tests/contract.rs @@ -43,8 +43,8 @@ async fn contract_lifecycle() -> Result<()> { .current_dir(&temp_dir) .args(&["build", "./test_contract", "--release"]) .assert() - .success();*/ - + .success(); + */ println!("Contract built!!"); // Verify that the directory target has been created From 0cbabc5b1e561b69236479fba2d99d818ee063f0 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Fri, 13 Dec 2024 20:26:59 +0900 Subject: [PATCH 05/14] cargo +nightly fmt --- crates/pop-cli/src/commands/build/spec.rs | 4 ++-- crates/pop-cli/src/commands/install/mod.rs | 5 ++--- crates/pop-cli/src/commands/new/pallet.rs | 10 +++++----- crates/pop-cli/src/commands/new/parachain.rs | 4 ++-- crates/pop-cli/src/commands/up/parachain.rs | 9 ++++----- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/crates/pop-cli/src/commands/build/spec.rs b/crates/pop-cli/src/commands/build/spec.rs index 0216f559b..3cde4c61e 100644 --- a/crates/pop-cli/src/commands/build/spec.rs +++ b/crates/pop-cli/src/commands/build/spec.rs @@ -226,8 +226,8 @@ impl BuildSpecCommand { // Output file. let maybe_chain_spec_file = PathBuf::from(&chain); // Check if the provided chain specification is a file. - let (output_file, prompt) = if maybe_chain_spec_file.exists() - && maybe_chain_spec_file.is_file() + let (output_file, prompt) = if maybe_chain_spec_file.exists() && + maybe_chain_spec_file.is_file() { if output_file.is_some() { cli.warning("NOTE: If an existing chain spec file is provided it will be used for the output path.")?; diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index fd6be9591..19b9fd3a2 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -299,12 +299,11 @@ async fn install_rustup() -> 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/new/pallet.rs b/crates/pop-cli/src/commands/new/pallet.rs index 338f1ef6c..ba47d49a4 100644 --- a/crates/pop-cli/src/commands/new/pallet.rs +++ b/crates/pop-cli/src/commands/new/pallet.rs @@ -84,11 +84,11 @@ impl NewPalletCommand { let mut pallet_custom_origin = false; if let Some(Mode::Advanced(advanced_mode_args)) = &self.mode { - if advanced_mode_args.config_common_types.is_empty() - && advanced_mode_args.storage.is_empty() - && !(advanced_mode_args.genesis_config - || advanced_mode_args.default_config - || advanced_mode_args.custom_origin) + if advanced_mode_args.config_common_types.is_empty() && + advanced_mode_args.storage.is_empty() && + !(advanced_mode_args.genesis_config || + advanced_mode_args.default_config || + advanced_mode_args.custom_origin) { Cli.info("Generate the pallet's config trait.")?; diff --git a/crates/pop-cli/src/commands/new/parachain.rs b/crates/pop-cli/src/commands/new/parachain.rs index c33457ad7..e65035cfc 100644 --- a/crates/pop-cli/src/commands/new/parachain.rs +++ b/crates/pop-cli/src/commands/new/parachain.rs @@ -268,8 +268,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/parachain.rs b/crates/pop-cli/src/commands/up/parachain.rs index 46f1940a7..2a8da10af 100644 --- a/crates/pop-cli/src/commands/up/parachain.rs +++ b/crates/pop-cli/src/commands/up/parachain.rs @@ -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 @@ -202,8 +201,8 @@ impl ZombienetCommand { )) .dim() .to_string(); - if !skip_confirm - && !confirm(format!( + if !skip_confirm && + !confirm(format!( "📦 Would you like to source them automatically now? It may take some time...\n {list}")) .initial_value(true) .interact()? From aac298458c487eac6b36efe76337699800f20942 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 21 Dec 2024 15:56:38 +0900 Subject: [PATCH 06/14] pop build completed --- crates/pop-cli/src/commands/build/mod.rs | 25 +++++++++++------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/crates/pop-cli/src/commands/build/mod.rs b/crates/pop-cli/src/commands/build/mod.rs index c17e53542..37d856625 100644 --- a/crates/pop-cli/src/commands/build/mod.rs +++ b/crates/pop-cli/src/commands/build/mod.rs @@ -1,8 +1,7 @@ // SPDX-License-Identifier: GPL-3.0 use crate::cli::{self, Cli}; -use anyhow::ensure; -use clap::{Args, Parser, Subcommand}; +use clap::{Args, Subcommand}; #[cfg(feature = "contract")] use contract::BuildContract; use duct::cmd; @@ -28,7 +27,7 @@ pub(crate) struct BuildArgs { #[arg(long)] pub(crate) path: Option, /// Directory path without flag for your project [default: current directory] - #[arg(value_name = "PATH", required_unless_present = "path")] + #[arg(value_name = "PATH", index = 1, conflicts_with = "path")] pub(crate) path_pos: Option, /// The package to be built. #[arg(short = 'p', long)] @@ -55,35 +54,33 @@ impl Command { pub(crate) fn execute(args: BuildArgs) -> anyhow::Result<&'static str> { // If only contract feature enabled, build as contract let path_flag = args.path.clone(); - let path_pos = args.path_pos.clone(); - let project_path = match path_flag { - Some(ref path) if path.to_str().unwrap().contains("./") => Some(path.to_owned()), - _ => { - ensure!(path_pos.is_some(), "Failed to get directory!"); - path_pos - }, + let project_path = if let Some(ref path_pos) = args.path_pos { + Some(path_pos) // Use positional path if present + } else { + path_flag.as_ref() // Otherwise, use the named path }; #[cfg(feature = "contract")] - if pop_contracts::is_supported(project_path.as_deref())? { + if pop_contracts::is_supported(project_path.as_deref().map(|v| &**v))? { // All commands originating from root command are valid let release = match args.profile { Some(profile) => profile.into(), None => args.release, }; - BuildContractCommand { path: project_path, release, valid: true }.execute()?; + BuildContract { path: project_path.cloned(), release }.execute()?; return Ok("contract"); } // If only parachain feature enabled, build as parachain #[cfg(feature = "parachain")] - if pop_parachains::is_supported(project_path.as_deref())? { + if pop_parachains::is_supported(project_path.as_deref().map(|v| &**v))? { let profile = match args.profile { Some(profile) => profile, None => args.release.into(), }; + let temp_path = &PathBuf::from("./"); BuildParachain { - path: project_path.unwrap_or_else(|| PathBuf::from("./")), + path: project_path.unwrap_or_else(|| temp_path).to_path_buf(), package: args.package, profile, } From 2f7b5a839d23740c107ea923cb15f85d8e287f1d Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 21 Dec 2024 17:09:32 +0900 Subject: [PATCH 07/14] pop up contract implementation --- crates/pop-cli/src/commands/up/contract.rs | 28 ++++++++++++++++++---- crates/pop-cli/tests/contract.rs | 19 ++++++++++----- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/crates/pop-cli/src/commands/up/contract.rs b/crates/pop-cli/src/commands/up/contract.rs index f46c0776f..1bbdb8df4 100644 --- a/crates/pop-cli/src/commands/up/contract.rs +++ b/crates/pop-cli/src/commands/up/contract.rs @@ -34,6 +34,9 @@ pub struct UpContractCommand { /// Path to the contract build directory. #[arg(short, long)] path: Option, + /// Directory path without flag for your project [default: current directory] + #[arg(value_name = "PATH", index = 1, conflicts_with = "path")] + pub path_pos: Option, /// The name of the contract constructor to call. #[clap(short, long, default_value = "new")] constructor: String, @@ -92,13 +95,19 @@ impl UpContractCommand { pub(crate) async fn execute(mut self) -> anyhow::Result<()> { Cli.intro("Deploy a smart contract")?; + let path_flag = self.path.clone(); + let project_path = if let Some(ref path_pos) = self.path_pos { + Some(path_pos) // Use positional path if present + } else { + path_flag.as_ref() // Otherwise, use the named path + }; // Check if build exists in the specified "Contract build directory" - if !has_contract_been_built(self.path.as_deref()) { + if !has_contract_been_built(project_path.as_deref().map(|v| &**v)) { // Build the contract in release mode Cli.warning("NOTE: contract has not yet been built.")?; let spinner = spinner(); spinner.start("Building contract in RELEASE mode..."); - let result = match build_smart_contract(self.path.as_deref(), true, Verbosity::Quiet) { + let result = match build_smart_contract(project_path.as_deref().map(|v| &**v), true, Verbosity::Quiet) { Ok(result) => result, Err(e) => { Cli.outro_cancel(format!("🚫 An error occurred building your contract: {e}\nUse `pop build` to retry with build output."))?; @@ -360,7 +369,13 @@ impl UpContractCommand { // get the call data and contract code hash async fn get_contract_data(&self) -> anyhow::Result<(Vec, [u8; 32])> { - let contract_code = get_contract_code(self.path.as_ref())?; + let path_flag = self.path.clone(); + let project_path = if let Some(ref path_pos) = self.path_pos { + Some(path_pos) // Use positional path if present + } else { + path_flag.as_ref() // Otherwise, use the named path + }; + let contract_code = get_contract_code(project_path)?; let hash = contract_code.code_hash(); if self.upload_only { let call_data = get_upload_payload(contract_code, self.url.as_str()).await?; @@ -435,6 +450,7 @@ mod tests { fn default_up_contract_command() -> UpContractCommand { UpContractCommand { path: None, + path_pos: None, constructor: "new".to_string(), args: vec![], value: "0".to_string(), @@ -510,7 +526,8 @@ mod tests { let localhost_url = format!("ws://127.0.0.1:{}", port); let up_contract_opts = UpContractCommand { - path: Some(temp_dir), + path: Some(temp_dir.clone()), + path_pos: Some(temp_dir), constructor: "new".to_string(), args: vec![], value: "0".to_string(), @@ -561,7 +578,8 @@ mod tests { let localhost_url = format!("ws://127.0.0.1:{}", port); let up_contract_opts = UpContractCommand { - path: Some(temp_dir), + path: Some(temp_dir.clone()), + path_pos: Some(temp_dir), constructor: "new".to_string(), args: vec!["false".to_string()], value: "0".to_string(), diff --git a/crates/pop-cli/tests/contract.rs b/crates/pop-cli/tests/contract.rs index 6b8a79b2e..962dd330d 100644 --- a/crates/pop-cli/tests/contract.rs +++ b/crates/pop-cli/tests/contract.rs @@ -67,22 +67,22 @@ async fn contract_lifecycle() -> Result<()> { .success(); assert!(temp_dir.join("test_contract").exists()); - // pop build --path ./test_contract --release +/* // pop build --path ./test_contract --release Command::cargo_bin("pop") .unwrap() .current_dir(&temp_dir) .args(&["build", "--path", "./test_contract", "--release"]) .assert() .success(); - +*/ // pop build ./test_contract --release - /*Command::cargo_bin("pop") + Command::cargo_bin("pop") .unwrap() .current_dir(&temp_dir) .args(&["build", "./test_contract", "--release"]) .assert() .success(); - */ + println!("Contract built!!"); // Verify that the directory target has been created @@ -99,13 +99,20 @@ async fn contract_lifecycle() -> Result<()> { sleep(Duration::from_secs(5)).await; // Only upload the contract - // pop up contract --upload-only + // pop up contract --path ./test_contract --upload-only Command::cargo_bin("pop") .unwrap() .current_dir(&temp_dir.join("test_contract")) - .args(&["up", "contract", "--upload-only", "--url", default_endpoint]) + .args(&["up", "contract", "--path", "./test_contract","--upload-only", "--url", default_endpoint]) .assert() .success(); + /*// pop up contract --upload-only + Command::cargo_bin("pop") + .unwrap() + .current_dir(&temp_dir.join("test_contract")) + .args(&["up", "contract", "--upload-only", "--url", default_endpoint]) + .assert() + .success();*/ // Instantiate contract, only dry-run Command::cargo_bin("pop") .unwrap() From a449edf368fd55e2c6c7f1916c621fbf5db4ce2c Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 21 Dec 2024 19:39:50 +0900 Subject: [PATCH 08/14] pop call contract implemented --- crates/pop-cli/src/commands/call/contract.rs | 73 +++++++++++++++++--- crates/pop-cli/src/commands/up/contract.rs | 6 +- crates/pop-cli/tests/contract.rs | 28 +++++--- 3 files changed, 86 insertions(+), 21 deletions(-) diff --git a/crates/pop-cli/src/commands/call/contract.rs b/crates/pop-cli/src/commands/call/contract.rs index ab7a826fd..9002ce992 100644 --- a/crates/pop-cli/src/commands/call/contract.rs +++ b/crates/pop-cli/src/commands/call/contract.rs @@ -17,7 +17,7 @@ use pop_contracts::{ parse_account, set_up_call, CallExec, CallOpts, DefaultEnvironment, Verbosity, }; use sp_weights::Weight; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; const DEFAULT_URL: &str = "ws://localhost:9944/"; const DEFAULT_URI: &str = "//Alice"; @@ -28,6 +28,9 @@ pub struct CallContractCommand { /// Path to the contract build directory or a contract artifact. #[arg(short, long)] path: Option, + /// Directory path without flag for your project [default: current directory] + #[arg(value_name = "PATH", index = 1, conflicts_with = "path")] + pub(crate) path_pos: Option, /// The address of the contract to call. #[arg(short, long, env = "CONTRACT")] contract: Option, @@ -109,7 +112,14 @@ impl CallContractCommand { fn display(&self) -> String { let mut full_message = "pop call contract".to_string(); - if let Some(path) = &self.path { + let path_flag = self.path.clone(); + let project_path = if let Some(ref path_pos) = self.path_pos { + Some(path_pos) // Use positional path if present + } else { + path_flag.as_ref() // Otherwise, use the named path + }; + + if let Some(path) = &project_path { full_message.push_str(&format!(" --path {}", path.display())); } if let Some(contract) = &self.contract { @@ -148,11 +158,21 @@ impl CallContractCommand { /// If the contract has not been built, build it in release mode. async fn ensure_contract_built(&self, cli: &mut impl Cli) -> Result<()> { + let path_flag = self.path.clone(); + let project_path = if let Some(ref path_pos) = self.path_pos { + Some(path_pos) // Use positional path if present + } else { + path_flag.as_ref() // Otherwise, use the named path + }; // Build the contract in release mode cli.warning("NOTE: contract has not yet been built.")?; let spinner = spinner(); spinner.start("Building contract in RELEASE mode..."); - let result = match build_smart_contract(self.path.as_deref(), true, Verbosity::Quiet) { + let result = match build_smart_contract( + project_path.as_deref().map(|v| &**v), + true, + Verbosity::Quiet, + ) { Ok(result) => result, Err(e) => { return Err(anyhow!(format!( @@ -182,7 +202,14 @@ impl CallContractCommand { /// Checks whether building the contract is required fn is_contract_build_required(&self) -> bool { - self.path + let path_flag = self.path.clone(); + let project_path = if let Some(ref path_pos) = self.path_pos { + Some(path_pos) // Use positional path if present + } else { + path_flag.as_ref() // Otherwise, use the named path + }; + + project_path .as_ref() .map(|p| p.is_dir() && !has_contract_been_built(Some(p))) .unwrap_or_default() @@ -190,6 +217,13 @@ impl CallContractCommand { /// Configure the call based on command line arguments/call UI. async fn configure(&mut self, cli: &mut impl Cli, repeat: bool) -> Result<()> { + let path_flag = self.path.clone(); + let mut project_path: Option = if let Some(ref path_pos) = self.path_pos { + Some(path_pos.to_path_buf()) // Use positional path if present + } else { + path_flag // Otherwise, use the named path + }; + // Show intro on first run. if !repeat { cli.intro("Call a contract")?; @@ -201,16 +235,15 @@ impl CallContractCommand { } // Resolve path. - if self.path.is_none() { + if project_path.is_none() { let input_path: String = cli .input("Where is your project or contract artifact located?") .placeholder("./") .default_input("./") .interact()?; - self.path = Some(PathBuf::from(input_path)); + project_path = Some(PathBuf::from(input_path)); } - let contract_path = self - .path + let contract_path = project_path .as_ref() .expect("path is guaranteed to be set as input as prompted when None; qed"); @@ -357,6 +390,13 @@ impl CallContractCommand { cli: &mut impl Cli, prompt_to_repeat_call: bool, ) -> Result<()> { + let path_flag = self.path.clone(); + let project_path = if let Some(ref path_pos) = self.path_pos { + Some(path_pos) // Use positional path if present + } else { + path_flag.as_ref() // Otherwise, use the named path + }; + let message = match &self.message { Some(message) => message.to_string(), None => { @@ -364,8 +404,9 @@ impl CallContractCommand { }, }; // Disable wallet signing and display warning if the call is read-only. + let path = PathBuf::from("./"); let message_metadata = - get_message(self.path.as_deref().unwrap_or_else(|| Path::new("./")), &message)?; + get_message(project_path.as_deref().unwrap_or_else(|| &path), &message)?; if !message_metadata.mutates && self.use_wallet { cli.warning("NOTE: Signing is not required for this read-only call. The '--use-wallet' flag will be ignored.")?; self.use_wallet = false; @@ -378,7 +419,7 @@ impl CallContractCommand { }, }; let call_exec = match set_up_call(CallOpts { - path: self.path.clone(), + path: project_path.cloned(), contract, message, args: self.args.clone(), @@ -564,6 +605,7 @@ mod tests { // Contract deployed on Pop Network testnet, test get CallContractCommand { path: Some(temp_dir.path().join("testing")), + path_pos: Some(temp_dir.path().join("testing")), contract: Some("15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".to_string()), message: Some("get".to_string()), args: vec![].to_vec(), @@ -600,6 +642,7 @@ mod tests { let mut call_config = CallContractCommand { path: Some(temp_dir.path().join("testing")), + path_pos: Some(temp_dir.path().join("testing")), contract: Some("15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".to_string()), message: Some("flip".to_string()), args: vec![].to_vec(), @@ -637,6 +680,7 @@ mod tests { // From .contract file let mut call_config = CallContractCommand { path: Some(current_dir.join("pop-contracts/tests/files/testing.contract")), + path_pos: Some(current_dir.join("pop-contracts/tests/files/testing.contract")), contract: Some("15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".to_string()), message: Some("flip".to_string()), args: vec![].to_vec(), @@ -723,6 +767,7 @@ mod tests { // Contract deployed on Pop Network testnet, test get let mut call_config = CallContractCommand { path: Some(temp_dir.path().join("testing")), + path_pos: Some(temp_dir.path().join("testing")), contract: Some("15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".to_string()), message: Some("get".to_string()), args: vec![].to_vec(), @@ -789,6 +834,7 @@ mod tests { let mut call_config = CallContractCommand { path: None, + path_pos: None, contract: None, message: None, args: vec![].to_vec(), @@ -876,6 +922,7 @@ mod tests { let mut call_config = CallContractCommand { path: None, + path_pos: None, contract: None, message: None, args: vec![].to_vec(), @@ -964,6 +1011,7 @@ mod tests { let mut call_config = CallContractCommand { path: None, + path_pos: None, contract: None, message: None, args: vec![].to_vec(), @@ -1023,6 +1071,7 @@ mod tests { // Test the path is a folder with an invalid build. let mut command = CallContractCommand { path: Some(temp_dir.path().join("testing")), + path_pos: Some(temp_dir.path().join("testing")), contract: None, message: None, args: vec![].to_vec(), @@ -1073,6 +1122,7 @@ mod tests { assert!(matches!( CallContractCommand { path: Some(temp_dir.path().join("testing")), + path_pos: Some(temp_dir.path().join("testing")), contract: Some("15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".to_string()), message: None, args: vec![].to_vec(), @@ -1092,6 +1142,7 @@ mod tests { assert!(matches!( CallContractCommand { path: Some(temp_dir.path().join("testing")), + path_pos: Some(temp_dir.path().join("testing")), contract: None, message: Some("get".to_string()), args: vec![].to_vec(), @@ -1116,6 +1167,7 @@ mod tests { let temp_dir = new_environment("testing")?; let call_config = CallContractCommand { path: Some(temp_dir.path().join("testing")), + path_pos: Some(temp_dir.path().join("testing")), contract: Some("15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".to_string()), message: None, args: vec![].to_vec(), @@ -1147,6 +1199,7 @@ mod tests { let temp_dir = new_environment("testing")?; let call_config = CallContractCommand { path: Some(temp_dir.path().join("testing")), + path_pos: Some(temp_dir.path().join("testing")), contract: Some("15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".to_string()), message: None, args: vec![].to_vec(), diff --git a/crates/pop-cli/src/commands/up/contract.rs b/crates/pop-cli/src/commands/up/contract.rs index 1bbdb8df4..946fd255c 100644 --- a/crates/pop-cli/src/commands/up/contract.rs +++ b/crates/pop-cli/src/commands/up/contract.rs @@ -107,7 +107,11 @@ impl UpContractCommand { Cli.warning("NOTE: contract has not yet been built.")?; let spinner = spinner(); spinner.start("Building contract in RELEASE mode..."); - let result = match build_smart_contract(project_path.as_deref().map(|v| &**v), true, Verbosity::Quiet) { + let result = match build_smart_contract( + project_path.as_deref().map(|v| &**v), + true, + Verbosity::Quiet, + ) { Ok(result) => result, Err(e) => { Cli.outro_cancel(format!("🚫 An error occurred building your contract: {e}\nUse `pop build` to retry with build output."))?; diff --git a/crates/pop-cli/tests/contract.rs b/crates/pop-cli/tests/contract.rs index 962dd330d..80c844881 100644 --- a/crates/pop-cli/tests/contract.rs +++ b/crates/pop-cli/tests/contract.rs @@ -67,14 +67,14 @@ async fn contract_lifecycle() -> Result<()> { .success(); assert!(temp_dir.join("test_contract").exists()); -/* // pop build --path ./test_contract --release - Command::cargo_bin("pop") - .unwrap() - .current_dir(&temp_dir) - .args(&["build", "--path", "./test_contract", "--release"]) - .assert() - .success(); -*/ + /* // pop build --path ./test_contract --release + Command::cargo_bin("pop") + .unwrap() + .current_dir(&temp_dir) + .args(&["build", "--path", "./test_contract", "--release"]) + .assert() + .success(); + */ // pop build ./test_contract --release Command::cargo_bin("pop") .unwrap() @@ -82,7 +82,7 @@ async fn contract_lifecycle() -> Result<()> { .args(&["build", "./test_contract", "--release"]) .assert() .success(); - + println!("Contract built!!"); // Verify that the directory target has been created @@ -103,7 +103,15 @@ async fn contract_lifecycle() -> Result<()> { Command::cargo_bin("pop") .unwrap() .current_dir(&temp_dir.join("test_contract")) - .args(&["up", "contract", "--path", "./test_contract","--upload-only", "--url", default_endpoint]) + .args(&[ + "up", + "contract", + "--path", + "./test_contract", + "--upload-only", + "--url", + default_endpoint, + ]) .assert() .success(); /*// pop up contract --upload-only From 45412f811bfbcd31031313e949be57d0bb754a19 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 24 Dec 2024 14:13:16 +0900 Subject: [PATCH 09/14] Fixed some of the issues pointed in the reviews --- crates/pop-cli/src/commands/build/mod.rs | 17 ++-- crates/pop-cli/src/commands/call/contract.rs | 91 ++++++-------------- crates/pop-cli/src/commands/up/contract.rs | 22 ++--- crates/pop-cli/src/common/contracts.rs | 10 +++ crates/pop-cli/tests/contract.rs | 22 +---- 5 files changed, 53 insertions(+), 109 deletions(-) diff --git a/crates/pop-cli/src/commands/build/mod.rs b/crates/pop-cli/src/commands/build/mod.rs index 37d856625..465fcf6d4 100644 --- a/crates/pop-cli/src/commands/build/mod.rs +++ b/crates/pop-cli/src/commands/build/mod.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0 -use crate::cli::{self, Cli}; +use crate::{common::contracts::get_project_path, cli::{self, Cli}}; use clap::{Args, Subcommand}; #[cfg(feature = "contract")] use contract::BuildContract; @@ -53,32 +53,27 @@ impl Command { /// Executes the command. pub(crate) fn execute(args: BuildArgs) -> anyhow::Result<&'static str> { // If only contract feature enabled, build as contract - let path_flag = args.path.clone(); - let project_path = if let Some(ref path_pos) = args.path_pos { - Some(path_pos) // Use positional path if present - } else { - path_flag.as_ref() // Otherwise, use the named path - }; + let project_path = get_project_path(args.path.clone(), args.path_pos.clone()); #[cfg(feature = "contract")] - if pop_contracts::is_supported(project_path.as_deref().map(|v| &**v))? { + if pop_contracts::is_supported(project_path.as_deref().map(|v| v))? { // All commands originating from root command are valid let release = match args.profile { Some(profile) => profile.into(), None => args.release, }; - BuildContract { path: project_path.cloned(), release }.execute()?; + BuildContract { path: project_path, release }.execute()?; return Ok("contract"); } // If only parachain feature enabled, build as parachain #[cfg(feature = "parachain")] - if pop_parachains::is_supported(project_path.as_deref().map(|v| &**v))? { + if pop_parachains::is_supported(project_path.as_deref().map(|v| v))? { let profile = match args.profile { Some(profile) => profile, None => args.release.into(), }; - let temp_path = &PathBuf::from("./"); + let temp_path = PathBuf::from("./"); BuildParachain { path: project_path.unwrap_or_else(|| temp_path).to_path_buf(), package: args.package, diff --git a/crates/pop-cli/src/commands/call/contract.rs b/crates/pop-cli/src/commands/call/contract.rs index 9002ce992..dd57d3098 100644 --- a/crates/pop-cli/src/commands/call/contract.rs +++ b/crates/pop-cli/src/commands/call/contract.rs @@ -3,7 +3,7 @@ use crate::{ cli::{self, traits::*}, common::{ - contracts::has_contract_been_built, + contracts::{has_contract_been_built, get_project_path}, wallet::{prompt_to_use_wallet, request_signature}, }, }; @@ -112,16 +112,13 @@ impl CallContractCommand { fn display(&self) -> String { let mut full_message = "pop call contract".to_string(); - let path_flag = self.path.clone(); - let project_path = if let Some(ref path_pos) = self.path_pos { - Some(path_pos) // Use positional path if present - } else { - path_flag.as_ref() // Otherwise, use the named path - }; - if let Some(path) = &project_path { + if let Some(path) = &self.path { full_message.push_str(&format!(" --path {}", path.display())); - } + } + if let Some(path_pos) = &self.path_pos { + full_message.push_str(&format!(" --path {}", path_pos.display())); + } if let Some(contract) = &self.contract { full_message.push_str(&format!(" --contract {}", contract)); } @@ -158,18 +155,13 @@ impl CallContractCommand { /// If the contract has not been built, build it in release mode. async fn ensure_contract_built(&self, cli: &mut impl Cli) -> Result<()> { - let path_flag = self.path.clone(); - let project_path = if let Some(ref path_pos) = self.path_pos { - Some(path_pos) // Use positional path if present - } else { - path_flag.as_ref() // Otherwise, use the named path - }; + let project_path = get_project_path(self.path.clone(), self.path_pos.clone()); // Build the contract in release mode cli.warning("NOTE: contract has not yet been built.")?; let spinner = spinner(); spinner.start("Building contract in RELEASE mode..."); let result = match build_smart_contract( - project_path.as_deref().map(|v| &**v), + project_path.as_deref().map(|v| v), true, Verbosity::Quiet, ) { @@ -202,12 +194,7 @@ impl CallContractCommand { /// Checks whether building the contract is required fn is_contract_build_required(&self) -> bool { - let path_flag = self.path.clone(); - let project_path = if let Some(ref path_pos) = self.path_pos { - Some(path_pos) // Use positional path if present - } else { - path_flag.as_ref() // Otherwise, use the named path - }; + let project_path = get_project_path(self.path.clone(), self.path_pos.clone()); project_path .as_ref() @@ -217,12 +204,7 @@ impl CallContractCommand { /// Configure the call based on command line arguments/call UI. async fn configure(&mut self, cli: &mut impl Cli, repeat: bool) -> Result<()> { - let path_flag = self.path.clone(); - let mut project_path: Option = if let Some(ref path_pos) = self.path_pos { - Some(path_pos.to_path_buf()) // Use positional path if present - } else { - path_flag // Otherwise, use the named path - }; + let mut project_path = get_project_path(self.path.clone(), self.path_pos.clone()); // Show intro on first run. if !repeat { @@ -390,12 +372,7 @@ impl CallContractCommand { cli: &mut impl Cli, prompt_to_repeat_call: bool, ) -> Result<()> { - let path_flag = self.path.clone(); - let project_path = if let Some(ref path_pos) = self.path_pos { - Some(path_pos) // Use positional path if present - } else { - path_flag.as_ref() // Otherwise, use the named path - }; + let project_path = get_project_path(self.path.clone(), self.path_pos.clone()); let message = match &self.message { Some(message) => message.to_string(), @@ -419,7 +396,7 @@ impl CallContractCommand { }, }; let call_exec = match set_up_call(CallOpts { - path: project_path.cloned(), + path: project_path, contract, message, args: self.args.clone(), @@ -605,7 +582,7 @@ mod tests { // Contract deployed on Pop Network testnet, test get CallContractCommand { path: Some(temp_dir.path().join("testing")), - path_pos: Some(temp_dir.path().join("testing")), + path_pos: None, contract: Some("15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".to_string()), message: Some("get".to_string()), args: vec![].to_vec(), @@ -642,7 +619,7 @@ mod tests { let mut call_config = CallContractCommand { path: Some(temp_dir.path().join("testing")), - path_pos: Some(temp_dir.path().join("testing")), + path_pos: None, contract: Some("15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".to_string()), message: Some("flip".to_string()), args: vec![].to_vec(), @@ -680,7 +657,7 @@ mod tests { // From .contract file let mut call_config = CallContractCommand { path: Some(current_dir.join("pop-contracts/tests/files/testing.contract")), - path_pos: Some(current_dir.join("pop-contracts/tests/files/testing.contract")), + path_pos: None, contract: Some("15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".to_string()), message: Some("flip".to_string()), args: vec![].to_vec(), @@ -767,7 +744,7 @@ mod tests { // Contract deployed on Pop Network testnet, test get let mut call_config = CallContractCommand { path: Some(temp_dir.path().join("testing")), - path_pos: Some(temp_dir.path().join("testing")), + path_pos: None, contract: Some("15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".to_string()), message: Some("get".to_string()), args: vec![].to_vec(), @@ -814,11 +791,7 @@ mod tests { true, Some(items), 1, // "get" message - ) - .expect_input( - "Where is your project or contract artifact located?", - temp_dir.path().join("testing").display().to_string(), - ) + ) .expect_input( "Where is your contract deployed?", "wss://rpc1.paseo.popnetwork.xyz".into(), @@ -834,7 +807,7 @@ mod tests { let mut call_config = CallContractCommand { path: None, - path_pos: None, + path_pos: Some(temp_dir.path().join("testing")), contract: None, message: None, args: vec![].to_vec(), @@ -864,7 +837,7 @@ mod tests { assert!(!call_config.dry_run); assert_eq!(call_config.display(), format!( "pop call contract --path {} --contract 15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm --message get --url wss://rpc1.paseo.popnetwork.xyz/ --suri //Alice", - temp_dir.path().join("testing").display().to_string(), + temp_dir.path().join("testing").display().to_string() )); cli.verify() @@ -890,10 +863,6 @@ mod tests { ]; // The inputs are processed in reverse order. let mut cli = MockCli::new() - .expect_input( - "Where is your project or contract artifact located?", - temp_dir.path().join("testing").display().to_string(), - ) .expect_input( "Where is your contract deployed?", "wss://rpc1.paseo.popnetwork.xyz".into(), @@ -922,7 +891,7 @@ mod tests { let mut call_config = CallContractCommand { path: None, - path_pos: None, + path_pos: Some(temp_dir.path().join("testing")), contract: None, message: None, args: vec![].to_vec(), @@ -955,7 +924,7 @@ mod tests { assert!(!call_config.dry_run); assert_eq!(call_config.display(), format!( "pop call contract --path {} --contract 15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm --message specific_flip --args \"true\", \"2\" --value 50 --url wss://rpc1.paseo.popnetwork.xyz/ --use-wallet --execute", - temp_dir.path().join("testing").display().to_string(), + temp_dir.path().join("testing").display().to_string() )); cli.verify() @@ -988,10 +957,6 @@ mod tests { Some(items), 2, // "specific_flip" message ) - .expect_input( - "Where is your project or contract artifact located?", - temp_dir.path().join("testing").display().to_string(), - ) .expect_input( "Where is your contract deployed?", "wss://rpc1.paseo.popnetwork.xyz".into(), @@ -1011,7 +976,7 @@ mod tests { let mut call_config = CallContractCommand { path: None, - path_pos: None, + path_pos: Some(temp_dir.path().join("testing")), contract: None, message: None, args: vec![].to_vec(), @@ -1044,7 +1009,7 @@ mod tests { assert!(call_config.dev_mode); assert_eq!(call_config.display(), format!( "pop call contract --path {} --contract 15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm --message specific_flip --args \"true\", \"2\" --value 50 --url wss://rpc1.paseo.popnetwork.xyz/ --suri //Alice --execute", - temp_dir.path().join("testing").display().to_string(), + temp_dir.path().join("testing").display().to_string() )); cli.verify() @@ -1071,7 +1036,7 @@ mod tests { // Test the path is a folder with an invalid build. let mut command = CallContractCommand { path: Some(temp_dir.path().join("testing")), - path_pos: Some(temp_dir.path().join("testing")), + path_pos: None, contract: None, message: None, args: vec![].to_vec(), @@ -1122,7 +1087,7 @@ mod tests { assert!(matches!( CallContractCommand { path: Some(temp_dir.path().join("testing")), - path_pos: Some(temp_dir.path().join("testing")), + path_pos: None, contract: Some("15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".to_string()), message: None, args: vec![].to_vec(), @@ -1142,7 +1107,7 @@ mod tests { assert!(matches!( CallContractCommand { path: Some(temp_dir.path().join("testing")), - path_pos: Some(temp_dir.path().join("testing")), + path_pos: None, contract: None, message: Some("get".to_string()), args: vec![].to_vec(), @@ -1167,7 +1132,7 @@ mod tests { let temp_dir = new_environment("testing")?; let call_config = CallContractCommand { path: Some(temp_dir.path().join("testing")), - path_pos: Some(temp_dir.path().join("testing")), + path_pos: None, contract: Some("15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".to_string()), message: None, args: vec![].to_vec(), @@ -1199,7 +1164,7 @@ mod tests { let temp_dir = new_environment("testing")?; let call_config = CallContractCommand { path: Some(temp_dir.path().join("testing")), - path_pos: Some(temp_dir.path().join("testing")), + path_pos: None, contract: Some("15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".to_string()), message: None, args: vec![].to_vec(), diff --git a/crates/pop-cli/src/commands/up/contract.rs b/crates/pop-cli/src/commands/up/contract.rs index 946fd255c..0128e6983 100644 --- a/crates/pop-cli/src/commands/up/contract.rs +++ b/crates/pop-cli/src/commands/up/contract.rs @@ -3,7 +3,7 @@ use crate::{ cli::{traits::Cli as _, Cli}, common::{ - contracts::{check_contracts_node_and_prompt, has_contract_been_built, terminate_node}, + contracts::{check_contracts_node_and_prompt, has_contract_been_built, terminate_node, get_project_path}, wallet::request_signature, }, style::style, @@ -95,20 +95,15 @@ impl UpContractCommand { pub(crate) async fn execute(mut self) -> anyhow::Result<()> { Cli.intro("Deploy a smart contract")?; - let path_flag = self.path.clone(); - let project_path = if let Some(ref path_pos) = self.path_pos { - Some(path_pos) // Use positional path if present - } else { - path_flag.as_ref() // Otherwise, use the named path - }; + let project_path = get_project_path(self.path.clone(), self.path_pos.clone()); // Check if build exists in the specified "Contract build directory" - if !has_contract_been_built(project_path.as_deref().map(|v| &**v)) { + if !has_contract_been_built(project_path.as_deref().map(|v| v)) { // Build the contract in release mode Cli.warning("NOTE: contract has not yet been built.")?; let spinner = spinner(); spinner.start("Building contract in RELEASE mode..."); let result = match build_smart_contract( - project_path.as_deref().map(|v| &**v), + project_path.as_deref().map(|v| v), true, Verbosity::Quiet, ) { @@ -373,13 +368,8 @@ impl UpContractCommand { // get the call data and contract code hash async fn get_contract_data(&self) -> anyhow::Result<(Vec, [u8; 32])> { - let path_flag = self.path.clone(); - let project_path = if let Some(ref path_pos) = self.path_pos { - Some(path_pos) // Use positional path if present - } else { - path_flag.as_ref() // Otherwise, use the named path - }; - let contract_code = get_contract_code(project_path)?; + let project_path = get_project_path(self.path.clone(), self.path_pos.clone()); + let contract_code = get_contract_code(project_path.as_ref())?; let hash = contract_code.code_hash(); if self.upload_only { let call_data = get_upload_payload(contract_code, self.url.as_str()).await?; diff --git a/crates/pop-cli/src/common/contracts.rs b/crates/pop-cli/src/common/contracts.rs index a3b8f878c..2f04c3295 100644 --- a/crates/pop-cli/src/common/contracts.rs +++ b/crates/pop-cli/src/common/contracts.rs @@ -126,6 +126,16 @@ pub fn has_contract_been_built(path: Option<&Path>) -> bool { .unwrap_or_default() } + +pub fn get_project_path(path_flag: Option, path_pos: Option) -> Option { + let project_path = if let Some(ref path) = path_pos { + Some(path) // Use positional path if present + } else { + path_flag.as_ref() // Otherwise, use the named path + }; + project_path.cloned() +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/pop-cli/tests/contract.rs b/crates/pop-cli/tests/contract.rs index 80c844881..7e45308ae 100644 --- a/crates/pop-cli/tests/contract.rs +++ b/crates/pop-cli/tests/contract.rs @@ -67,24 +67,15 @@ async fn contract_lifecycle() -> Result<()> { .success(); assert!(temp_dir.join("test_contract").exists()); - /* // pop build --path ./test_contract --release + // pop build --path ./test_contract --release Command::cargo_bin("pop") .unwrap() .current_dir(&temp_dir) .args(&["build", "--path", "./test_contract", "--release"]) .assert() .success(); - */ - // pop build ./test_contract --release - Command::cargo_bin("pop") - .unwrap() - .current_dir(&temp_dir) - .args(&["build", "./test_contract", "--release"]) - .assert() - .success(); - - println!("Contract built!!"); - + + // Verify that the directory target has been created assert!(temp_dir.join("test_contract/target").exists()); // Verify that all the artifacts has been generated @@ -114,13 +105,6 @@ async fn contract_lifecycle() -> Result<()> { ]) .assert() .success(); - /*// pop up contract --upload-only - Command::cargo_bin("pop") - .unwrap() - .current_dir(&temp_dir.join("test_contract")) - .args(&["up", "contract", "--upload-only", "--url", default_endpoint]) - .assert() - .success();*/ // Instantiate contract, only dry-run Command::cargo_bin("pop") .unwrap() From 961a43b3ed2eeaf282fed813d82bdc4b4613e9fe Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 24 Dec 2024 14:14:30 +0900 Subject: [PATCH 10/14] cargo +nightly fmt --- crates/pop-cli/src/commands/build/mod.rs | 5 ++++- crates/pop-cli/src/commands/call/contract.rs | 10 +++++----- crates/pop-cli/src/commands/up/contract.rs | 5 ++++- crates/pop-cli/src/common/contracts.rs | 1 - crates/pop-cli/tests/contract.rs | 17 ++++++++--------- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/crates/pop-cli/src/commands/build/mod.rs b/crates/pop-cli/src/commands/build/mod.rs index 465fcf6d4..0403a8461 100644 --- a/crates/pop-cli/src/commands/build/mod.rs +++ b/crates/pop-cli/src/commands/build/mod.rs @@ -1,6 +1,9 @@ // SPDX-License-Identifier: GPL-3.0 -use crate::{common::contracts::get_project_path, cli::{self, Cli}}; +use crate::{ + cli::{self, Cli}, + common::contracts::get_project_path, +}; use clap::{Args, Subcommand}; #[cfg(feature = "contract")] use contract::BuildContract; diff --git a/crates/pop-cli/src/commands/call/contract.rs b/crates/pop-cli/src/commands/call/contract.rs index dd57d3098..2a3b684b1 100644 --- a/crates/pop-cli/src/commands/call/contract.rs +++ b/crates/pop-cli/src/commands/call/contract.rs @@ -3,7 +3,7 @@ use crate::{ cli::{self, traits::*}, common::{ - contracts::{has_contract_been_built, get_project_path}, + contracts::{get_project_path, has_contract_been_built}, wallet::{prompt_to_use_wallet, request_signature}, }, }; @@ -115,10 +115,10 @@ impl CallContractCommand { if let Some(path) = &self.path { full_message.push_str(&format!(" --path {}", path.display())); - } - if let Some(path_pos) = &self.path_pos { + } + if let Some(path_pos) = &self.path_pos { full_message.push_str(&format!(" --path {}", path_pos.display())); - } + } if let Some(contract) = &self.contract { full_message.push_str(&format!(" --contract {}", contract)); } @@ -791,7 +791,7 @@ mod tests { true, Some(items), 1, // "get" message - ) + ) .expect_input( "Where is your contract deployed?", "wss://rpc1.paseo.popnetwork.xyz".into(), diff --git a/crates/pop-cli/src/commands/up/contract.rs b/crates/pop-cli/src/commands/up/contract.rs index 0128e6983..e50938c06 100644 --- a/crates/pop-cli/src/commands/up/contract.rs +++ b/crates/pop-cli/src/commands/up/contract.rs @@ -3,7 +3,10 @@ use crate::{ cli::{traits::Cli as _, Cli}, common::{ - contracts::{check_contracts_node_and_prompt, has_contract_been_built, terminate_node, get_project_path}, + contracts::{ + check_contracts_node_and_prompt, get_project_path, has_contract_been_built, + terminate_node, + }, wallet::request_signature, }, style::style, diff --git a/crates/pop-cli/src/common/contracts.rs b/crates/pop-cli/src/common/contracts.rs index 2f04c3295..d3b16a933 100644 --- a/crates/pop-cli/src/common/contracts.rs +++ b/crates/pop-cli/src/common/contracts.rs @@ -126,7 +126,6 @@ pub fn has_contract_been_built(path: Option<&Path>) -> bool { .unwrap_or_default() } - pub fn get_project_path(path_flag: Option, path_pos: Option) -> Option { let project_path = if let Some(ref path) = path_pos { Some(path) // Use positional path if present diff --git a/crates/pop-cli/tests/contract.rs b/crates/pop-cli/tests/contract.rs index 7e45308ae..a095702a0 100644 --- a/crates/pop-cli/tests/contract.rs +++ b/crates/pop-cli/tests/contract.rs @@ -67,15 +67,14 @@ async fn contract_lifecycle() -> Result<()> { .success(); assert!(temp_dir.join("test_contract").exists()); - // pop build --path ./test_contract --release - Command::cargo_bin("pop") - .unwrap() - .current_dir(&temp_dir) - .args(&["build", "--path", "./test_contract", "--release"]) - .assert() - .success(); - - + // pop build --path ./test_contract --release + Command::cargo_bin("pop") + .unwrap() + .current_dir(&temp_dir) + .args(&["build", "--path", "./test_contract", "--release"]) + .assert() + .success(); + // Verify that the directory target has been created assert!(temp_dir.join("test_contract/target").exists()); // Verify that all the artifacts has been generated From 701a125b48a96c72fb1ff0c46b8b0f15dda8ece2 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 24 Dec 2024 14:21:18 +0900 Subject: [PATCH 11/14] Review corrections implemented --- crates/pop-cli/src/commands/call/contract.rs | 2 +- crates/pop-cli/src/commands/up/contract.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/pop-cli/src/commands/call/contract.rs b/crates/pop-cli/src/commands/call/contract.rs index 2a3b684b1..0ccd4fe7a 100644 --- a/crates/pop-cli/src/commands/call/contract.rs +++ b/crates/pop-cli/src/commands/call/contract.rs @@ -161,7 +161,7 @@ impl CallContractCommand { let spinner = spinner(); spinner.start("Building contract in RELEASE mode..."); let result = match build_smart_contract( - project_path.as_deref().map(|v| v), + project_path.as_deref(), true, Verbosity::Quiet, ) { diff --git a/crates/pop-cli/src/commands/up/contract.rs b/crates/pop-cli/src/commands/up/contract.rs index e50938c06..7300ec7cf 100644 --- a/crates/pop-cli/src/commands/up/contract.rs +++ b/crates/pop-cli/src/commands/up/contract.rs @@ -100,7 +100,7 @@ impl UpContractCommand { let project_path = get_project_path(self.path.clone(), self.path_pos.clone()); // Check if build exists in the specified "Contract build directory" - if !has_contract_been_built(project_path.as_deref().map(|v| v)) { + if !has_contract_been_built(project_path.as_deref()) { // Build the contract in release mode Cli.warning("NOTE: contract has not yet been built.")?; let spinner = spinner(); From b4af4fd69b3d083238f03c7fcecfe6d736fecac1 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 31 Dec 2024 11:02:30 +0900 Subject: [PATCH 12/14] cargo fmt --- crates/pop-cli/src/commands/call/contract.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/pop-cli/src/commands/call/contract.rs b/crates/pop-cli/src/commands/call/contract.rs index 0ccd4fe7a..f383d394a 100644 --- a/crates/pop-cli/src/commands/call/contract.rs +++ b/crates/pop-cli/src/commands/call/contract.rs @@ -160,11 +160,7 @@ impl CallContractCommand { cli.warning("NOTE: contract has not yet been built.")?; let spinner = spinner(); spinner.start("Building contract in RELEASE mode..."); - let result = match build_smart_contract( - project_path.as_deref(), - true, - Verbosity::Quiet, - ) { + let result = match build_smart_contract(project_path.as_deref(), true, Verbosity::Quiet) { Ok(result) => result, Err(e) => { return Err(anyhow!(format!( From 4b19b409ecc0789272a44c16760c223a1965590e Mon Sep 17 00:00:00 2001 From: ndkazu Date: Wed, 1 Jan 2025 11:30:08 +0900 Subject: [PATCH 13/14] Fixing CI errors --- crates/pop-cli/src/commands/build/mod.rs | 2 +- crates/pop-cli/src/commands/call/contract.rs | 3 ++- crates/pop-cli/src/commands/up/contract.rs | 6 ++---- crates/pop-cli/src/common/builds.rs | 11 +++++++++++ crates/pop-cli/src/common/contracts.rs | 9 --------- crates/pop-cli/src/common/mod.rs | 1 + 6 files changed, 17 insertions(+), 15 deletions(-) create mode 100644 crates/pop-cli/src/common/builds.rs diff --git a/crates/pop-cli/src/commands/build/mod.rs b/crates/pop-cli/src/commands/build/mod.rs index 0403a8461..1f805f8df 100644 --- a/crates/pop-cli/src/commands/build/mod.rs +++ b/crates/pop-cli/src/commands/build/mod.rs @@ -2,7 +2,7 @@ use crate::{ cli::{self, Cli}, - common::contracts::get_project_path, + common::builds::get_project_path, }; use clap::{Args, Subcommand}; #[cfg(feature = "contract")] diff --git a/crates/pop-cli/src/commands/call/contract.rs b/crates/pop-cli/src/commands/call/contract.rs index f383d394a..629ca204b 100644 --- a/crates/pop-cli/src/commands/call/contract.rs +++ b/crates/pop-cli/src/commands/call/contract.rs @@ -3,7 +3,8 @@ use crate::{ cli::{self, traits::*}, common::{ - contracts::{get_project_path, has_contract_been_built}, + builds::get_project_path, + contracts::has_contract_been_built, wallet::{prompt_to_use_wallet, request_signature}, }, }; diff --git a/crates/pop-cli/src/commands/up/contract.rs b/crates/pop-cli/src/commands/up/contract.rs index 7300ec7cf..c11e55e5c 100644 --- a/crates/pop-cli/src/commands/up/contract.rs +++ b/crates/pop-cli/src/commands/up/contract.rs @@ -3,10 +3,8 @@ use crate::{ cli::{traits::Cli as _, Cli}, common::{ - contracts::{ - check_contracts_node_and_prompt, get_project_path, has_contract_been_built, - terminate_node, - }, + builds::get_project_path, + contracts::{check_contracts_node_and_prompt, has_contract_been_built, terminate_node}, wallet::request_signature, }, style::style, diff --git a/crates/pop-cli/src/common/builds.rs b/crates/pop-cli/src/common/builds.rs new file mode 100644 index 000000000..5d0aa37dc --- /dev/null +++ b/crates/pop-cli/src/common/builds.rs @@ -0,0 +1,11 @@ +use std::path::PathBuf; + +/// This method is used to get the proper project path format (with or without cli flag) +pub fn get_project_path(path_flag: Option, path_pos: Option) -> Option { + let project_path = if let Some(ref path) = path_pos { + Some(path) // Use positional path if present + } else { + path_flag.as_ref() // Otherwise, use the named path + }; + project_path.cloned() +} diff --git a/crates/pop-cli/src/common/contracts.rs b/crates/pop-cli/src/common/contracts.rs index d3b16a933..a3b8f878c 100644 --- a/crates/pop-cli/src/common/contracts.rs +++ b/crates/pop-cli/src/common/contracts.rs @@ -126,15 +126,6 @@ pub fn has_contract_been_built(path: Option<&Path>) -> bool { .unwrap_or_default() } -pub fn get_project_path(path_flag: Option, path_pos: Option) -> Option { - let project_path = if let Some(ref path) = path_pos { - Some(path) // Use positional path if present - } else { - path_flag.as_ref() // Otherwise, use the named path - }; - project_path.cloned() -} - #[cfg(test)] mod tests { use super::*; diff --git a/crates/pop-cli/src/common/mod.rs b/crates/pop-cli/src/common/mod.rs index 4a89036e5..512d2a670 100644 --- a/crates/pop-cli/src/common/mod.rs +++ b/crates/pop-cli/src/common/mod.rs @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0 +pub mod builds; #[cfg(feature = "contract")] pub mod contracts; pub mod helpers; From 431da4d2aaf037d747fce97f9f0465621ff2e1d5 Mon Sep 17 00:00:00 2001 From: ndkazu Date: Wed, 1 Jan 2025 11:34:37 +0900 Subject: [PATCH 14/14] License --- crates/pop-cli/src/common/builds.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/pop-cli/src/common/builds.rs b/crates/pop-cli/src/common/builds.rs index 5d0aa37dc..1192ed0cc 100644 --- a/crates/pop-cli/src/common/builds.rs +++ b/crates/pop-cli/src/common/builds.rs @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-3.0 use std::path::PathBuf; /// This method is used to get the proper project path format (with or without cli flag)