Skip to content

Commit

Permalink
tools: Fix block_search endpoint integration tests (#999)
Browse files Browse the repository at this point in the history
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 <connect@thanethomson.com>
  • Loading branch information
thanethomson authored Sep 30, 2021
1 parent 34c5d2a commit 4f1c553
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:
runs-on: ubuntu-latest
services:
tendermint:
image: informaldev/tendermint:0.34.0
image: informaldev/tendermint:0.34.13
ports:
- 26656:26656
- 26657:26657
Expand Down
2 changes: 1 addition & 1 deletion tools/kvstore-test/Makefile.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[env]
CONTAINER_NAME = "kvstore-test"
DOCKER_IMAGE = "informaldev/tendermint:0.34.0"
DOCKER_IMAGE = "informaldev/tendermint:0.34.13"
HOST_RPC_PORT = 26657
CARGO_MAKE_WAIT_MILLISECONDS = 1000
RUST_LOG = "debug"
Expand Down
37 changes: 20 additions & 17 deletions tools/kvstore-test/tests/tendermint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,14 @@ mod rpc {
assert!(block_results.txs_results.is_none());
}

/// `/block_search` endpoint
#[tokio::test]
async fn block_search() {
let res = localhost_http_client()
.block_search(
Query::gt("block.height", "1"),
1,
1,
Order::Ascending,
)
.block_search(Query::gt("block.height", 1), 1, 1, Order::Ascending)
.await
.unwrap();
assert!(res.total_count > 0);
assert_eq!(res.total_count as usize, res.blocks.len());
}

/// `/blockchain` endpoint
Expand Down Expand Up @@ -264,15 +260,21 @@ mod rpc {
}

async fn transaction_by_hash() {
let rpc_client = localhost_http_client();
let (mut subs_client, driver) = localhost_websocket_client().await;
let driver_handle = tokio::spawn(async move { driver.run().await });

let tx = Transaction::from(String::from("txtest=value").into_bytes());
let r = localhost_http_client()
.broadcast_tx_commit(tx.clone())
let (hash, _) = broadcast_tx(&rpc_client, &mut subs_client, tx.clone())
.await
.unwrap();
let hash = r.hash;
tokio::time::sleep(Duration::from_secs(1)).await;
let r = localhost_http_client().tx(hash, false).await.unwrap();
assert_eq!(r.hash, hash);
assert_eq!(r.tx, tx);

subs_client.close().unwrap();
let _ = driver_handle.await.unwrap();
}

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

let tx = "tx_search_key=tx_search_value".to_string();
let tx_info = broadcast_tx(
let (_, tx_info) = broadcast_tx(
&rpc_client,
&mut subs_client,
Transaction::from(tx.into_bytes()),
Expand All @@ -418,9 +420,8 @@ mod rpc {
.unwrap();
println!("Got tx_info: {:?}", tx_info);

// TODO(thane): Find a better way of accomplishing this. This might
// still be nondeterministic.
tokio::time::sleep(Duration::from_millis(500)).await;
// Give the indexer time to catch up
tokio::time::sleep(Duration::from_secs(1)).await;

let res = rpc_client
.tx_search(
Expand Down Expand Up @@ -455,6 +456,8 @@ mod rpc {
let r = client.broadcast_tx_commit(tx).await.unwrap();
let hash = r.hash;

tokio::time::sleep(Duration::from_secs(1)).await;

let r = client
.tx_search(
Query::from(EventType::Tx).and_eq("tx.hash", hash.to_string()),
Expand All @@ -472,9 +475,9 @@ mod rpc {
http_client: &HttpClient,
websocket_client: &mut WebSocketClient,
tx: Transaction,
) -> Result<TxInfo, tendermint_rpc::Error> {
) -> Result<(tendermint::abci::transaction::Hash, TxInfo), tendermint_rpc::Error> {
let mut subs = websocket_client.subscribe(EventType::Tx.into()).await?;
let _ = http_client.broadcast_tx_async(tx.clone()).await?;
let r = http_client.broadcast_tx_async(tx.clone()).await?;

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

0 comments on commit 4f1c553

Please sign in to comment.