@@ -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 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]
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.
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( )
0 commit comments