Skip to content

Commit 86e8af1

Browse files
committed
add test comments and error propagation
1 parent f6c7b57 commit 86e8af1

2 files changed

Lines changed: 22 additions & 17 deletions

File tree

‎cli/tests/execute_block.rs‎

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ use regex::Regex;
2525
use substrate_cli_test_utils as common;
2626
use tokio::process::Command;
2727

28+
/*
29+
* Test that `execute-block` works as expected.
30+
* It covers three scenarios:
31+
* 1. Passing --at to execute a specific block.
32+
* 2. Not passing --at to execute the latest block.
33+
* 3. Passing --from and --to to execute an inclusive range of blocks.
34+
*/
2835
#[tokio::test]
2936
async fn execute_block_works() {
3037
let port = 45789;
@@ -45,7 +52,7 @@ async fn execute_block_works() {
4552
// Wait some time to ensure the node is warmed up.
4653
std::thread::sleep(Duration::from_secs(90));
4754

48-
// Test passing --at
55+
// 1. Test passing --at to execute a specific block.
4956
common::run_with_timeout(Duration::from_secs(60), async move {
5057
let ws_url = format!("ws://localhost:{}", port);
5158

@@ -87,7 +94,7 @@ async fn execute_block_works() {
8794
})
8895
.await;
8996

90-
// Test not passing --at
97+
// 2. Test not passing --at should execute the latest block.
9198
common::run_with_timeout(Duration::from_secs(60), async move {
9299
let ws_url = format!("ws://localhost:{}", port);
93100

@@ -123,7 +130,7 @@ async fn execute_block_works() {
123130
})
124131
.await;
125132

126-
// Test passing --from and --to to execute a range of blocks.
133+
// 3. Test passing --from and --to to execute a range of blocks (inclusive).
127134
common::run_with_timeout(Duration::from_secs(120), async move {
128135
let ws_url = format!("ws://localhost:{}", port);
129136
let from = 3u64;
@@ -142,24 +149,23 @@ async fn execute_block_works() {
142149
.unwrap()
143150
}
144151

145-
let mut block_execution = execute_block_range(&ws_url, from, to);
152+
let block_execution = execute_block_range(&ws_url, from, to);
153+
154+
let output = block_execution.wait_with_output().await.unwrap();
155+
let stderr = String::from_utf8_lossy(&output.stderr);
146156

147157
// Expect the last block in the range to be successfully executed.
148158
let expected_output = format!(r#".*Block #{} successfully executed"#, to);
149159
let re = Regex::new(expected_output.as_str()).unwrap();
150-
let matched =
151-
common::wait_for_stream_pattern_match(block_execution.stderr.take().unwrap(), re).await;
160+
assert!(re.is_match(&stderr));
152161

153-
// Assert that all blocks in the range were executed.
154-
assert!(matched.is_ok());
162+
// Assert that the block after is not executed.
163+
let expected_output = format!(r#".*Block #{} successfully executed"#, to + 1);
164+
let re = Regex::new(expected_output.as_str()).unwrap();
165+
assert!(!re.is_match(&stderr));
155166

156167
// Assert that the block-execution exited successfully.
157-
assert!(block_execution
158-
.wait_with_output()
159-
.await
160-
.unwrap()
161-
.status
162-
.success());
168+
assert!(output.status.success());
163169
})
164170
.await
165171
}

‎core/src/commands/execute_block.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,8 @@ where
150150
child_tree: Default::default(),
151151
};
152152

153-
let _ =
154-
execute_block::<Block, HostFns>(&shared, &command, &executor, &rpc, live_state)
155-
.await;
153+
execute_block::<Block, HostFns>(&shared, &command, &executor, &rpc, live_state)
154+
.await?;
156155
}
157156
}
158157

0 commit comments

Comments
 (0)