Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: Fix block_search endpoint integration tests #999

Merged
merged 3 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important to note here that the block_search endpoint was only introduced in Tendermint v0.34.9.

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"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this needs to be maintained separately and coordinated with the .github/workflows/test.yml config because this cargo make makefile allows you to run the same tests locally.

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)
Copy link
Contributor Author

@thanethomson thanethomson Sep 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original string representation was breaking CI. Changing it to a numerical value fixed it.

.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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests kept failing locally so I had to tweak them here too.

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