@@ -25,6 +25,13 @@ use regex::Regex;
2525use substrate_cli_test_utils as common;
2626use 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]
2936async 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}
0 commit comments