@@ -138,18 +138,14 @@ mod rpc {
138
138
assert ! ( block_results. txs_results. is_none( ) ) ;
139
139
}
140
140
141
+ /// `/block_search` endpoint
142
+ #[ tokio:: test]
141
143
async fn block_search ( ) {
142
144
let res = localhost_http_client ( )
143
- . block_search (
144
- Query :: gt ( "block.height" , "1" ) ,
145
- 1 ,
146
- 1 ,
147
- Order :: Ascending ,
148
- )
145
+ . block_search ( Query :: gt ( "block.height" , 1 ) , 1 , 1 , Order :: Ascending )
149
146
. await
150
147
. unwrap ( ) ;
151
148
assert ! ( res. total_count > 0 ) ;
152
- assert_eq ! ( res. total_count as usize , res. blocks. len( ) ) ;
153
149
}
154
150
155
151
/// `/blockchain` endpoint
@@ -264,15 +260,21 @@ mod rpc {
264
260
}
265
261
266
262
async fn transaction_by_hash ( ) {
263
+ let rpc_client = localhost_http_client ( ) ;
264
+ let ( mut subs_client, driver) = localhost_websocket_client ( ) . await ;
265
+ let driver_handle = tokio:: spawn ( async move { driver. run ( ) . await } ) ;
266
+
267
267
let tx = Transaction :: from ( String :: from ( "txtest=value" ) . into_bytes ( ) ) ;
268
- let r = localhost_http_client ( )
269
- . broadcast_tx_commit ( tx. clone ( ) )
268
+ let ( hash, _) = broadcast_tx ( & rpc_client, & mut subs_client, tx. clone ( ) )
270
269
. await
271
270
. unwrap ( ) ;
272
- let hash = r . hash ;
271
+ tokio :: time :: sleep ( Duration :: from_secs ( 1 ) ) . await ;
273
272
let r = localhost_http_client ( ) . tx ( hash, false ) . await . unwrap ( ) ;
274
273
assert_eq ! ( r. hash, hash) ;
275
274
assert_eq ! ( r. tx, tx) ;
275
+
276
+ subs_client. close ( ) . unwrap ( ) ;
277
+ let _ = driver_handle. await . unwrap ( ) ;
276
278
}
277
279
278
280
async fn simple_transaction_subscription ( ) {
@@ -409,7 +411,7 @@ mod rpc {
409
411
let driver_handle = tokio:: spawn ( async move { driver. run ( ) . await } ) ;
410
412
411
413
let tx = "tx_search_key=tx_search_value" . to_string ( ) ;
412
- let tx_info = broadcast_tx (
414
+ let ( _ , tx_info) = broadcast_tx (
413
415
& rpc_client,
414
416
& mut subs_client,
415
417
Transaction :: from ( tx. into_bytes ( ) ) ,
@@ -418,9 +420,8 @@ mod rpc {
418
420
. unwrap ( ) ;
419
421
println ! ( "Got tx_info: {:?}" , tx_info) ;
420
422
421
- // TODO(thane): Find a better way of accomplishing this. This might
422
- // still be nondeterministic.
423
- tokio:: time:: sleep ( Duration :: from_millis ( 500 ) ) . await ;
423
+ // Give the indexer time to catch up
424
+ tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
424
425
425
426
let res = rpc_client
426
427
. tx_search (
@@ -455,6 +456,8 @@ mod rpc {
455
456
let r = client. broadcast_tx_commit ( tx) . await . unwrap ( ) ;
456
457
let hash = r. hash ;
457
458
459
+ tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
460
+
458
461
let r = client
459
462
. tx_search (
460
463
Query :: from ( EventType :: Tx ) . and_eq ( "tx.hash" , hash. to_string ( ) ) ,
@@ -472,9 +475,9 @@ mod rpc {
472
475
http_client : & HttpClient ,
473
476
websocket_client : & mut WebSocketClient ,
474
477
tx : Transaction ,
475
- ) -> Result < TxInfo , tendermint_rpc:: Error > {
478
+ ) -> Result < ( tendermint :: abci :: transaction :: Hash , TxInfo ) , tendermint_rpc:: Error > {
476
479
let mut subs = websocket_client. subscribe ( EventType :: Tx . into ( ) ) . await ?;
477
- let _ = http_client. broadcast_tx_async ( tx. clone ( ) ) . await ?;
480
+ let r = http_client. broadcast_tx_async ( tx. clone ( ) ) . await ?;
478
481
479
482
let timeout = tokio:: time:: sleep ( Duration :: from_secs ( 3 ) ) ;
480
483
tokio:: pin!( timeout) ;
@@ -487,7 +490,7 @@ mod rpc {
487
490
let tx_result_bytes: & [ u8 ] = tx_result. tx. as_ref( ) ;
488
491
// Make sure we have the right transaction here
489
492
assert_eq!( tx. as_bytes( ) , tx_result_bytes) ;
490
- Ok ( tx_result)
493
+ Ok ( ( r . hash , tx_result) )
491
494
} ,
492
495
_ => panic!( "Unexpected event: {:?}" , ev) ,
493
496
}
0 commit comments