diff --git a/Cargo.lock b/Cargo.lock index b6fcf7da8cd..e9e659a9963 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1096,6 +1096,15 @@ dependencies = [ "rand 0.7.3", ] +[[package]] +name = "cumulus-cli" +version = "0.1.0" +dependencies = [ + "sc-cli", + "sc-service", + "structopt", +] + [[package]] name = "cumulus-client-collator" version = "0.1.0" @@ -7027,6 +7036,7 @@ name = "rococo-collator" version = "0.1.0" dependencies = [ "assert_cmd", + "cumulus-cli", "cumulus-client-collator", "cumulus-client-consensus-relay-chain", "cumulus-client-network", @@ -7083,6 +7093,7 @@ dependencies = [ "substrate-build-script-utils", "substrate-test-client", "substrate-test-runtime-client", + "tempfile", "tokio 0.2.24", "trie-root 0.15.2", ] diff --git a/Cargo.toml b/Cargo.toml index f6ee7c08e77..a4bf9efe7c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,6 @@ [workspace] members = [ + "cli", "client/consensus/common", "client/consensus/relay-chain", "client/network", diff --git a/cli/Cargo.toml b/cli/Cargo.toml new file mode 100644 index 00000000000..0761275d93d --- /dev/null +++ b/cli/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "cumulus-cli" +version = "0.1.0" +authors = ["Parity Technologies "] +edition = "2018" + +[dependencies] +structopt = "0.3.3" + +# Substrate dependencies +sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } +sc-service = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/cli/src/lib.rs b/cli/src/lib.rs new file mode 100644 index 00000000000..c8711273b1d --- /dev/null +++ b/cli/src/lib.rs @@ -0,0 +1,114 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +//! Cumulus CLI library. + +#![warn(missing_docs)] + +use sc_cli; +use std::{ + fs, + io::{self, Write}, +}; +use structopt::StructOpt; + +/// The `purge-chain` command used to remove the whole chain: the parachain and the relaychain. +#[derive(Debug, StructOpt)] +pub struct PurgeChainCmd { + /// The base struct of the purge-chain command. + #[structopt(flatten)] + pub base: sc_cli::PurgeChainCmd, + + /// Only delete the para chain database + #[structopt(long, aliases = &["para"])] + pub parachain: bool, + + /// Only delete the relay chain database + #[structopt(long, aliases = &["relay"])] + pub relaychain: bool, +} + +impl PurgeChainCmd { + /// Run the purge command + pub fn run( + &self, + para_config: sc_service::Configuration, + relay_config: sc_service::Configuration, + ) -> sc_cli::Result<()> { + let databases = match (self.parachain, self.relaychain) { + (true, true) | (false, false) => vec![ + ("parachain", para_config.database), + ("relaychain", relay_config.database), + ], + (true, false) => vec![("parachain", para_config.database)], + (false, true) => vec![("relaychain", relay_config.database)], + }; + + let db_paths = databases + .iter() + .map(|(chain_label, database)| { + database.path().ok_or_else(|| sc_cli::Error::Input(format!( + "Cannot purge custom database implementation of: {}", + chain_label, + ))) + }) + .collect::>>()?; + + if !self.base.yes { + for db_path in &db_paths { + println!("{}", db_path.display()); + } + print!("Are you sure to remove? [y/N]: "); + io::stdout().flush().expect("failed to flush stdout"); + + let mut input = String::new(); + io::stdin().read_line(&mut input)?; + let input = input.trim(); + + match input.chars().nth(0) { + Some('y') | Some('Y') => {} + _ => { + println!("Aborted"); + return Ok(()); + } + } + } + + for db_path in &db_paths { + match fs::remove_dir_all(&db_path) { + Ok(_) => { + println!("{:?} removed.", &db_path); + } + Err(ref err) if err.kind() == io::ErrorKind::NotFound => { + eprintln!("{:?} did not exist.", &db_path); + } + Err(err) => return Err(err.into()), + } + } + + Ok(()) + } +} + +impl sc_cli::CliConfiguration for PurgeChainCmd { + fn shared_params(&self) -> &sc_cli::SharedParams { + &self.base.shared_params + } + + fn database_params(&self) -> Option<&sc_cli::DatabaseParams> { + Some(&self.base.database_params) + } +} diff --git a/client/collator/src/lib.rs b/client/collator/src/lib.rs index ef3a9d0f45b..d59a35e2a04 100644 --- a/client/collator/src/lib.rs +++ b/client/collator/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Substrate is free software: you can redistribute it and/or modify diff --git a/client/consensus/common/src/lib.rs b/client/consensus/common/src/lib.rs index b8ee16af6ce..9c810d60423 100644 --- a/client/consensus/common/src/lib.rs +++ b/client/consensus/common/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify diff --git a/client/consensus/relay-chain/src/import_queue.rs b/client/consensus/relay-chain/src/import_queue.rs index c35397bba4e..0054079e39c 100644 --- a/client/consensus/relay-chain/src/import_queue.rs +++ b/client/consensus/relay-chain/src/import_queue.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify diff --git a/client/network/src/lib.rs b/client/network/src/lib.rs index 5c52f2c4b14..5a05452d048 100644 --- a/client/network/src/lib.rs +++ b/client/network/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Polkadot. // Polkadot is free software: you can redistribute it and/or modify diff --git a/client/network/src/tests.rs b/client/network/src/tests.rs index 4e8c14812d4..8114eede1d0 100644 --- a/client/network/src/tests.rs +++ b/client/network/src/tests.rs @@ -1,4 +1,4 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. +// Copyright 2020-2021 Parity Technologies (UK) Ltd. // This file is part of Polkadot. // Polkadot is free software: you can redistribute it and/or modify diff --git a/client/network/src/wait_on_relay_chain_block.rs b/client/network/src/wait_on_relay_chain_block.rs index 73251fa0a38..5a0c72cbc32 100644 --- a/client/network/src/wait_on_relay_chain_block.rs +++ b/client/network/src/wait_on_relay_chain_block.rs @@ -1,4 +1,4 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. +// Copyright 2020-2021 Parity Technologies (UK) Ltd. // This file is part of Polkadot. // Polkadot is free software: you can redistribute it and/or modify diff --git a/client/service/src/genesis.rs b/client/service/src/genesis.rs index 0efc0c85c10..12f3b4e3bd1 100644 --- a/client/service/src/genesis.rs +++ b/client/service/src/genesis.rs @@ -1,4 +1,4 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. +// Copyright 2020-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index a930438863e..4298b5eff6b 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. +// Copyright 2020-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Substrate is free software: you can redistribute it and/or modify diff --git a/pallets/parachain-system/src/validate_block/implementation.rs b/pallets/parachain-system/src/validate_block/implementation.rs index 7ea408dfd09..def5e1d343b 100644 --- a/pallets/parachain-system/src/validate_block/implementation.rs +++ b/pallets/parachain-system/src/validate_block/implementation.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Substrate. // Substrate is free software: you can redistribute it and/or modify diff --git a/pallets/parachain-system/src/validate_block/mod.rs b/pallets/parachain-system/src/validate_block/mod.rs index 1cb26d6da7e..1b47b1eace5 100644 --- a/pallets/parachain-system/src/validate_block/mod.rs +++ b/pallets/parachain-system/src/validate_block/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Substrate. // Substrate is free software: you can redistribute it and/or modify diff --git a/pallets/parachain-system/src/validate_block/tests.rs b/pallets/parachain-system/src/validate_block/tests.rs index fe7b67a3b30..f5fb723c744 100644 --- a/pallets/parachain-system/src/validate_block/tests.rs +++ b/pallets/parachain-system/src/validate_block/tests.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Substrate. // Substrate is free software: you can redistribute it and/or modify diff --git a/pallets/xcm-handler/src/lib.rs b/pallets/xcm-handler/src/lib.rs index 23efc97ec0d..fade40a2942 100644 --- a/pallets/xcm-handler/src/lib.rs +++ b/pallets/xcm-handler/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. +// Copyright 2020-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Substrate is free software: you can redistribute it and/or modify diff --git a/primitives/core/src/lib.rs b/primitives/core/src/lib.rs index 12183704a6e..7751fdcec42 100644 --- a/primitives/core/src/lib.rs +++ b/primitives/core/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. +// Copyright 2020-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Substrate is free software: you can redistribute it and/or modify diff --git a/rococo-parachains/Cargo.toml b/rococo-parachains/Cargo.toml index 023429820f2..a7ab051f68a 100644 --- a/rococo-parachains/Cargo.toml +++ b/rococo-parachains/Cargo.toml @@ -56,6 +56,7 @@ sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "maste jsonrpc-core = "15.1.0" # Cumulus dependencies +cumulus-cli = { path = "../cli" } cumulus-client-consensus-relay-chain = { path = "../client/consensus/relay-chain" } cumulus-client-collator = { path = "../client/collator" } cumulus-client-service = { path = "../client/service" } @@ -76,6 +77,7 @@ substrate-build-script-utils = { git = "https://github.com/paritytech/substrate" assert_cmd = "0.12" nix = "0.17" rand = "0.7.3" +tempfile = "3.2.0" tokio = { version = "0.2.13", features = ["macros"] } # Polkadot dependencies diff --git a/rococo-parachains/build.rs b/rococo-parachains/build.rs index c3462ee3913..ae164d6cb0f 100644 --- a/rococo-parachains/build.rs +++ b/rococo-parachains/build.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Substrate is free software: you can redistribute it and/or modify diff --git a/rococo-parachains/contracts-runtime/src/lib.rs b/rococo-parachains/contracts-runtime/src/lib.rs index 59a07551e39..432163e293d 100644 --- a/rococo-parachains/contracts-runtime/src/lib.rs +++ b/rococo-parachains/contracts-runtime/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify diff --git a/rococo-parachains/pallets/parachain-info/src/lib.rs b/rococo-parachains/pallets/parachain-info/src/lib.rs index 0a1422fdb68..4a189dee671 100644 --- a/rococo-parachains/pallets/parachain-info/src/lib.rs +++ b/rococo-parachains/pallets/parachain-info/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. +// Copyright 2020-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify diff --git a/rococo-parachains/primitives/src/lib.rs b/rococo-parachains/primitives/src/lib.rs index 4c93d3f3bba..7219b1588ed 100644 --- a/rococo-parachains/primitives/src/lib.rs +++ b/rococo-parachains/primitives/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. +// Copyright 2020-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Substrate is free software: you can redistribute it and/or modify diff --git a/rococo-parachains/runtime/build.rs b/rococo-parachains/runtime/build.rs index 4ffbb1f64a6..fe1a2ea911d 100644 --- a/rococo-parachains/runtime/build.rs +++ b/rococo-parachains/runtime/build.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Substrate is free software: you can redistribute it and/or modify diff --git a/rococo-parachains/runtime/src/lib.rs b/rococo-parachains/runtime/src/lib.rs index a3d0d861ca8..3c1741a6210 100644 --- a/rococo-parachains/runtime/src/lib.rs +++ b/rococo-parachains/runtime/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify diff --git a/rococo-parachains/src/chain_spec.rs b/rococo-parachains/src/chain_spec.rs index 3bcb201696b..c34932d8e41 100644 --- a/rococo-parachains/src/chain_spec.rs +++ b/rococo-parachains/src/chain_spec.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify diff --git a/rococo-parachains/src/cli.rs b/rococo-parachains/src/cli.rs index 8ad2a32ec34..d1aace17d79 100644 --- a/rococo-parachains/src/cli.rs +++ b/rococo-parachains/src/cli.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use std::path::PathBuf; - +use crate::chain_spec; use sc_cli; +use std::path::PathBuf; use structopt::StructOpt; /// Sub-commands supported by the collator. @@ -46,7 +46,7 @@ pub enum Subcommand { ImportBlocks(sc_cli::ImportBlocksCmd), /// Remove the whole chain. - PurgeChain(sc_cli::PurgeChainCmd), + PurgeChain(cumulus_cli::PurgeChainCmd), /// Revert the chain to a previous state. Revert(sc_cli::RevertCmd), @@ -143,12 +143,17 @@ pub struct RelayChainCli { } impl RelayChainCli { - /// Create a new instance of `Self`. + /// Parse the relay chain CLI parameters using the para chain `Configuration`. pub fn new<'a>( - base_path: Option, - chain_id: Option, + para_config: &sc_service::Configuration, relay_chain_args: impl Iterator, ) -> Self { + let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec); + let chain_id = extension.map(|e| e.relay_chain.clone()); + let base_path = para_config + .base_path + .as_ref() + .map(|x| x.path().join("polkadot")); Self { base_path, chain_id, diff --git a/rococo-parachains/src/command.rs b/rococo-parachains/src/command.rs index 1d2578cb9cb..a0069af5923 100644 --- a/rococo-parachains/src/command.rs +++ b/rococo-parachains/src/command.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify @@ -203,7 +203,25 @@ pub fn run() -> Result<()> { } Some(Subcommand::PurgeChain(cmd)) => { let runner = cli.create_runner(cmd)?; - runner.sync_run(|config| cmd.run(config.database)) + + runner.sync_run(|config| { + let polkadot_cli = RelayChainCli::new( + &config, + [RelayChainCli::executable_name().to_string()] + .iter() + .chain(cli.relaychain_args.iter()), + ); + + let polkadot_config = SubstrateCli::create_configuration( + &polkadot_cli, + &polkadot_cli, + config.task_executor.clone(), + None, + ) + .map_err(|err| format!("Relay chain argument error: {}", err))?; + + cmd.run(config, polkadot_config) + }) } Some(Subcommand::Revert(cmd)) => { let runner = cli.create_runner(cmd)?; @@ -269,13 +287,11 @@ pub fn run() -> Result<()> { // TODO let key = sp_core::Pair::generate().0; - let extension = chain_spec::Extensions::try_get(&*config.chain_spec); - let relay_chain_id = extension.map(|e| e.relay_chain.clone()); - let para_id = extension.map(|e| e.para_id); + let para_id = + chain_spec::Extensions::try_get(&*config.chain_spec).map(|e| e.para_id); let polkadot_cli = RelayChainCli::new( - config.base_path.as_ref().map(|x| x.path().join("polkadot")), - relay_chain_id, + &config, [RelayChainCli::executable_name().to_string()] .iter() .chain(cli.relaychain_args.iter()), diff --git a/rococo-parachains/src/main.rs b/rococo-parachains/src/main.rs index be7e27dcd37..7d02fd46489 100644 --- a/rococo-parachains/src/main.rs +++ b/rococo-parachains/src/main.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify diff --git a/rococo-parachains/src/service.rs b/rococo-parachains/src/service.rs index 95358b48f06..cfea2549564 100644 --- a/rococo-parachains/src/service.rs +++ b/rococo-parachains/src/service.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify diff --git a/rococo-parachains/tests/common.rs b/rococo-parachains/tests/common.rs index 37fcaea688a..72f3881b7bc 100644 --- a/rococo-parachains/tests/common.rs +++ b/rococo-parachains/tests/common.rs @@ -1,4 +1,4 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. +// Copyright 2020-2021 Parity Technologies (UK) Ltd. // This file is part of Substrate. // Substrate is free software: you can redistribute it and/or modify diff --git a/rococo-parachains/tests/polkadot_argument_parsing.rs b/rococo-parachains/tests/polkadot_argument_parsing.rs index d71321b409c..717edda0bf8 100644 --- a/rococo-parachains/tests/polkadot_argument_parsing.rs +++ b/rococo-parachains/tests/polkadot_argument_parsing.rs @@ -1,4 +1,4 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. +// Copyright 2020-2021 Parity Technologies (UK) Ltd. // This file is part of Substrate. // Substrate is free software: you can redistribute it and/or modify diff --git a/rococo-parachains/tests/polkadot_mdns_issue.rs b/rococo-parachains/tests/polkadot_mdns_issue.rs index c3a1ad5d05a..e0c2f9bf382 100644 --- a/rococo-parachains/tests/polkadot_mdns_issue.rs +++ b/rococo-parachains/tests/polkadot_mdns_issue.rs @@ -1,4 +1,4 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. +// Copyright 2020-2021 Parity Technologies (UK) Ltd. // This file is part of Substrate. // Substrate is free software: you can redistribute it and/or modify diff --git a/rococo-parachains/tests/purge_chain_works.rs b/rococo-parachains/tests/purge_chain_works.rs index 16c07e20e7e..2d994fb3403 100644 --- a/rococo-parachains/tests/purge_chain_works.rs +++ b/rococo-parachains/tests/purge_chain_works.rs @@ -1,4 +1,4 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. +// Copyright 2020-2021 Parity Technologies (UK) Ltd. // This file is part of Substrate. // Substrate is free software: you can redistribute it and/or modify @@ -15,50 +15,63 @@ // along with Substrate. If not, see . use assert_cmd::cargo::cargo_bin; -use std::{convert::TryInto, fs, path::PathBuf, process::Command, thread, time::Duration}; +use std::{convert::TryInto, process::Command, thread, time::Duration}; mod common; #[test] #[cfg(unix)] fn purge_chain_works() { - use nix::{ - sys::signal::{kill, Signal::SIGINT}, - unistd::Pid, - }; + fn run_node_and_stop() -> tempfile::TempDir { + use nix::{ + sys::signal::{kill, Signal::SIGINT}, + unistd::Pid, + }; - let base_path = "purge_chain_test"; + let base_path = tempfile::tempdir().unwrap(); - let _ = fs::remove_dir_all(base_path); - let mut cmd = Command::new(cargo_bin("rococo-collator")) - .args(&["-d", base_path, "--", "--dev"]) - .spawn() - .unwrap(); + let mut cmd = Command::new(cargo_bin("rococo-collator")) + .args(&["-d"]) + .arg(base_path.path()) + .args(&["--"]) + .spawn() + .unwrap(); - // Let it produce some blocks. - thread::sleep(Duration::from_secs(30)); - assert!( - cmd.try_wait().unwrap().is_none(), - "the process should still be running" - ); + // Let it produce some blocks. + thread::sleep(Duration::from_secs(30)); + assert!( + cmd.try_wait().unwrap().is_none(), + "the process should still be running" + ); - // Stop the process - kill(Pid::from_raw(cmd.id().try_into().unwrap()), SIGINT).unwrap(); - assert!(common::wait_for(&mut cmd, 30) - .map(|x| x.success()) - .unwrap_or_default()); + // Stop the process + kill(Pid::from_raw(cmd.id().try_into().unwrap()), SIGINT).unwrap(); + assert!(common::wait_for(&mut cmd, 30) + .map(|x| x.success()) + .unwrap_or_default()); - let status = Command::new(cargo_bin("rococo-collator")) - .args(&["purge-chain", "-d", base_path, "-y"]) - .status() - .unwrap(); - assert!(status.success()); + base_path + } - // Make sure that the `parachain_local_testnet` chain folder exists, but the `db` is deleted. - assert!(PathBuf::from(base_path) - .join("chains/local_testnet/") - .exists()); - assert!(!PathBuf::from(base_path) - .join("chains/local_testnet/db") - .exists()); + // Check that both databases are deleted + { + let base_path = run_node_and_stop(); + + assert!(base_path.path().join("chains/local_testnet/db").exists()); + assert!(base_path.path().join("polkadot/chains/westend_dev/db").exists()); + + let status = Command::new(cargo_bin("rococo-collator")) + .args(&["purge-chain", "-d"]) + .arg(base_path.path()) + .arg("-y") + .status() + .unwrap(); + assert!(status.success()); + + // Make sure that the `parachain_local_testnet` chain folder exists, but the `db` is deleted. + assert!(base_path.path().join("chains/local_testnet").exists()); + assert!(!base_path.path().join("chains/local_testnet/db").exists()); + assert!(base_path.path().join("polkadot/chains/westend_dev").exists()); + assert!(!base_path.path().join("polkadot/chains/westend_dev/db").exists()); + } } diff --git a/rococo-parachains/tests/running_the_node_and_interrupt.rs b/rococo-parachains/tests/running_the_node_and_interrupt.rs index 935d5fbada4..83f37ebcf48 100644 --- a/rococo-parachains/tests/running_the_node_and_interrupt.rs +++ b/rococo-parachains/tests/running_the_node_and_interrupt.rs @@ -1,4 +1,4 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. +// Copyright 2020-2021 Parity Technologies (UK) Ltd. // This file is part of Substrate. // Substrate is free software: you can redistribute it and/or modify diff --git a/test/client/src/block_builder.rs b/test/client/src/block_builder.rs index 2e494ae5f6a..b1905da8f32 100644 --- a/test/client/src/block_builder.rs +++ b/test/client/src/block_builder.rs @@ -1,4 +1,4 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. +// Copyright 2020-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify diff --git a/test/client/src/lib.rs b/test/client/src/lib.rs index 6d529f0f478..24d06c7497d 100644 --- a/test/client/src/lib.rs +++ b/test/client/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Substrate. // Substrate is free software: you can redistribute it and/or modify diff --git a/test/runtime/build.rs b/test/runtime/build.rs index 4ffbb1f64a6..fe1a2ea911d 100644 --- a/test/runtime/build.rs +++ b/test/runtime/build.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Substrate is free software: you can redistribute it and/or modify diff --git a/test/runtime/src/lib.rs b/test/runtime/src/lib.rs index 650af418e43..28f58e3dd03 100644 --- a/test/runtime/src/lib.rs +++ b/test/runtime/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify diff --git a/test/service/src/chain_spec.rs b/test/service/src/chain_spec.rs index 6e48821b509..bd3a0350510 100644 --- a/test/service/src/chain_spec.rs +++ b/test/service/src/chain_spec.rs @@ -1,4 +1,4 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. +// Copyright 2020-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify diff --git a/test/service/src/genesis.rs b/test/service/src/genesis.rs index 34f3457c9f7..c30dcffe36f 100644 --- a/test/service/src/genesis.rs +++ b/test/service/src/genesis.rs @@ -1,4 +1,4 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. +// Copyright 2020-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify diff --git a/test/service/src/lib.rs b/test/service/src/lib.rs index b653c60bfa5..00aa807a8cb 100644 --- a/test/service/src/lib.rs +++ b/test/service/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify diff --git a/test/service/tests/integration.rs b/test/service/tests/integration.rs index cdbef977652..2742cd2c68c 100644 --- a/test/service/tests/integration.rs +++ b/test/service/tests/integration.rs @@ -1,4 +1,4 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. +// Copyright 2020-2021 Parity Technologies (UK) Ltd. // This file is part of Substrate. // Substrate is free software: you can redistribute it and/or modify