Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

fix try-runtime fast-forward when run from the substrate cli and add test #13888

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
5 changes: 4 additions & 1 deletion bin/node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

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

I personally always prefer using the full path where needed, or doing the import more locally, rather than feature gated imports, but up to you.


#[cfg(feature = "try-runtime")]
use {
kitchensink_runtime::constants::time::SLOT_DURATION,
Expand Down Expand Up @@ -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::<Block, ExtendedHostFunctions<
Expand Down
4 changes: 2 additions & 2 deletions test-utils/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Comment on lines -64 to 69
Copy link
Member

Choose a reason for hiding this comment

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

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to make things simpler.

--dev makes --tmp redundant, and node-template doesn't run any hardware benchmarks by default.

Let me know if I'm missing something though.

}
Expand Down
74 changes: 74 additions & 0 deletions utils/frame/try-runtime/cli/tests/fast_forward.rs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

#![cfg(unix)]

#[cfg(feature = "try-runtime")]
mod tests {
use assert_cmd::cargo::cargo_bin;
use regex::Regex;
use std::{
process::{self},
liamaharon marked this conversation as resolved.
Show resolved Hide resolved
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 {
liamaharon marked this conversation as resolved.
Show resolved Hide resolved
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;
}
}