From 8566c87fdaf0d92ce4b4b09c3ad6023071419d53 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Wed, 12 Apr 2023 11:16:35 +0400 Subject: [PATCH 1/6] fix fast_forward when used with substrate binary --- bin/node/cli/src/command.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/node/cli/src/command.rs b/bin/node/cli/src/command.rs index b38b25d8fb3ad..a19a4d119a0d5 100644 --- a/bin/node/cli/src/command.rs +++ b/bin/node/cli/src/command.rs @@ -32,6 +32,9 @@ use sp_keyring::Sr25519Keyring; use std::sync::Arc; +#[cfg(feature = "try-runtime")] +use try_runtime_cli::block_building_info::timestamp_with_aura_info; + #[cfg(feature = "try-runtime")] use { kitchensink_runtime::constants::time::SLOT_DURATION, @@ -242,7 +245,7 @@ pub fn run() -> Result<()> { sc_service::TaskManager::new(config.tokio_handle.clone(), registry) .map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?; - let info_provider = substrate_info(SLOT_DURATION); + let info_provider = timestamp_with_aura_info(6000); Ok(( cmd.run:: Date: Wed, 12 Apr 2023 11:17:09 +0400 Subject: [PATCH 2/6] test that fast forward runs and logs expected output --- .../try-runtime/cli/tests/fast_forward.rs | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 utils/frame/try-runtime/cli/tests/fast_forward.rs diff --git a/utils/frame/try-runtime/cli/tests/fast_forward.rs b/utils/frame/try-runtime/cli/tests/fast_forward.rs new file mode 100644 index 0000000000000..eb07345a49011 --- /dev/null +++ b/utils/frame/try-runtime/cli/tests/fast_forward.rs @@ -0,0 +1,74 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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 this program. If not, see . + +#![cfg(unix)] + +#[cfg(feature = "try-runtime")] +mod tests { + use assert_cmd::cargo::cargo_bin; + use regex::Regex; + use std::{ + process::{self}, + str::from_utf8, + time::Duration, + }; + use substrate_cli_test_utils as common; + use tokio::process::Command; + + #[tokio::test] + async fn follow_chain_works() { + // Build substrate so binaries used in the test use the latest code. + common::build_substrate(&["--features=try-runtime"]); + + let n_blocks = 10; + common::run_with_timeout(Duration::from_secs(60), async move { + let run_fast_forward = |ws_url: String| async move { + Command::new(cargo_bin("substrate")) + .stdout(process::Stdio::piped()) + .stderr(process::Stdio::piped()) + .args(&["try-runtime", "--runtime=existing"]) + .args(&[ + "fast-forward", + format!("--n-blocks={}", n_blocks).as_str(), + "live", + format!("--uri={}", ws_url).as_str(), + ]) + .kill_on_drop(true) + .output() + .await + .unwrap() + }; + + // Start a node and wait for it to begin finalizing blocks + let mut node = common::KillChildOnDrop(common::start_node()); + let ws_url = common::extract_info_from_output(node.stderr.take().unwrap()).0.ws_url; + common::wait_n_finalized_blocks(1, &ws_url).await; + + // Make sure fast_forward logged "Executed the new block" the expected number of times + // and exited successfully + let fast_forward = run_fast_forward(ws_url).await; + let re = Regex::new( + format!(r#"(?:(?s).*Executed the new block.*\s*){}"#, n_blocks).as_str(), + ) + .unwrap(); + assert!(re.is_match(from_utf8(&fast_forward.stderr).unwrap())); + assert!(fast_forward.status.success()); + }) + .await; + } +} From ea4c92b256c11541ce1f28b32f7ad9be071def96 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Wed, 12 Apr 2023 11:17:32 +0400 Subject: [PATCH 3/6] update start_node to use node-template --- test-utils/cli/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-utils/cli/src/lib.rs b/test-utils/cli/src/lib.rs index 1846f19090b33..a77add6a2f7b4 100644 --- a/test-utils/cli/src/lib.rs +++ b/test-utils/cli/src/lib.rs @@ -61,10 +61,10 @@ use tokio::io::{AsyncBufReadExt, AsyncRead}; /// /// [`Child`]: std::process::Child pub fn start_node() -> Child { - Command::new(cargo_bin("substrate")) + Command::new(cargo_bin("node-template")) .stdout(process::Stdio::piped()) .stderr(process::Stdio::piped()) - .args(&["--dev", "--tmp", "--ws-port=45789", "--no-hardware-benchmarks"]) + .args(&["--dev", "--ws-port=45789"]) .spawn() .unwrap() } From 1166f9bacaab5419a4a68f9127bfa2e6fe9162d5 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Wed, 12 Apr 2023 22:58:54 +1000 Subject: [PATCH 4/6] Update utils/frame/try-runtime/cli/tests/fast_forward.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- utils/frame/try-runtime/cli/tests/fast_forward.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/frame/try-runtime/cli/tests/fast_forward.rs b/utils/frame/try-runtime/cli/tests/fast_forward.rs index eb07345a49011..a897a590fbec8 100644 --- a/utils/frame/try-runtime/cli/tests/fast_forward.rs +++ b/utils/frame/try-runtime/cli/tests/fast_forward.rs @@ -23,7 +23,7 @@ mod tests { use assert_cmd::cargo::cargo_bin; use regex::Regex; use std::{ - process::{self}, + process, str::from_utf8, time::Duration, }; From baced250e7d83afbd87dba8259b1827d4dd73d1d Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Wed, 12 Apr 2023 22:59:01 +1000 Subject: [PATCH 5/6] Update utils/frame/try-runtime/cli/tests/fast_forward.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- utils/frame/try-runtime/cli/tests/fast_forward.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/frame/try-runtime/cli/tests/fast_forward.rs b/utils/frame/try-runtime/cli/tests/fast_forward.rs index a897a590fbec8..920bb2b1e5ad2 100644 --- a/utils/frame/try-runtime/cli/tests/fast_forward.rs +++ b/utils/frame/try-runtime/cli/tests/fast_forward.rs @@ -36,7 +36,7 @@ mod tests { common::build_substrate(&["--features=try-runtime"]); let n_blocks = 10; - common::run_with_timeout(Duration::from_secs(60), async move { + common::run_with_timeout(Duration::from_secs(10 * 60), async move { let run_fast_forward = |ws_url: String| async move { Command::new(cargo_bin("substrate")) .stdout(process::Stdio::piped()) From 730e1e6b4e43dd23afb4364889c59086a547956a Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Wed, 12 Apr 2023 16:59:53 +0400 Subject: [PATCH 6/6] increase follow_chain test timeout --- utils/frame/try-runtime/cli/tests/follow_chain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/frame/try-runtime/cli/tests/follow_chain.rs b/utils/frame/try-runtime/cli/tests/follow_chain.rs index a4961aa280171..040ef312ab238 100644 --- a/utils/frame/try-runtime/cli/tests/follow_chain.rs +++ b/utils/frame/try-runtime/cli/tests/follow_chain.rs @@ -34,7 +34,7 @@ mod tests { // Build substrate so binaries used in the test use the latest code. common::build_substrate(&["--features=try-runtime"]); - common::run_with_timeout(Duration::from_secs(60), async move { + common::run_with_timeout(Duration::from_secs(10 * 60), async move { fn start_follow(ws_url: &str) -> Child { Command::new(cargo_bin("substrate")) .stdout(process::Stdio::piped())