diff --git a/crates/configuration/src/network.rs b/crates/configuration/src/network.rs index 82cbd34888337b521cbf8a4012e5308e9f45385c..af3496eab492ab46269a734d893844c80d1c5b46 100644 --- a/crates/configuration/src/network.rs +++ b/crates/configuration/src/network.rs @@ -427,8 +427,6 @@ impl NetworkConfigBuilder<WithRelaychain> { #[cfg(test)] mod tests { - use std::fs; - use super::*; use crate::parachain::RegistrationStrategy; diff --git a/crates/examples/examples/add_para.rs b/crates/examples/examples/add_para.rs index ee2e2d38ad9d99f264f0671ed93136b90bbbebad..04b1b17390c9f35c4781ac45e9063ea9dbf59bc6 100644 --- a/crates/examples/examples/add_para.rs +++ b/crates/examples/examples/add_para.rs @@ -1,3 +1,5 @@ +use std::time::Duration; + use anyhow::anyhow; use futures::stream::StreamExt; use zombienet_sdk::{NetworkConfigBuilder, NetworkConfigExt}; @@ -12,6 +14,17 @@ async fn main() -> Result<(), anyhow::Error> { .with_node(|node| node.with_name("alice")) .with_node(|node| node.with_name("bob")) }) + .with_parachain(|p| { + p.with_id(2000) + .cumulus_based(true) + .with_collator(|n| + n.with_name("collator") + // TODO: check how we can clean + .with_command("polkadot-parachain") + // .with_command("test-parachain") + // .with_image("docker.io/paritypr/test-parachain:c90f9713b5bc73a9620b2e72b226b4d11e018190") + ) + }) .build() .unwrap() .spawn_native() @@ -20,6 +33,8 @@ async fn main() -> Result<(), anyhow::Error> { println!("🚀🚀🚀🚀 network deployed"); let alice = network.get_node("alice")?; + tokio::time::sleep(Duration::from_secs(10)).await; + println!("{:#?}", alice); let client = alice.client::<subxt::PolkadotConfig>().await?; // wait 3 blocks @@ -34,12 +49,15 @@ async fn main() -> Result<(), anyhow::Error> { let para_config = network .para_config_builder() .with_id(100) + //.with_registration_strategy(zombienet_sdk::RegistrationStrategy::Manual) .with_default_command("polkadot-parachain") .with_collator(|c| c.with_name("col-100-1")) .build() .map_err(|_e| anyhow!("Building config"))?; - network.add_parachain(¶_config, None).await?; + network + .add_parachain(¶_config, None, Some("new_para_100".to_string())) + .await?; // For now let just loop.... #[allow(clippy::empty_loop)] diff --git a/crates/orchestrator/src/network.rs b/crates/orchestrator/src/network.rs index e70c6a26b8ba8c31a2adf2e3b14aa10bdc58ae45..35b20be649c65977092700557682ca059b596b44 100644 --- a/crates/orchestrator/src/network.rs +++ b/crates/orchestrator/src/network.rs @@ -312,7 +312,11 @@ impl<T: FileSystem> Network<T> { /// Add a new parachain to the running network /// - /// NOTE: para_id must be unique in the whole network. + /// # Arguments + /// * `para_config` - Parachain configuration to deploy + /// * `custom_relaychain_spec` - Optional path to a custom relaychain spec to use + /// * `custom_parchain_fs_prefix` - Optional prefix to use when artifacts are created + /// /// /// # Example: /// ```rust @@ -334,7 +338,7 @@ impl<T: FileSystem> Network<T> { /// .build() /// .map_err(|_e| anyhow!("Building config"))?; /// - /// network.add_parachain(¶_config, None).await?; + /// network.add_parachain(¶_config, None, None).await?; /// /// # Ok(()) /// # } @@ -343,6 +347,7 @@ impl<T: FileSystem> Network<T> { &mut self, para_config: &ParachainConfig, custom_relaychain_spec: Option<PathBuf>, + custom_parchain_fs_prefix: Option<String>, ) -> Result<(), anyhow::Error> { // build let mut para_spec = network_spec::parachain::ParachainSpec::from_config(para_config)?; @@ -375,13 +380,21 @@ impl<T: FileSystem> Network<T> { let chain_spec_raw_path = para_spec .build_chain_spec(&relay_chain_id, &self.ns, &scoped_fs) .await?; - scoped_fs.create_dir(para_spec.id.to_string()).await?; + + // Para artifacts + let para_path_prefix = if let Some(custom_prefix) = custom_parchain_fs_prefix { + custom_prefix + } else { + para_spec.id.to_string() + }; + + scoped_fs.create_dir(¶_path_prefix).await?; // create wasm/state para_spec .genesis_state .build( chain_spec_raw_path.as_ref(), - format!("{}/genesis-state", para_spec.id), + format!("{}/genesis-state", ¶_path_prefix), &self.ns, &scoped_fs, ) @@ -390,7 +403,7 @@ impl<T: FileSystem> Network<T> { .genesis_wasm .build( chain_spec_raw_path.as_ref(), - format!("{}/para_spec-wasm", para_spec.id), + format!("{}/para_spec-wasm", ¶_path_prefix), &self.ns, &scoped_fs, ) diff --git a/crates/provider/src/kubernetes/namespace.rs b/crates/provider/src/kubernetes/namespace.rs index 998b003af932ccea468e4d338b3172fe7bac4167..fa952f162ece47bc145ce732d3735c6d9e3014c8 100644 --- a/crates/provider/src/kubernetes/namespace.rs +++ b/crates/provider/src/kubernetes/namespace.rs @@ -60,7 +60,7 @@ where filesystem: &FS, ) -> Result<Arc<Self>, ProviderError> { let name = format!("{}{}", NAMESPACE_PREFIX, Uuid::new_v4()); - let base_dir = PathBuf::from_iter([&tmp_dir, &PathBuf::from(&name)]); + let base_dir = PathBuf::from_iter([tmp_dir, &PathBuf::from(&name)]); filesystem.create_dir(&base_dir).await?; let namespace = Arc::new_cyclic(|weak| KubernetesNamespace { diff --git a/crates/provider/src/kubernetes/node.rs b/crates/provider/src/kubernetes/node.rs index 9577cc0bd43b3a80446400c430f13d821103a20b..03cf50a3e92496a0273f91dcf1f1df57200da453 100644 --- a/crates/provider/src/kubernetes/node.rs +++ b/crates/provider/src/kubernetes/node.rs @@ -73,7 +73,7 @@ where let filesystem = options.filesystem.clone(); let base_dir = - PathBuf::from_iter([&options.namespace_base_dir, &PathBuf::from(options.name)]); + PathBuf::from_iter([options.namespace_base_dir, &PathBuf::from(options.name)]); filesystem.create_dir_all(&base_dir).await?; let base_dir_raw = base_dir.to_string_lossy(); diff --git a/crates/provider/src/native/namespace.rs b/crates/provider/src/native/namespace.rs index ba31035dc2bbf478146b250052954052f972b4f3..7ba225fc58ceb0bf50dc92058d93c45574687fb7 100644 --- a/crates/provider/src/native/namespace.rs +++ b/crates/provider/src/native/namespace.rs @@ -45,7 +45,7 @@ where filesystem: &FS, ) -> Result<Arc<Self>, ProviderError> { let name = format!("{}{}", NAMESPACE_PREFIX, Uuid::new_v4()); - let base_dir = PathBuf::from_iter([&tmp_dir, &PathBuf::from(&name)]); + let base_dir = PathBuf::from_iter([tmp_dir, &PathBuf::from(&name)]); filesystem.create_dir(&base_dir).await?; Ok(Arc::new_cyclic(|weak| NativeNamespace { diff --git a/crates/provider/src/native/node.rs b/crates/provider/src/native/node.rs index e3866ac5becb5b21573dd32f8e3a07eccc50b800..84b4925a3c8ba005aba82d45c99de3479d4eb87e 100644 --- a/crates/provider/src/native/node.rs +++ b/crates/provider/src/native/node.rs @@ -71,7 +71,7 @@ where created_paths: &[PathBuf], filesystem: &FS, ) -> Result<Arc<Self>, ProviderError> { - let base_dir = PathBuf::from_iter([&namespace_base_dir, &PathBuf::from(name)]); + let base_dir = PathBuf::from_iter([namespace_base_dir, &PathBuf::from(name)]); trace!("creating base_dir {:?}", base_dir); filesystem.create_dir_all(&base_dir).await?; trace!("created base_dir {:?}", base_dir); diff --git a/crates/provider/src/shared/helpers.rs b/crates/provider/src/shared/helpers.rs index 1a998f5e1462b0ff03b569cf6d43ce090f776b0a..68983061aeef6d67f49aa85c68f5ee7099281178 100644 --- a/crates/provider/src/shared/helpers.rs +++ b/crates/provider/src/shared/helpers.rs @@ -30,8 +30,6 @@ pub fn running_in_ci() -> bool { #[cfg(test)] mod tests { - use std::collections::HashMap; - use super::*; #[test]