11#[ cfg( test) ]
22mod tests {
3- use atoms_rpc_types:: Block ;
3+ use atoms_rpc_types:: { Block , SyncInfo } ;
4+ use base_primitives:: U256 ;
45 use cli_error:: CliError ;
56 use modules:: { Module , XcbModule } ;
67 use rpc:: MockRpcClient ;
@@ -23,6 +24,11 @@ mod tests {
2324 XcbModule :: new ( client)
2425 }
2526
27+ fn get_module_with_rpc_client ( client : MockRpcClient ) -> XcbModule {
28+ let client = Arc :: new ( Mutex :: new ( client) ) ;
29+ XcbModule :: new ( client)
30+ }
31+
2632 #[ tokio:: test]
2733 async fn test_execute_get_block_height ( ) {
2834 let mut module = get_module ( ) ;
@@ -139,4 +145,49 @@ mod tests {
139145 Err ( CliError :: InvalidNumberOfArguments ( _) )
140146 ) ) ;
141147 }
148+
149+ #[ tokio:: test]
150+ async fn test_syncing ( ) {
151+ let mut module = get_module ( ) ;
152+ let response = module. execute ( "syncing" . to_string ( ) , vec ! [ ] ) . await . unwrap ( ) ;
153+ assert_eq ! (
154+ response,
155+ Response :: SyncStatus ( atoms_rpc_types:: SyncStatus :: None )
156+ ) ;
157+
158+ assert_eq ! (
159+ response. format( types:: ResponseView :: Human ) ,
160+ "RPC node is synced and data is up to date"
161+ ) ;
162+ }
163+
164+ #[ tokio:: test]
165+ async fn test_syncing_active ( ) {
166+ let mut module = get_module_with_rpc_client ( MockRpcClient :: new ( ) . with_syncing (
167+ atoms_rpc_types:: SyncStatus :: Info ( SyncInfo {
168+ starting_block : U256 :: from ( 0 ) ,
169+ current_block : U256 :: from ( 100 ) ,
170+ highest_block : U256 :: from ( 1000 ) ,
171+ warp_chunks_amount : None ,
172+ warp_chunks_processed : None ,
173+ } ) ,
174+ ) ) ;
175+
176+ let response = module. execute ( "syncing" . to_string ( ) , vec ! [ ] ) . await . unwrap ( ) ;
177+ assert_eq ! (
178+ response,
179+ Response :: SyncStatus ( atoms_rpc_types:: SyncStatus :: Info ( SyncInfo {
180+ starting_block: U256 :: from( 0 ) ,
181+ current_block: U256 :: from( 100 ) ,
182+ highest_block: U256 :: from( 1000 ) ,
183+ warp_chunks_amount: None ,
184+ warp_chunks_processed: None ,
185+ } ) )
186+ ) ;
187+
188+ assert_eq ! (
189+ response. format( types:: ResponseView :: Human ) ,
190+ "RPC node is syncing now. Current block: 100, highest block: 1000, starting block: 0"
191+ ) ;
192+ }
142193}
0 commit comments