Skip to content

Commit aab40f1

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

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎cli/tests/execute_block.rs‎

Lines changed: 17 additions & 3 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 expectd.
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 a 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.
127134
common::run_with_timeout(Duration::from_secs(120), async move {
128135
let ws_url = format!("ws://localhost:{}", port);
129136
let from = 3u64;
@@ -153,6 +160,13 @@ async fn execute_block_works() {
153160
// Assert that all blocks in the range were executed.
154161
assert!(matched.is_ok());
155162

163+
// Assert that the block after is not executed.
164+
let expected_output = format!(r#".*Block #{} successfully executed"#, to + 1);
165+
let re = Regex::new(expected_output.as_str()).unwrap();
166+
let matched =
167+
common::wait_for_stream_pattern_match(block_execution.stderr.take().unwrap(), re).await;
168+
assert!(matched.is_err());
169+
156170
// Assert that the block-execution exited successfully.
157171
assert!(block_execution
158172
.wait_with_output()

‎core/src/commands/execute_block.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ where
152152

153153
let _ =
154154
execute_block::<Block, HostFns>(&shared, &command, &executor, &rpc, live_state)
155-
.await;
155+
.await?;
156156
}
157157
}
158158

0 commit comments

Comments
 (0)