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: update parachain templates #297

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
12610ef
feat: include new parachain template and remove old one for Parity
AlexD10S Aug 28, 2024
31ac60d
fix: tests
AlexD10S Aug 29, 2024
fec60a8
fix: order in test
AlexD10S Aug 29, 2024
392bdd9
fix: export PATH
AlexD10S Sep 4, 2024
c085a66
chore: merge main
AlexD10S Sep 6, 2024
ba6b7e0
Merge branch 'main' into alex/parity-template
AlexD10S Sep 12, 2024
e5ab436
chore: bump zombienet-sdk version
AlexD10S Sep 12, 2024
5da07ef
fix: remove parity evm
AlexD10S Sep 12, 2024
6070af6
fix: missing changes
AlexD10S Sep 12, 2024
dbf1ee7
fix: parse collator and parachain-template-node without path for spawn
AlexD10S Sep 12, 2024
d83700d
chore: remove set PATH
AlexD10S Sep 12, 2024
316de33
refactor: functionality and test
AlexD10S Sep 12, 2024
9f2076b
refactor: prefix for external templates
AlexD10S Sep 17, 2024
7addd9b
fix: deprecate old command for generating parity contracts template
AlexD10S Sep 18, 2024
d40ec06
test: update configure_works test to test new functionality
AlexD10S Sep 18, 2024
7017d63
test: fix unit tests templates
AlexD10S Sep 18, 2024
9871fe2
fix: show deprecation message and fixes
AlexD10S Sep 18, 2024
2b549c4
chore: merge main
AlexD10S Sep 18, 2024
7fbb66b
docs: improve comments
AlexD10S Sep 18, 2024
abfca64
refactor: nitpicks in parachain description
AlexD10S Sep 22, 2024
34ff183
fix: logic for substrate-contracts-node without path in config file
AlexD10S Sep 22, 2024
1898075
chore: merge latest changes
AlexD10S Jan 14, 2025
a68dd5f
feat: support v3.0.0 of OpenZeppelin templates
AlexD10S Jan 16, 2025
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
31 changes: 21 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(),
AlexD10S marked this conversation as resolved.
Show resolved Hide resolved
];
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,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()?)
}
Expand Down Expand Up @@ -467,11 +478,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 @@ -45,6 +45,16 @@ pub trait Template:
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 @@ pub trait Type<T: Template>: Clone + Default + EnumMessage + Eq + PartialEq + Va
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 @@ -99,3 +109,15 @@ macro_rules! enum_variants {
.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::<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