From 7910de3b925dd5314f7765db03d4ae663d45ccdb Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Mon, 29 Apr 2024 12:21:17 +0400 Subject: [PATCH 1/4] fix none at --- core/src/commands/execute_block.rs | 22 +++++++++++++++- core/tests/execute_block.rs | 42 +++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/core/src/commands/execute_block.rs b/core/src/commands/execute_block.rs index 8f1883f2d40..ab547b1381c 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 let Some(_) = live_state.at { + 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..ebc27a09a1f 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,43 @@ 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); + + // The execute-block command is actually executing the next block. + 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 the expected block. + assert!(matched.is_ok()); + + // Assert that the block-execution exited succesfully + assert!(block_execution + .wait_with_output() + .await + .unwrap() + .status + .success()); + }) .await } From bb62ecf071c0fbfe06d60323e6da364bcb83a7df Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Mon, 29 Apr 2024 12:21:49 +0400 Subject: [PATCH 2/4] bump version --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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" From 3595669637a0ab376429637a33561a2ee9f5c6dc Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Mon, 29 Apr 2024 12:23:01 +0400 Subject: [PATCH 3/4] comments --- core/tests/execute_block.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/tests/execute_block.rs b/core/tests/execute_block.rs index ebc27a09a1f..c247321b7d2 100644 --- a/core/tests/execute_block.rs +++ b/core/tests/execute_block.rs @@ -105,14 +105,12 @@ async fn execute_block_works() { // Try to execute the block. let mut block_execution = execute_block(&ws_url); - - // The execute-block command is actually executing the next block. 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 the expected block. + // Assert that the block-execution process has executed a block. assert!(matched.is_ok()); // Assert that the block-execution exited succesfully From 0f37bde832231c6d4101b4377db721b0e15014f8 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Mon, 29 Apr 2024 18:16:17 +0400 Subject: [PATCH 4/4] clippy --- core/src/commands/execute_block.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/commands/execute_block.rs b/core/src/commands/execute_block.rs index ab547b1381c..1c918424b91 100644 --- a/core/src/commands/execute_block.rs +++ b/core/src/commands/execute_block.rs @@ -100,7 +100,7 @@ where let live_state = match command.state { State::Live(live_state) => { // If no --at is provided, get the latest block to replay - if let Some(_) = live_state.at { + if live_state.at.is_some() { live_state } else { let header =