diff --git a/Cargo.lock b/Cargo.lock index 4e4531801c2..5909ca99f06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11080,7 +11080,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "try-runtime-cli" -version = "0.6.1" +version = "0.6.2" dependencies = [ "clap", "env_logger", @@ -11133,7 +11133,7 @@ dependencies = [ [[package]] name = "try-runtime-core" -version = "0.6.1" +version = "0.6.2" dependencies = [ "assert_cmd", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 0e3b622a2d0..0f5801da73c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ resolver = "2" members = ["cli", "core"] [workspace.package] -version = "0.6.1" +version = "0.6.2" authors = ["Parity Technologies "] description = "Substrate's programmatic testing framework." edition = "2021" diff --git a/core/src/commands/execute_block.rs b/core/src/commands/execute_block.rs index 8f1883f2d40..1c918424b91 100644 --- a/core/src/commands/execute_block.rs +++ b/core/src/commands/execute_block.rs @@ -98,7 +98,27 @@ where let rpc = ws_client(&block_ws_uri).await?; let live_state = match command.state { - State::Live(live_state) => live_state, + State::Live(live_state) => { + // If no --at is provided, get the latest block to replay + if live_state.at.is_some() { + live_state + } else { + let header = + ChainApi::<(), Block::Hash, Block::Header, SignedBlock>::header( + &rpc, None, + ) + .await + .map_err(rpc_err_handler)? + .expect("header exists, block should also exist; qed"); + LiveState { + uri: block_ws_uri, + at: Some(hex::encode(header.hash().encode())), + pallet: Default::default(), + hashed_prefixes: Default::default(), + child_tree: Default::default(), + } + } + } _ => { unreachable!("execute block currently only supports Live state") } diff --git a/core/tests/execute_block.rs b/core/tests/execute_block.rs index 93d9b85143d..c247321b7d2 100644 --- a/core/tests/execute_block.rs +++ b/core/tests/execute_block.rs @@ -28,7 +28,6 @@ use tokio::process::Command; #[tokio::test] async fn execute_block_works() { let port = 45789; - let ws_url = format!("ws://localhost:{}", port); // Spawn a dev node. let _ = std::thread::spawn(move || { @@ -46,7 +45,10 @@ async fn execute_block_works() { // Wait some time to ensure the node is warmed up. std::thread::sleep(Duration::from_secs(90)); + // Test passing --at common::run_with_timeout(Duration::from_secs(60), async move { + let ws_url = format!("ws://localhost:{}", port); + fn execute_block(ws_url: &str, at: Hash) -> tokio::process::Child { Command::new(cargo_bin("try-runtime")) .stdout(std::process::Stdio::piped()) @@ -83,5 +85,41 @@ async fn execute_block_works() { .status .success()); }) + .await; + + // Test not passing --at + common::run_with_timeout(Duration::from_secs(60), async move { + let ws_url = format!("ws://localhost:{}", port); + + fn execute_block(ws_url: &str) -> tokio::process::Child { + Command::new(cargo_bin("try-runtime")) + .stdout(std::process::Stdio::piped()) + .stderr(std::process::Stdio::piped()) + .arg("--runtime=existing") + .args(["execute-block"]) + .args(["live", format!("--uri={}", ws_url).as_str()]) + .kill_on_drop(true) + .spawn() + .unwrap() + } + + // Try to execute the block. + let mut block_execution = execute_block(&ws_url); + let expected_output = r".*Block #(\d+) successfully executed"; + let re = Regex::new(expected_output).unwrap(); + let matched = + common::wait_for_stream_pattern_match(block_execution.stderr.take().unwrap(), re).await; + + // Assert that the block-execution process has executed a block. + assert!(matched.is_ok()); + + // Assert that the block-execution exited succesfully + assert!(block_execution + .wait_with_output() + .await + .unwrap() + .status + .success()); + }) .await }