Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new parachain template and remove outdated one from parity #297

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 13 additions & 10 deletions crates/pop-cli/src/commands/new/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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 // Hide the deprecated templates
)]
pub(crate) template: Option<Parachain>,
#[arg(
Expand Down Expand Up @@ -126,10 +127,9 @@ async fn guide_user_to_generate_parachain(verify: bool) -> Result<NewParachainCo
provider,
provider.name(),
format!(
"{} {} available option(s) {}",
"{} {} available option(s)",
provider.description(),
provider.templates().len(),
if provider.name() == "Parity" { "[deprecated]" } else { "" }
provider.templates().len()
),
);
}
Expand Down Expand Up @@ -216,7 +216,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(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep it pop build. Adding --release takes way too long for development, and could degrade the UX for parachain development. --release should be suggested when prepping the chain for onboarding.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this change because it's common in the Zombienet configuration file to reference /target/release/. See https://github.com/OpenZeppelin/polkadot-runtime-templates/blob/main/generic-template/zombienet-config/devnet.toml#L21 or https://github.com/r0gue-io/pop-cli/blob/main/tests/networks/template.toml#L16.
Without running pop build --release, the path needs to be manually updated in the Zombienet file for things to work correctly.

];
if let Some(network_config) = template.network_config() {
next_steps.push(format!(
Expand Down Expand Up @@ -244,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()))?;
}
Ok(())
}

Expand All @@ -253,7 +256,7 @@ 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(), template.description().trim());
}
Ok(prompt.interact()?)
}
Expand Down Expand Up @@ -467,11 +470,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]
Expand Down
24 changes: 23 additions & 1 deletion crates/pop-common/src/templates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
use strum::{EnumMessage, EnumProperty, VariantArray};
pub use thiserror::Error;

pub mod extractor;

Check warning on line 6 in crates/pop-common/src/templates/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a module

warning: missing documentation for a module --> crates/pop-common/src/templates/mod.rs:6:1 | 6 | pub mod extractor; | ^^^^^^^^^^^^^^^^^

#[derive(Error, Debug)]
pub enum Error {

Check warning on line 9 in crates/pop-common/src/templates/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for an enum

warning: missing documentation for an enum --> crates/pop-common/src/templates/mod.rs:9:1 | 9 | pub enum Error { | ^^^^^^^^^^^^^^
#[error("The `Repository` property is missing from the template variant")]
RepositoryMissing,

Check warning on line 11 in crates/pop-common/src/templates/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-common/src/templates/mod.rs:11:2 | 11 | RepositoryMissing, | ^^^^^^^^^^^^^^^^^

#[error("The `TypeMissing` property is missing from the template variant")]
TypeMissing,

Check warning on line 14 in crates/pop-common/src/templates/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-common/src/templates/mod.rs:14:2 | 14 | TypeMissing, | ^^^^^^^^^^^
}

/// A trait for templates. A template is a variant of a template type.
Expand All @@ -19,7 +19,7 @@
Clone + Default + EnumMessage + EnumProperty + Eq + PartialEq + VariantArray
{
// What is the template's type strum property identifier.
const PROPERTY: &'static str = "Type";

Check warning on line 22 in crates/pop-common/src/templates/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for an associated constant

warning: missing documentation for an associated constant --> crates/pop-common/src/templates/mod.rs:22:2 | 22 | const PROPERTY: &'static str = "Type"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

/// Get the template's name.
fn name(&self) -> &str {
Expand All @@ -45,6 +45,16 @@
fn template_type(&self) -> Result<&str, Error> {
self.get_str(Self::PROPERTY).ok_or(Error::TypeMissing)
}

/// Get whether the template is deprecated.
fn is_deprecated(&self) -> bool {
self.get_str("IsDeprecated").map_or(false, |s| s == "true")
}

/// Get the deprecation message for the template
fn deprecated_message(&self) -> &str {
self.get_str("DeprecatedMessage").unwrap_or_default()
}
}

/// A trait for defining overarching types of specific template variants.
Expand Down Expand Up @@ -76,7 +86,7 @@
fn templates(&self) -> Vec<&T> {
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()
}

Expand All @@ -88,7 +98,7 @@
}

#[macro_export]
macro_rules! enum_variants {

Check warning on line 101 in crates/pop-common/src/templates/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a macro

warning: missing documentation for a macro --> crates/pop-common/src/templates/mod.rs:101:1 | 101 | macro_rules! enum_variants { | ^^^^^^^^^^^^^^^^^^^^^^^^^^
($e: ty) => {{
PossibleValuesParser::new(
<$e>::VARIANTS
Expand All @@ -99,3 +109,15 @@
.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 {

Check warning on line 114 in crates/pop-common/src/templates/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a macro

warning: missing documentation for a macro --> crates/pop-common/src/templates/mod.rs:114:1 | 114 | 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::<Vec<_>>()
.join(", ")
}};
}
1 change: 0 additions & 1 deletion crates/pop-parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
Loading
Loading