Skip to content

Commit 4f1c553

Browse files
authored
tools: Fix block_search endpoint integration tests (#999)
Closes #998 * Bump integration test tendermint to v0.34.13 * Fix kvstore integration tests * Bump tendermint version to v0.34.13 in CI Signed-off-by: Thane Thomson <[email protected]>
1 parent 34c5d2a commit 4f1c553

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ jobs:
125125
runs-on: ubuntu-latest
126126
services:
127127
tendermint:
128-
image: informaldev/tendermint:0.34.0
128+
image: informaldev/tendermint:0.34.13
129129
ports:
130130
- 26656:26656
131131
- 26657:26657

tools/kvstore-test/Makefile.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[env]
22
CONTAINER_NAME = "kvstore-test"
3-
DOCKER_IMAGE = "informaldev/tendermint:0.34.0"
3+
DOCKER_IMAGE = "informaldev/tendermint:0.34.13"
44
HOST_RPC_PORT = 26657
55
CARGO_MAKE_WAIT_MILLISECONDS = 1000
66
RUST_LOG = "debug"

tools/kvstore-test/tests/tendermint.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,14 @@ mod rpc {
138138
assert!(block_results.txs_results.is_none());
139139
}
140140

141+
/// `/block_search` endpoint
142+
#[tokio::test]
141143
async fn block_search() {
142144
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)
149146
.await
150147
.unwrap();
151148
assert!(res.total_count > 0);
152-
assert_eq!(res.total_count as usize, res.blocks.len());
153149
}
154150

155151
/// `/blockchain` endpoint
@@ -264,15 +260,21 @@ mod rpc {
264260
}
265261

266262
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+
267267
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())
270269
.await
271270
.unwrap();
272-
let hash = r.hash;
271+
tokio::time::sleep(Duration::from_secs(1)).await;
273272
let r = localhost_http_client().tx(hash, false).await.unwrap();
274273
assert_eq!(r.hash, hash);
275274
assert_eq!(r.tx, tx);
275+
276+
subs_client.close().unwrap();
277+
let _ = driver_handle.await.unwrap();
276278
}
277279

278280
async fn simple_transaction_subscription() {
@@ -409,7 +411,7 @@ mod rpc {
409411
let driver_handle = tokio::spawn(async move { driver.run().await });
410412

411413
let tx = "tx_search_key=tx_search_value".to_string();
412-
let tx_info = broadcast_tx(
414+
let (_, tx_info) = broadcast_tx(
413415
&rpc_client,
414416
&mut subs_client,
415417
Transaction::from(tx.into_bytes()),
@@ -418,9 +420,8 @@ mod rpc {
418420
.unwrap();
419421
println!("Got tx_info: {:?}", tx_info);
420422

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;
424425

425426
let res = rpc_client
426427
.tx_search(
@@ -455,6 +456,8 @@ mod rpc {
455456
let r = client.broadcast_tx_commit(tx).await.unwrap();
456457
let hash = r.hash;
457458

459+
tokio::time::sleep(Duration::from_secs(1)).await;
460+
458461
let r = client
459462
.tx_search(
460463
Query::from(EventType::Tx).and_eq("tx.hash", hash.to_string()),
@@ -472,9 +475,9 @@ mod rpc {
472475
http_client: &HttpClient,
473476
websocket_client: &mut WebSocketClient,
474477
tx: Transaction,
475-
) -> Result<TxInfo, tendermint_rpc::Error> {
478+
) -> Result<(tendermint::abci::transaction::Hash, TxInfo), tendermint_rpc::Error> {
476479
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?;
478481

479482
let timeout = tokio::time::sleep(Duration::from_secs(3));
480483
tokio::pin!(timeout);
@@ -487,7 +490,7 @@ mod rpc {
487490
let tx_result_bytes: &[u8] = tx_result.tx.as_ref();
488491
// Make sure we have the right transaction here
489492
assert_eq!(tx.as_bytes(), tx_result_bytes);
490-
Ok(tx_result)
493+
Ok((r.hash, tx_result))
491494
},
492495
_ => panic!("Unexpected event: {:?}", ev),
493496
}

0 commit comments

Comments
 (0)