From 12610ef95a59965c3d22b0a23ebfa0f09f76f30c Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Wed, 28 Aug 2024 11:31:23 +0200 Subject: [PATCH 01/18] feat: include new parachain template and remove old one for Parity --- crates/pop-cli/src/commands/new/parachain.rs | 5 +-- crates/pop-parachains/src/templates.rs | 42 ++++++++++---------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/crates/pop-cli/src/commands/new/parachain.rs b/crates/pop-cli/src/commands/new/parachain.rs index ba69ea44..caff36bf 100644 --- a/crates/pop-cli/src/commands/new/parachain.rs +++ b/crates/pop-cli/src/commands/new/parachain.rs @@ -112,10 +112,9 @@ async fn guide_user_to_generate_parachain() -> Result { provider, provider.name(), format!( - "{} {} available option(s) {}", + "{} {} available option(s)", provider.description(), - provider.templates().len(), - if provider.name() == "Parity" { "[deprecated]" } else { "" } + provider.templates().len() ), ); } diff --git a/crates/pop-parachains/src/templates.rs b/crates/pop-parachains/src/templates.rs index 83342308..2ccb3400 100644 --- a/crates/pop-parachains/src/templates.rs +++ b/crates/pop-parachains/src/templates.rs @@ -38,7 +38,7 @@ impl Type for Provider { match &self { Provider::Pop => Some(Parachain::Standard), Provider::OpenZeppelin => Some(Parachain::OpenZeppelinGeneric), - Provider::Parity => Some(Parachain::ParityContracts), + Provider::Parity => Some(Parachain::ParityGeneric), } } } @@ -131,6 +131,18 @@ pub enum Parachain { ) )] OpenZeppelinGeneric, + /// The Parachain-Ready Template From Polkadot SDK. + #[strum( + serialize = "polkadot-sdk-parachain-template", + message = "Polkadot SDK's Parachain Template", + detailed_message = "The Parachain-Ready Template From Polkadot SDK.", + props( + Provider = "Parity", + Repository = "https://github.com/paritytech/polkadot-sdk-parachain-template", + Network = "./zombienet.toml" + ) + )] + ParityGeneric, /// Minimal Substrate node configured for smart contracts via pallet-contracts. #[strum( serialize = "cpt", @@ -143,19 +155,6 @@ pub enum Parachain { ) )] ParityContracts, - /// Template node for a Frontier (EVM) based parachain. - #[strum( - serialize = "fpt", - message = "EVM", - detailed_message = "Template node for a Frontier (EVM) based parachain.", - props( - Provider = "Parity", - Repository = "https://github.com/paritytech/frontier-parachain-template", - Network = "./zombienet-config.toml" - ) - )] - ParityFPT, - // templates for unit tests below #[cfg(test)] #[strum( @@ -221,8 +220,8 @@ mod tests { ("evm".to_string(), EVM), // openzeppelin ("polkadot-generic-runtime-template".to_string(), OpenZeppelinGeneric), + ("polkadot-sdk-parachain-template".to_string(), ParityGeneric), ("cpt".to_string(), ParityContracts), - ("fpt".to_string(), ParityFPT), ("test_01".to_string(), TestTemplate01), ("test_02".to_string(), TestTemplate02), ]) @@ -239,8 +238,11 @@ mod tests { "polkadot-generic-runtime-template".to_string(), "https://github.com/OpenZeppelin/polkadot-runtime-templates", ), + ( + "polkadot-sdk-parachain-template".to_string(), + "https://github.com/paritytech/polkadot-sdk-parachain-template", + ), ("cpt".to_string(), "https://github.com/paritytech/substrate-contracts-node"), - ("fpt".to_string(), "https://github.com/paritytech/frontier-parachain-template"), ("test_01".to_string(), ""), ("test_02".to_string(), ""), ]) @@ -253,8 +255,8 @@ mod tests { (Contracts, Some("./network.toml")), (EVM, Some("./network.toml")), (OpenZeppelinGeneric, Some("./zombienet-config/devnet.toml")), + (ParityGeneric, Some("./zombienet.toml")), (ParityContracts, Some("./zombienet.toml")), - (ParityFPT, Some("./zombienet-config.toml")), (TestTemplate01, Some("")), (TestTemplate02, Some("")), ] @@ -268,7 +270,7 @@ mod tests { assert_eq!(Provider::Pop.provides(&template), true); assert_eq!(Provider::Parity.provides(&template), false); } - if matches!(template, ParityContracts | ParityFPT) { + if matches!(template, ParityContracts | ParityGeneric) { assert_eq!(Provider::Pop.provides(&template), false); assert_eq!(Provider::Parity.provides(&template), true) } @@ -313,7 +315,7 @@ mod tests { let mut provider = Provider::Pop; assert_eq!(provider.default_template(), Some(Standard)); provider = Provider::Parity; - assert_eq!(provider.default_template(), Some(ParityContracts)); + assert_eq!(provider.default_template(), Some(ParityGeneric)); } #[test] @@ -321,7 +323,7 @@ mod tests { let mut provider = Provider::Pop; assert_eq!(provider.templates(), [&Standard, &Assets, &Contracts, &EVM]); provider = Provider::Parity; - assert_eq!(provider.templates(), [&ParityContracts, &ParityFPT]); + assert_eq!(provider.templates(), [&ParityContracts, &ParityGeneric]); } #[test] From 31ac60d4d6a0d63a4c4b49e8834d3adcbec67304 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 29 Aug 2024 08:52:55 +0200 Subject: [PATCH 02/18] fix: tests --- crates/pop-cli/src/commands/new/parachain.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/pop-cli/src/commands/new/parachain.rs b/crates/pop-cli/src/commands/new/parachain.rs index caff36bf..0d702440 100644 --- a/crates/pop-cli/src/commands/new/parachain.rs +++ b/crates/pop-cli/src/commands/new/parachain.rs @@ -436,11 +436,11 @@ mod tests { fn test_is_template_supported() -> Result<()> { is_template_supported(&Provider::Pop, &Parachain::Standard)?; assert!(is_template_supported(&Provider::Pop, &Parachain::ParityContracts).is_err()); - assert!(is_template_supported(&Provider::Pop, &Parachain::ParityFPT).is_err()); + assert!(is_template_supported(&Provider::Pop, &Parachain::ParityGeneric).is_err()); assert!(is_template_supported(&Provider::Parity, &Parachain::Standard).is_err()); is_template_supported(&Provider::Parity, &Parachain::ParityContracts)?; - is_template_supported(&Provider::Parity, &Parachain::ParityFPT) + is_template_supported(&Provider::Parity, &Parachain::ParityGeneric) } #[test] From fec60a8bf7624fd5490009abe891ff9d6dd0d8c1 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 29 Aug 2024 09:20:03 +0200 Subject: [PATCH 03/18] fix: order in test --- crates/pop-parachains/src/templates.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/pop-parachains/src/templates.rs b/crates/pop-parachains/src/templates.rs index 2ccb3400..7192ac7b 100644 --- a/crates/pop-parachains/src/templates.rs +++ b/crates/pop-parachains/src/templates.rs @@ -323,7 +323,7 @@ mod tests { let mut provider = Provider::Pop; assert_eq!(provider.templates(), [&Standard, &Assets, &Contracts, &EVM]); provider = Provider::Parity; - assert_eq!(provider.templates(), [&ParityContracts, &ParityGeneric]); + assert_eq!(provider.templates(), [&ParityGeneric, &ParityContracts]); } #[test] From 392bdd97c316bcfb85254d9457ab4cfe524fb93a Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Wed, 4 Sep 2024 17:35:08 +0200 Subject: [PATCH 04/18] fix: export PATH --- crates/pop-parachains/src/new_parachain.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/pop-parachains/src/new_parachain.rs b/crates/pop-parachains/src/new_parachain.rs index adfe82e9..088500f8 100644 --- a/crates/pop-parachains/src/new_parachain.rs +++ b/crates/pop-parachains/src/new_parachain.rs @@ -10,7 +10,7 @@ use pop_common::{ git::Git, templates::{Template, Type}, }; -use std::{fs, path::Path}; +use std::{env, fs, path::Path}; use walkdir::WalkDir; /// Create a new parachain. @@ -32,6 +32,10 @@ pub fn instantiate_template_dir( if Provider::Pop.provides(&template) { return instantiate_standard_template(template, target, config, tag_version); } + if Provider::Parity.provides(&template) { + // export PATH="./target/release/:$PATH" + env::set_var("PATH", format!("./target/release/:{}", env::var("PATH")?)); + } let tag = Git::clone_and_degit(template.repository_url()?, target, tag_version)?; Ok(tag) } From e5ab43607f8aca7dc9dc842ff7972fa971c715ca Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 12 Sep 2024 13:56:05 +0200 Subject: [PATCH 05/18] chore: bump zombienet-sdk version --- Cargo.lock | 26 +++++++++++++------------- Cargo.toml | 3 +-- crates/pop-parachains/Cargo.toml | 1 - crates/pop-parachains/src/up/mod.rs | 8 ++++---- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5943f556..639542d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4776,7 +4776,6 @@ dependencies = [ "url", "walkdir", "zombienet-sdk", - "zombienet-support", ] [[package]] @@ -8515,9 +8514,9 @@ dependencies = [ [[package]] name = "zombienet-configuration" -version = "0.2.7" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5ee069fa52f2057eaae7f27f0c638d4a5f630e42159f66665398681cdd82d4f" +checksum = "23322e411b8d19b41b5c20ab8e88c10822189a4fcfd069c7fcd1542b8d3035aa" dependencies = [ "anyhow", "lazy_static", @@ -8533,9 +8532,9 @@ dependencies = [ [[package]] name = "zombienet-orchestrator" -version = "0.2.7" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdbffc9d2fd1c8f727718a197f7fc65ad7b7a2397855f87a6deb738a26d499f8" +checksum = "381f701565b3918a909132743b3674569ce3da25b5c3a6493883abaf1046577a" dependencies = [ "anyhow", "async-trait", @@ -8543,6 +8542,7 @@ dependencies = [ "glob-match", "hex", "libp2p", + "libsecp256k1", "multiaddr", "rand", "regex", @@ -8565,9 +8565,9 @@ dependencies = [ [[package]] name = "zombienet-prom-metrics-parser" -version = "0.2.7" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af494234607b9bbfee8b6ab93a0b85c5f9238c6ffdb9c46f1db3e811b1940e0e" +checksum = "dab79fa58bcfecbcd41485c6f13052853ccde8b09f173b601f78747d7abc2b7f" dependencies = [ "pest", "pest_derive", @@ -8576,9 +8576,9 @@ dependencies = [ [[package]] name = "zombienet-provider" -version = "0.2.7" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c900c3a42098db63bbf4ac1b3ce37157d66a1e6627ac4c806bf7a346253a9093" +checksum = "6af0264938da61b25da89f17ee0630393a4ba793582a4a8a1650eb15b47fc1ef" dependencies = [ "anyhow", "async-trait", @@ -8607,9 +8607,9 @@ dependencies = [ [[package]] name = "zombienet-sdk" -version = "0.2.7" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27224e17fd674c21c1ac16280bc85d2333ee71520fa02a1c6de6aa6f642aa1b5" +checksum = "5bc5b7ebfba4ab62486c8cb5bcd7345c4376487487cfe3481476cb4d4accc75e" dependencies = [ "async-trait", "futures", @@ -8624,9 +8624,9 @@ dependencies = [ [[package]] name = "zombienet-support" -version = "0.2.7" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f4ec8f69b9c4b6407ae721911da25df0c99a1d70da1e4b9d7ee11bcbea0594a" +checksum = "6f5b80d34a0eecca69dd84c2e13f84f1fae0cc378baf4f15f769027af068418b" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 8ca9fa23..3a2e1904 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,8 +60,7 @@ toml_edit = { version = "0.22", features = ["serde"] } symlink = "0.1" serde_json = { version = "1.0", features = ["preserve_order"] } serde = { version = "1.0", features = ["derive"] } -zombienet-sdk = "0.2.7" -zombienet-support = "0.2.7" +zombienet-sdk = "0.2.10" git2_credentials = "0.13.0" # pop-cli diff --git a/crates/pop-parachains/Cargo.toml b/crates/pop-parachains/Cargo.toml index 1ac8166b..4b135c8f 100644 --- a/crates/pop-parachains/Cargo.toml +++ b/crates/pop-parachains/Cargo.toml @@ -31,7 +31,6 @@ toml_edit.workspace = true walkdir.workspace = true # Zombienet zombienet-sdk.workspace = true -zombienet-support.workspace = true # Pop pop-common = { path = "../pop-common", version = "0.3.0" } diff --git a/crates/pop-parachains/src/up/mod.rs b/crates/pop-parachains/src/up/mod.rs index 192da7ff..56201e3f 100644 --- a/crates/pop-parachains/src/up/mod.rs +++ b/crates/pop-parachains/src/up/mod.rs @@ -16,8 +16,7 @@ use std::{ use symlink::{remove_symlink_file, symlink_file}; use tempfile::{Builder, NamedTempFile}; use toml_edit::{value, ArrayOfTables, DocumentMut, Formatted, Item, Table, Value}; -use zombienet_sdk::{Network, NetworkConfig, NetworkConfigExt}; -use zombienet_support::fs::local::LocalFileSystem; +use zombienet_sdk::{LocalFileSystem, Network, NetworkConfig, NetworkConfigExt}; mod chain_specs; mod parachains; @@ -252,12 +251,13 @@ 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) From 5da07ef0e2d054c21cf7a3bdd66f8063faa2dad6 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 12 Sep 2024 14:06:54 +0200 Subject: [PATCH 06/18] fix: remove parity evm --- crates/pop-cli/src/commands/new/parachain.rs | 16 ++++++++++++---- crates/pop-parachains/src/templates.rs | 16 +--------------- crates/pop-parachains/src/up/mod.rs | 5 ++--- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/crates/pop-cli/src/commands/new/parachain.rs b/crates/pop-cli/src/commands/new/parachain.rs index 6febcba4..859f1f7d 100644 --- a/crates/pop-cli/src/commands/new/parachain.rs +++ b/crates/pop-cli/src/commands/new/parachain.rs @@ -215,7 +215,7 @@ async fn generate_parachain_from_template( // add next steps let mut next_steps = vec![ format!("cd into \"{name_template}\" and enjoy hacking! 🚀"), - "Use `pop build` to build your parachain.".into(), + "Use `pop build --release` to build your parachain.".into(), ]; if let Some(network_config) = template.network_config() { next_steps.push(format!( @@ -252,7 +252,15 @@ fn display_select_options(provider: &Provider) -> Result<&Parachain> { if i == 0 { prompt = prompt.initial_value(template); } - prompt = prompt.item(template, template.name(), template.description()); + prompt = prompt.item( + template, + template.name(), + format!( + "{} {}", + template.description(), + if matches!(template, Parachain::ParityContracts) { "[deprecated]" } else { "" } + ), + ); } Ok(prompt.interact()?) } @@ -263,8 +271,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-parachains/src/templates.rs b/crates/pop-parachains/src/templates.rs index 0f7c03bd..80aea45d 100644 --- a/crates/pop-parachains/src/templates.rs +++ b/crates/pop-parachains/src/templates.rs @@ -162,20 +162,6 @@ pub enum Parachain { ) )] ParityContracts, - /// Template node for a Frontier (EVM) based parachain. - #[strum( - serialize = "fpt", - message = "EVM", - detailed_message = "Template node for a Frontier (EVM) based parachain.", - props( - Provider = "Parity", - Repository = "https://github.com/paritytech/frontier-parachain-template", - Network = "./zombienet-config.toml", - License = "Unlicense" - ) - )] - ParityFPT, - // templates for unit tests below #[cfg(test)] #[strum( @@ -296,8 +282,8 @@ mod tests { (Contracts, Some("Unlicense")), (EVM, Some("Unlicense")), (OpenZeppelinGeneric, Some("GPL-3.0")), + (ParityGeneric, Some("Unlicense")), (ParityContracts, Some("Unlicense")), - (ParityFPT, Some("Unlicense")), (TestTemplate01, Some("Unlicense")), (TestTemplate02, Some("GPL-3.0")), ] diff --git a/crates/pop-parachains/src/up/mod.rs b/crates/pop-parachains/src/up/mod.rs index 56201e3f..232fd7bc 100644 --- a/crates/pop-parachains/src/up/mod.rs +++ b/crates/pop-parachains/src/up/mod.rs @@ -251,13 +251,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) From 6070af6a1076890831716e7c6da41a76935fb278 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 12 Sep 2024 14:11:53 +0200 Subject: [PATCH 07/18] fix: missing changes --- crates/pop-cli/src/commands/new/parachain.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/pop-cli/src/commands/new/parachain.rs b/crates/pop-cli/src/commands/new/parachain.rs index 859f1f7d..8ab6ab42 100644 --- a/crates/pop-cli/src/commands/new/parachain.rs +++ b/crates/pop-cli/src/commands/new/parachain.rs @@ -271,8 +271,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)) From dbf1ee743ec11fb5ecfa8f6167af0ac2f83cb89b Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 12 Sep 2024 15:26:56 +0200 Subject: [PATCH 08/18] fix: parse collator and parachain-template-node without path for spawn --- crates/pop-parachains/src/up/mod.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crates/pop-parachains/src/up/mod.rs b/crates/pop-parachains/src/up/mod.rs index 232fd7bc..f0291bfe 100644 --- a/crates/pop-parachains/src/up/mod.rs +++ b/crates/pop-parachains/src/up/mod.rs @@ -149,6 +149,14 @@ impl Zombienet { } } } + // Check if collator has defined command + if let Some(collator) = table.get("collator").and_then(|i| i.as_table()) { + if let Some(command) = + NetworkConfiguration::command(collator).and_then(|i| i.as_str()) + { + return Some(Item::Value(Value::String(Formatted::new(command.into())))); + } + } // Otherwise default to polkadot-parachain Some(Item::Value(Value::String(Formatted::new("polkadot-parachain".into())))) @@ -200,6 +208,18 @@ impl Zombienet { continue; } + // Check if command references to a template local binary without path + if command == "parachain-template-node" { + paras.insert( + id, + Parachain::from_local( + id, + PathBuf::from("./target/release/parachain-template-node"), + chain, + )?, + ); + continue; + } return Err(Error::MissingBinary(command)); } Ok(paras) @@ -453,6 +473,12 @@ impl NetworkConfiguration { } } } + // Resolve individual collator command to binary + if let Some(collator) = table.get_mut("collator").and_then(|p| p.as_table_mut()) { + if let Some(command) = NetworkConfiguration::command_mut(collator) { + *command = value(&path) + } + } } } From d83700de6b02afbf89b59c9ce8d49f2b6a321544 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 12 Sep 2024 15:35:58 +0200 Subject: [PATCH 09/18] chore: remove set PATH --- crates/pop-parachains/src/new_parachain.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/pop-parachains/src/new_parachain.rs b/crates/pop-parachains/src/new_parachain.rs index 088500f8..adfe82e9 100644 --- a/crates/pop-parachains/src/new_parachain.rs +++ b/crates/pop-parachains/src/new_parachain.rs @@ -10,7 +10,7 @@ use pop_common::{ git::Git, templates::{Template, Type}, }; -use std::{env, fs, path::Path}; +use std::{fs, path::Path}; use walkdir::WalkDir; /// Create a new parachain. @@ -32,10 +32,6 @@ pub fn instantiate_template_dir( if Provider::Pop.provides(&template) { return instantiate_standard_template(template, target, config, tag_version); } - if Provider::Parity.provides(&template) { - // export PATH="./target/release/:$PATH" - env::set_var("PATH", format!("./target/release/:{}", env::var("PATH")?)); - } let tag = Git::clone_and_degit(template.repository_url()?, target, tag_version)?; Ok(tag) } From 316de338481853a14b45aae776ebf4c8cc89c30e Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 12 Sep 2024 22:42:52 +0200 Subject: [PATCH 10/18] refactor: functionality and test --- crates/pop-parachains/src/up/mod.rs | 74 +++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 10 deletions(-) diff --git a/crates/pop-parachains/src/up/mod.rs b/crates/pop-parachains/src/up/mod.rs index f0291bfe..44770246 100644 --- a/crates/pop-parachains/src/up/mod.rs +++ b/crates/pop-parachains/src/up/mod.rs @@ -208,16 +208,14 @@ impl Zombienet { continue; } - // Check if command references to a template local binary without path + // Check if command references a parachain template binary without a specified path + // (e.g. Polkadot SDK parachain template) if command == "parachain-template-node" { - paras.insert( - id, - Parachain::from_local( - id, - PathBuf::from("./target/release/parachain-template-node"), - chain, - )?, - ); + let binary_path = PathBuf::from("./target/release").join("parachain-template-node"); + if !binary_path.exists() { + return Err(Error::MissingBinary(command)); + } + paras.insert(id, Parachain::from_local(id, binary_path, chain)?); continue; } return Err(Error::MissingBinary(command)); @@ -677,7 +675,11 @@ fn resolve_manifest(package: &str, path: &Path) -> Result, Error mod tests { use super::*; use anyhow::Result; - use std::{env::current_dir, fs::File, io::Write}; + use std::{ + env::current_dir, + fs::{create_dir_all, remove_dir, remove_file, File}, + io::Write, + }; use tempfile::tempdir; mod zombienet { @@ -1124,6 +1126,58 @@ default_command = "./target/release/parachain-template-node" Ok(()) } + #[tokio::test] + async fn new_with_local_parachain_without_path_works() -> Result<()> { + let temp_dir = tempdir()?; + let cache = PathBuf::from(temp_dir.path()); + let config = Builder::new().suffix(".toml").tempfile()?; + writeln!( + config.as_file(), + r#" +[relaychain] +chain = "rococo-local" + +[[parachains]] +id = 1000 + +[parachains.collator] +name = "collator" +command = "parachain-template-node" +"# + )?; + assert!(matches!( + Zombienet::new(&cache, config.path().to_str().unwrap(), None, None, None, None, None).await, + Err(Error::MissingBinary(command)) + if command == "parachain-template-node" + )); + // Create the binary in the hardcoded path + let parachain_template = PathBuf::from("target/release/parachain-template-node"); + create_dir_all(parachain_template.parent().unwrap())?; + File::create(¶chain_template)?; + + let zombienet = Zombienet::new( + &cache, + config.path().to_str().unwrap(), + None, + None, + None, + None, + None, + ) + .await?; + // Remove the binary hardcoded path + remove_file(¶chain_template)?; + remove_dir(parachain_template.parent().unwrap())?; + + assert_eq!(zombienet.parachains.len(), 1); + let parachain = &zombienet.parachains.get(&1000).unwrap().binary; + assert_eq!(parachain.name(), "parachain-template-node"); + assert_eq!(parachain.path(), Path::new("./target/release/parachain-template-node")); + assert_eq!(parachain.version(), None); + assert!(matches!(parachain, Binary::Local { .. })); + Ok(()) + } + #[tokio::test] async fn new_with_collator_command_works() -> Result<()> { let temp_dir = tempdir()?; From 9f2076b15a3f8e202c0d64aa100edfa3b4693fd9 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Tue, 17 Sep 2024 10:47:40 +0200 Subject: [PATCH 11/18] refactor: prefix for external templates --- crates/pop-parachains/src/templates.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/crates/pop-parachains/src/templates.rs b/crates/pop-parachains/src/templates.rs index 80aea45d..022e8597 100644 --- a/crates/pop-parachains/src/templates.rs +++ b/crates/pop-parachains/src/templates.rs @@ -123,7 +123,7 @@ pub enum Parachain { EVM, // OpenZeppelin #[strum( - serialize = "polkadot-generic-runtime-template", + serialize = "openzeppelin/polkadot-generic-runtime-template", message = "Generic Runtime Template", detailed_message = "A generic template for Substrate Runtime", props( @@ -138,7 +138,7 @@ pub enum Parachain { OpenZeppelinGeneric, /// The Parachain-Ready Template From Polkadot SDK. #[strum( - serialize = "polkadot-sdk-parachain-template", + serialize = "parity/polkadot-sdk-parachain-template", message = "Polkadot SDK's Parachain Template", detailed_message = "The Parachain-Ready Template From Polkadot SDK.", props( @@ -151,7 +151,7 @@ pub enum Parachain { ParityGeneric, /// Minimal Substrate node configured for smart contracts via pallet-contracts. #[strum( - serialize = "cpt", + serialize = "parity/contracts", message = "Contracts", detailed_message = "Minimal Substrate node configured for smart contracts via pallet-contracts.", props( @@ -231,9 +231,9 @@ mod tests { ("contracts".to_string(), Contracts), ("evm".to_string(), EVM), // openzeppelin - ("polkadot-generic-runtime-template".to_string(), OpenZeppelinGeneric), - ("polkadot-sdk-parachain-template".to_string(), ParityGeneric), - ("cpt".to_string(), ParityContracts), + ("openzeppelin/polkadot-generic-runtime-template".to_string(), OpenZeppelinGeneric), + ("parity/polkadot-sdk-parachain-template".to_string(), ParityGeneric), + ("parity/contracts".to_string(), ParityContracts), ("test_01".to_string(), TestTemplate01), ("test_02".to_string(), TestTemplate02), ]) @@ -247,14 +247,17 @@ mod tests { ("evm".to_string(), "https://github.com/r0gue-io/evm-parachain"), // openzeppelin ( - "polkadot-generic-runtime-template".to_string(), + "openzeppelin/polkadot-generic-runtime-template".to_string(), "https://github.com/OpenZeppelin/polkadot-runtime-templates", ), ( - "polkadot-sdk-parachain-template".to_string(), + "parity/polkadot-sdk-parachain-template".to_string(), "https://github.com/paritytech/polkadot-sdk-parachain-template", ), - ("cpt".to_string(), "https://github.com/paritytech/substrate-contracts-node"), + ( + "parity/contracts".to_string(), + "https://github.com/paritytech/substrate-contracts-node", + ), ("test_01".to_string(), ""), ("test_02".to_string(), ""), ]) From 7addd9bbbf33cf591c3d1262b4f286ba67c6bd43 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Wed, 18 Sep 2024 16:54:18 +0200 Subject: [PATCH 12/18] fix: deprecate old command for generating parity contracts template --- crates/pop-common/src/templates/mod.rs | 22 +++++++++++-- crates/pop-parachains/src/templates.rs | 45 ++++++++++++++++++++------ 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/crates/pop-common/src/templates/mod.rs b/crates/pop-common/src/templates/mod.rs index e4f7604a..4e7329f7 100644 --- a/crates/pop-common/src/templates/mod.rs +++ b/crates/pop-common/src/templates/mod.rs @@ -45,6 +45,11 @@ pub trait Template: fn template_type(&self) -> Result<&str, Error> { self.get_str(Self::PROPERTY).ok_or(Error::TypeMissing) } + + /// Get if the template is deprecated + fn is_deprecated(&self) -> bool { + self.get_str("IsDeprecated").map_or(false, |s| s == "true") + } } /// A trait for defining overarching types of specific template variants. @@ -74,9 +79,10 @@ pub trait Type: Clone + Default + EnumMessage + Eq + PartialEq + Va /// Get the list of templates of the type. fn templates(&self) -> Vec<&T> { + #[allow(deprecated)] T::VARIANTS .iter() - .filter(|t| t.get_str(T::PROPERTY) == Some(self.name())) + .filter(|t| t.get_str(T::PROPERTY) == Some(self.name()) && !t.is_deprecated()) .collect() } @@ -85,6 +91,12 @@ pub trait Type: Clone + Default + EnumMessage + Eq + PartialEq + Va // Match explicitly on type name (message) template.get_str(T::PROPERTY) == Some(self.name()) } + + /// Get if the type is deprecated. Currently, this function always returns `false` as there are + /// no deprecated variants. + fn is_deprecated(&self) -> bool { + false + } } #[macro_export] @@ -93,7 +105,13 @@ macro_rules! enum_variants { PossibleValuesParser::new( <$e>::VARIANTS .iter() - .map(|p| PossibleValue::new(p.as_ref())) + .filter_map(|p| { + if !p.is_deprecated() { + Some(PossibleValue::new(p.as_ref())) + } else { + None + } + }) .collect::>(), ) .try_map(|s| <$e>::from_str(&s).map_err(|e| format!("could not convert from {s} to type"))) diff --git a/crates/pop-parachains/src/templates.rs b/crates/pop-parachains/src/templates.rs index 022e8597..4d15034d 100644 --- a/crates/pop-parachains/src/templates.rs +++ b/crates/pop-parachains/src/templates.rs @@ -123,7 +123,7 @@ pub enum Parachain { EVM, // OpenZeppelin #[strum( - serialize = "openzeppelin/polkadot-generic-runtime-template", + serialize = "polkadot-generic-runtime-template", message = "Generic Runtime Template", detailed_message = "A generic template for Substrate Runtime", props( @@ -138,7 +138,7 @@ pub enum Parachain { OpenZeppelinGeneric, /// The Parachain-Ready Template From Polkadot SDK. #[strum( - serialize = "parity/polkadot-sdk-parachain-template", + serialize = "paritytech/polkadot-sdk-parachain-template", message = "Polkadot SDK's Parachain Template", detailed_message = "The Parachain-Ready Template From Polkadot SDK.", props( @@ -149,9 +149,24 @@ pub enum Parachain { ) )] ParityGeneric, + /// [Deprecated] This command is deprecated, please use 'paritytech/substrate-contracts-node' + /// instead. + #[strum( + serialize = "cpt", + message = "Contracts", + detailed_message = "Minimal Substrate node configured for smart contracts via pallet-contracts.", + props( + Provider = "Parity", + Repository = "https://github.com/paritytech/substrate-contracts-node", + Network = "./zombienet.toml", + License = "Unlicense", + IsDeprecated = "true" + ) + )] + ParityFPT, /// Minimal Substrate node configured for smart contracts via pallet-contracts. #[strum( - serialize = "parity/contracts", + serialize = "paritytech/substrate-contracts-node", message = "Contracts", detailed_message = "Minimal Substrate node configured for smart contracts via pallet-contracts.", props( @@ -174,7 +189,8 @@ pub enum Parachain { Network = "", SupportedVersions = "v1.0.0,v2.0.0", IsAudited = "true", - License = "Unlicense" + IsDeprecated = "true", + License = "Unlicense", ) )] TestTemplate01, @@ -231,9 +247,9 @@ mod tests { ("contracts".to_string(), Contracts), ("evm".to_string(), EVM), // openzeppelin - ("openzeppelin/polkadot-generic-runtime-template".to_string(), OpenZeppelinGeneric), - ("parity/polkadot-sdk-parachain-template".to_string(), ParityGeneric), - ("parity/contracts".to_string(), ParityContracts), + ("polkadot-generic-runtime-template".to_string(), OpenZeppelinGeneric), + ("paritytech/polkadot-sdk-parachain-template".to_string(), ParityGeneric), + ("paritytech/substrate-contracts-node".to_string(), ParityContracts), ("test_01".to_string(), TestTemplate01), ("test_02".to_string(), TestTemplate02), ]) @@ -247,15 +263,15 @@ mod tests { ("evm".to_string(), "https://github.com/r0gue-io/evm-parachain"), // openzeppelin ( - "openzeppelin/polkadot-generic-runtime-template".to_string(), + "polkadot-generic-runtime-template".to_string(), "https://github.com/OpenZeppelin/polkadot-runtime-templates", ), ( - "parity/polkadot-sdk-parachain-template".to_string(), + "paritytech/polkadot-sdk-parachain-template".to_string(), "https://github.com/paritytech/polkadot-sdk-parachain-template", ), ( - "parity/contracts".to_string(), + "paritytech/substrate-contracts-node".to_string(), "https://github.com/paritytech/substrate-contracts-node", ), ("test_01".to_string(), ""), @@ -404,4 +420,13 @@ mod tests { let template = TestTemplate02; assert_eq!(template.is_audited(), false); } + + #[test] + fn test_is_deprecated() { + let template = TestTemplate01; + assert_eq!(template.is_deprecated(), true); + + let template = TestTemplate02; + assert_eq!(template.is_deprecated(), false); + } } From d40ec0603d4db48f689c263eda9f989d27e3c79e Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Wed, 18 Sep 2024 17:02:12 +0200 Subject: [PATCH 13/18] test: update configure_works test to test new functionality --- crates/pop-parachains/src/up/mod.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/pop-parachains/src/up/mod.rs b/crates/pop-parachains/src/up/mod.rs index 44770246..9a81eca3 100644 --- a/crates/pop-parachains/src/up/mod.rs +++ b/crates/pop-parachains/src/up/mod.rs @@ -1633,6 +1633,14 @@ default_command = "./target/release/parachain-template-node" [[parachains.collators]] name = "collator" command = "./target/release/parachain-template-node" + +[[parachains]] +id = 2002 +default_command = "./target/release/parachain-template-node" + +[parachains.collator] +name = "collator" +command = "./target/release/parachain-template-node" "# )?; let mut network_config = NetworkConfiguration::from(config.path())?; @@ -1702,6 +1710,19 @@ command = "./target/release/parachain-template-node" chain_spec_generator: None, }, ), + ( + 2002, + Parachain { + id: 2002, + binary: Binary::Local { + name: "parachain-template-node".to_string(), + path: parachain_template.to_path_buf(), + manifest: None, + }, + chain: None, + chain_spec_generator: None, + }, + ), ] .into(), )?; @@ -1747,6 +1768,14 @@ default_command = "{3}" name = "collator" command = "{3}" +[[parachains]] +id = 2002 +default_command = "{3}" + +[parachains.collator] +name = "collator" +command = "{3}" + [settings] timeout = 1000 node_spawn_timeout = 300 From 7017d639a534b477dae8ce4104da7f52db9597bf Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Wed, 18 Sep 2024 17:16:41 +0200 Subject: [PATCH 14/18] test: fix unit tests templates --- crates/pop-parachains/src/templates.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/pop-parachains/src/templates.rs b/crates/pop-parachains/src/templates.rs index 4d15034d..c8959f76 100644 --- a/crates/pop-parachains/src/templates.rs +++ b/crates/pop-parachains/src/templates.rs @@ -163,7 +163,7 @@ pub enum Parachain { IsDeprecated = "true" ) )] - ParityFPT, + ParityCPT, /// Minimal Substrate node configured for smart contracts via pallet-contracts. #[strum( serialize = "paritytech/substrate-contracts-node", @@ -250,6 +250,7 @@ mod tests { ("polkadot-generic-runtime-template".to_string(), OpenZeppelinGeneric), ("paritytech/polkadot-sdk-parachain-template".to_string(), ParityGeneric), ("paritytech/substrate-contracts-node".to_string(), ParityContracts), + ("cpt".to_string(), ParityCPT), ("test_01".to_string(), TestTemplate01), ("test_02".to_string(), TestTemplate02), ]) @@ -274,6 +275,7 @@ mod tests { "paritytech/substrate-contracts-node".to_string(), "https://github.com/paritytech/substrate-contracts-node", ), + ("cpt".to_string(), "https://github.com/paritytech/substrate-contracts-node"), ("test_01".to_string(), ""), ("test_02".to_string(), ""), ]) @@ -288,6 +290,7 @@ mod tests { (OpenZeppelinGeneric, Some("./zombienet-config/devnet.toml")), (ParityGeneric, Some("./zombienet.toml")), (ParityContracts, Some("./zombienet.toml")), + (ParityCPT, Some("./zombienet.toml")), (TestTemplate01, Some("")), (TestTemplate02, Some("")), ] @@ -303,6 +306,7 @@ mod tests { (OpenZeppelinGeneric, Some("GPL-3.0")), (ParityGeneric, Some("Unlicense")), (ParityContracts, Some("Unlicense")), + (ParityCPT, Some("Unlicense")), (TestTemplate01, Some("Unlicense")), (TestTemplate02, Some("GPL-3.0")), ] From 9871fe2195a7d0cd2cdcdf98489e0d0abec1f7d5 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Wed, 18 Sep 2024 18:24:52 +0200 Subject: [PATCH 15/18] fix: show deprecation message and fixes --- crates/pop-cli/src/commands/new/parachain.rs | 10 +++-- crates/pop-common/src/templates/mod.rs | 32 +++++++++------- crates/pop-parachains/src/templates.rs | 40 +++++++++++++------- 3 files changed, 52 insertions(+), 30 deletions(-) diff --git a/crates/pop-cli/src/commands/new/parachain.rs b/crates/pop-cli/src/commands/new/parachain.rs index 8ab6ab42..80147883 100644 --- a/crates/pop-cli/src/commands/new/parachain.rs +++ b/crates/pop-cli/src/commands/new/parachain.rs @@ -15,7 +15,7 @@ use cliclack::{ outro, outro_cancel, }; use pop_common::{ - enum_variants, + enum_variants, enum_variants_for_help, templates::{Template, Type}, Git, GitHub, Release, }; @@ -40,8 +40,9 @@ pub struct NewParachainCommand { #[arg( short = 't', long, - help = "Template to use.", - value_parser = enum_variants!(Parachain) + help = format!("Template to use. [possible values: {}]", enum_variants_for_help!(Parachain)), + value_parser = enum_variants!(Parachain), + hide_possible_values = true // To hide the deprecated templates )] pub(crate) template: Option, #[arg( @@ -243,6 +244,9 @@ fn is_template_supported(provider: &Provider, template: &Parachain) -> Result<() provider, template ))); }; + if template.is_deprecated() { + warning(format!("NOTE: this template is deprecated.{}", template.deprecated_message()))?; + } return Ok(()); } diff --git a/crates/pop-common/src/templates/mod.rs b/crates/pop-common/src/templates/mod.rs index 4e7329f7..737746a5 100644 --- a/crates/pop-common/src/templates/mod.rs +++ b/crates/pop-common/src/templates/mod.rs @@ -50,6 +50,11 @@ pub trait Template: fn is_deprecated(&self) -> bool { self.get_str("IsDeprecated").map_or(false, |s| s == "true") } + + /// Get the deprecated message if the template is deprecated + fn deprecated_message(&self) -> &str { + self.get_str("DeprecatedMessage").unwrap_or_default() + } } /// A trait for defining overarching types of specific template variants. @@ -79,7 +84,6 @@ pub trait Type: Clone + Default + EnumMessage + Eq + PartialEq + Va /// Get the list of templates of the type. fn templates(&self) -> Vec<&T> { - #[allow(deprecated)] T::VARIANTS .iter() .filter(|t| t.get_str(T::PROPERTY) == Some(self.name()) && !t.is_deprecated()) @@ -91,12 +95,6 @@ pub trait Type: Clone + Default + EnumMessage + Eq + PartialEq + Va // Match explicitly on type name (message) template.get_str(T::PROPERTY) == Some(self.name()) } - - /// Get if the type is deprecated. Currently, this function always returns `false` as there are - /// no deprecated variants. - fn is_deprecated(&self) -> bool { - false - } } #[macro_export] @@ -105,15 +103,21 @@ macro_rules! enum_variants { PossibleValuesParser::new( <$e>::VARIANTS .iter() - .filter_map(|p| { - if !p.is_deprecated() { - Some(PossibleValue::new(p.as_ref())) - } else { - None - } - }) + .map(|p| PossibleValue::new(p.as_ref())) .collect::>(), ) .try_map(|s| <$e>::from_str(&s).map_err(|e| format!("could not convert from {s} to type"))) }}; } + +#[macro_export] +macro_rules! enum_variants_for_help { + ($e:ty) => {{ + <$e>::VARIANTS + .iter() + .filter(|variant| !variant.is_deprecated()) // Exclude deprecated variants for --help + .map(|v| v.as_ref()) + .collect::>() + .join(", ") + }}; +} diff --git a/crates/pop-parachains/src/templates.rs b/crates/pop-parachains/src/templates.rs index c8959f76..11f41b57 100644 --- a/crates/pop-parachains/src/templates.rs +++ b/crates/pop-parachains/src/templates.rs @@ -149,34 +149,35 @@ pub enum Parachain { ) )] ParityGeneric, - /// [Deprecated] This command is deprecated, please use 'paritytech/substrate-contracts-node' - /// instead. + /// Minimal Substrate node configured for smart contracts via pallet-contracts. #[strum( - serialize = "cpt", + serialize = "paritytech/substrate-contracts-node", message = "Contracts", detailed_message = "Minimal Substrate node configured for smart contracts via pallet-contracts.", props( Provider = "Parity", Repository = "https://github.com/paritytech/substrate-contracts-node", Network = "./zombienet.toml", - License = "Unlicense", - IsDeprecated = "true" + License = "Unlicense" ) )] - ParityCPT, - /// Minimal Substrate node configured for smart contracts via pallet-contracts. + ParityContracts, + /// [Deprecated] This command is deprecated, please use 'paritytech/substrate-contracts-node' + /// instead. #[strum( - serialize = "paritytech/substrate-contracts-node", + serialize = "cpt", message = "Contracts", detailed_message = "Minimal Substrate node configured for smart contracts via pallet-contracts.", props( Provider = "Parity", Repository = "https://github.com/paritytech/substrate-contracts-node", Network = "./zombienet.toml", - License = "Unlicense" + License = "Unlicense", + IsDeprecated = "true", + DeprecatedMessage = "This template is deprecated. Please use paritytech/substrate-contracts-node in the future.", ) )] - ParityContracts, + DeprecatedParityContracts, // templates for unit tests below #[cfg(test)] #[strum( @@ -190,6 +191,7 @@ pub enum Parachain { SupportedVersions = "v1.0.0,v2.0.0", IsAudited = "true", IsDeprecated = "true", + DeprecatedMessage = "This template is deprecated. Please use test_02 in the future.", License = "Unlicense", ) )] @@ -250,7 +252,7 @@ mod tests { ("polkadot-generic-runtime-template".to_string(), OpenZeppelinGeneric), ("paritytech/polkadot-sdk-parachain-template".to_string(), ParityGeneric), ("paritytech/substrate-contracts-node".to_string(), ParityContracts), - ("cpt".to_string(), ParityCPT), + ("cpt".to_string(), DeprecatedParityContracts), ("test_01".to_string(), TestTemplate01), ("test_02".to_string(), TestTemplate02), ]) @@ -290,7 +292,7 @@ mod tests { (OpenZeppelinGeneric, Some("./zombienet-config/devnet.toml")), (ParityGeneric, Some("./zombienet.toml")), (ParityContracts, Some("./zombienet.toml")), - (ParityCPT, Some("./zombienet.toml")), + (DeprecatedParityContracts, Some("./zombienet.toml")), (TestTemplate01, Some("")), (TestTemplate02, Some("")), ] @@ -306,7 +308,7 @@ mod tests { (OpenZeppelinGeneric, Some("GPL-3.0")), (ParityGeneric, Some("Unlicense")), (ParityContracts, Some("Unlicense")), - (ParityCPT, Some("Unlicense")), + (DeprecatedParityContracts, Some("Unlicense")), (TestTemplate01, Some("Unlicense")), (TestTemplate02, Some("GPL-3.0")), ] @@ -433,4 +435,16 @@ mod tests { let template = TestTemplate02; assert_eq!(template.is_deprecated(), false); } + + #[test] + fn test_deprecated_message() { + let template = TestTemplate01; + assert_eq!( + template.deprecated_message(), + "This template is deprecated. Please use test_02 in the future." + ); + + let template = TestTemplate02; + assert_eq!(template.deprecated_message(), ""); + } } From 7fbb66bb712e20055066e6b1b92ec6765d1a0a31 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Wed, 18 Sep 2024 18:37:54 +0200 Subject: [PATCH 16/18] docs: improve comments --- crates/pop-cli/src/commands/new/parachain.rs | 2 +- crates/pop-common/src/templates/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/pop-cli/src/commands/new/parachain.rs b/crates/pop-cli/src/commands/new/parachain.rs index ee83a4c4..7fab2672 100644 --- a/crates/pop-cli/src/commands/new/parachain.rs +++ b/crates/pop-cli/src/commands/new/parachain.rs @@ -42,7 +42,7 @@ pub struct NewParachainCommand { long, help = format!("Template to use. [possible values: {}]", enum_variants_for_help!(Parachain)), value_parser = enum_variants!(Parachain), - hide_possible_values = true // To hide the deprecated templates + hide_possible_values = true // Hide the deprecated templates )] pub(crate) template: Option, #[arg( diff --git a/crates/pop-common/src/templates/mod.rs b/crates/pop-common/src/templates/mod.rs index 737746a5..0ccbf45d 100644 --- a/crates/pop-common/src/templates/mod.rs +++ b/crates/pop-common/src/templates/mod.rs @@ -46,12 +46,12 @@ pub trait Template: self.get_str(Self::PROPERTY).ok_or(Error::TypeMissing) } - /// Get if the template is deprecated + /// Get whether the template is deprecated. fn is_deprecated(&self) -> bool { self.get_str("IsDeprecated").map_or(false, |s| s == "true") } - /// Get the deprecated message if the template is deprecated + /// Get the deprecation message for the template fn deprecated_message(&self) -> &str { self.get_str("DeprecatedMessage").unwrap_or_default() } From abfca6470f456f150144980ebc8b48aa4404ba95 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Sun, 22 Sep 2024 08:58:58 +0200 Subject: [PATCH 17/18] refactor: nitpicks in parachain description --- crates/pop-cli/src/commands/new/parachain.rs | 14 +++----------- crates/pop-parachains/src/templates.rs | 2 +- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/crates/pop-cli/src/commands/new/parachain.rs b/crates/pop-cli/src/commands/new/parachain.rs index 7fab2672..b000d936 100644 --- a/crates/pop-cli/src/commands/new/parachain.rs +++ b/crates/pop-cli/src/commands/new/parachain.rs @@ -256,15 +256,7 @@ fn display_select_options(provider: &Provider) -> Result<&Parachain> { if i == 0 { prompt = prompt.initial_value(template); } - prompt = prompt.item( - template, - template.name(), - format!( - "{} {}", - template.description(), - if matches!(template, Parachain::ParityContracts) { "[deprecated]" } else { "" } - ), - ); + prompt = prompt.item(template, template.name(), template.description().trim()); } Ok(prompt.interact()?) } @@ -275,8 +267,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-parachains/src/templates.rs b/crates/pop-parachains/src/templates.rs index 11f41b57..be258366 100644 --- a/crates/pop-parachains/src/templates.rs +++ b/crates/pop-parachains/src/templates.rs @@ -153,7 +153,7 @@ pub enum Parachain { #[strum( serialize = "paritytech/substrate-contracts-node", message = "Contracts", - detailed_message = "Minimal Substrate node configured for smart contracts via pallet-contracts.", + detailed_message = "Minimal Substrate node configured for smart contracts via pallet-contracts. [deprecated]. Suggested to use Pop > Contracts template instead.", props( Provider = "Parity", Repository = "https://github.com/paritytech/substrate-contracts-node", From 34ff183453425d7ed9ecd48eafa6b98cd6dc2995 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Sun, 22 Sep 2024 09:26:39 +0200 Subject: [PATCH 18/18] fix: logic for substrate-contracts-node without path in config file --- crates/pop-cli/src/commands/new/parachain.rs | 4 +-- crates/pop-parachains/src/up/mod.rs | 27 +++++++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/crates/pop-cli/src/commands/new/parachain.rs b/crates/pop-cli/src/commands/new/parachain.rs index b000d936..b565e3e8 100644 --- a/crates/pop-cli/src/commands/new/parachain.rs +++ b/crates/pop-cli/src/commands/new/parachain.rs @@ -267,8 +267,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-parachains/src/up/mod.rs b/crates/pop-parachains/src/up/mod.rs index 8626b411..1406280c 100644 --- a/crates/pop-parachains/src/up/mod.rs +++ b/crates/pop-parachains/src/up/mod.rs @@ -212,8 +212,8 @@ impl Zombienet { // Check if command references a parachain template binary without a specified path // (e.g. Polkadot SDK parachain template) - if command == "parachain-template-node" { - let binary_path = PathBuf::from("./target/release").join("parachain-template-node"); + if command == "parachain-template-node" || command == "substrate-contracts-node" { + let binary_path = PathBuf::from("./target/release").join(&command); if !binary_path.exists() { return Err(Error::MissingBinary(command)); } @@ -1144,6 +1144,13 @@ id = 1000 [parachains.collator] name = "collator" command = "parachain-template-node" + +[[parachains]] +id = 2000 + +[parachains.collator] +name = "collator" +command = "substrate-contracts-node" "# )?; assert!(matches!( @@ -1151,10 +1158,13 @@ command = "parachain-template-node" Err(Error::MissingBinary(command)) if command == "parachain-template-node" )); - // Create the binary in the hardcoded path + // Create the binaries in the hardcoded path let parachain_template = PathBuf::from("target/release/parachain-template-node"); create_dir_all(parachain_template.parent().unwrap())?; File::create(¶chain_template)?; + let parachain_contracts_template = + PathBuf::from("target/release/substrate-contracts-node"); + File::create(¶chain_contracts_template)?; let zombienet = Zombienet::new( &cache, @@ -1168,14 +1178,23 @@ command = "parachain-template-node" .await?; // Remove the binary hardcoded path remove_file(¶chain_template)?; + remove_file(¶chain_contracts_template)?; remove_dir(parachain_template.parent().unwrap())?; - assert_eq!(zombienet.parachains.len(), 1); + assert_eq!(zombienet.parachains.len(), 2); let parachain = &zombienet.parachains.get(&1000).unwrap().binary; assert_eq!(parachain.name(), "parachain-template-node"); assert_eq!(parachain.path(), Path::new("./target/release/parachain-template-node")); assert_eq!(parachain.version(), None); assert!(matches!(parachain, Binary::Local { .. })); + let contract_parachain = &zombienet.parachains.get(&2000).unwrap().binary; + assert_eq!(contract_parachain.name(), "substrate-contracts-node"); + assert_eq!( + contract_parachain.path(), + Path::new("./target/release/substrate-contracts-node") + ); + assert_eq!(contract_parachain.version(), None); + assert!(matches!(contract_parachain, Binary::Local { .. })); Ok(()) }