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

backport: rpc-probe updates from #1061 #1084

Merged
merged 7 commits into from
Jan 19, 2022
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
3 changes: 3 additions & 0 deletions .changelog/unreleased/breaking-changes/1084-rpc-probe-gaia.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- `[tools/rpc-probe]` CLI updated to support probing Gaia nodes in addition
to kvstore-based Tendermint nodes to generate static fixtures for RPC tests
([#1084](https://github.com/informalsystems/tendermint-rs/pull/1084))
2 changes: 1 addition & 1 deletion tools/rpc-probe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ description = """
all-features = true

[dependencies]
async-tungstenite = { version = "0.12", features = [ "tokio-runtime" ] }
async-tungstenite = { version = "0.16", features = [ "tokio-runtime", "tokio-rustls-native-certs" ] }
futures = "0.3"
getrandom = "0.2"
log = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion tools/rpc-probe/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Client {
self.cmd_tx.send(cmd).map_err(|e| {
Error::Internal(format!(
"WebSocket driver channel receiving end closed unexpectedly: {}",
e.to_string()
e
))
})
}
Expand Down
146 changes: 146 additions & 0 deletions tools/rpc-probe/src/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
//! Common interactions that can be used by plans interacting with any ABCI
//! application.

use crate::plan::{PlannedInteraction, PlannedSubscription};
use crate::request::Request;
use crate::utils::{encode_kvpair, hex_string};
use serde_json::json;

pub fn abci_info() -> PlannedInteraction {
Request::new("abci_info", json!(null)).into()
}

pub fn abci_query(key: &str) -> PlannedInteraction {
Request::new(
"abci_query",
json!({
"data": hex_string(key),
}),
)
.into()
}

pub fn block(height: u64) -> PlannedInteraction {
Request::new(
"block",
json!({
"height": format!("{}", height),
}),
)
.into()
}

pub fn block_search(query: &str, page: u32, per_page: u32, order_by: &str) -> PlannedInteraction {
Request::new(
"block_search",
json!({
"query": query,
"page": format!("{}", page),
"per_page": format!("{}", per_page),
"order_by": order_by,
}),
)
.into()
}

pub fn block_results(height: u64) -> PlannedInteraction {
Request::new(
"block_results",
json!({
"height": format!("{}", height),
}),
)
.into()
}

pub fn blockchain(min_height: u64, max_height: u64) -> PlannedInteraction {
Request::new(
"blockchain",
json!({
"minHeight": format!("{}", min_height),
"maxHeight": format!("{}", max_height),
}),
)
.into()
}

pub fn broadcast_tx(method: &str, key: &str, value: &str) -> PlannedInteraction {
Request::new(
format!("broadcast_tx_{}", method).as_str(),
json!({
"tx": encode_kvpair(key, value),
}),
)
.into()
}

pub fn commit(height: u64) -> PlannedInteraction {
Request::new(
"commit",
json!({
"height": format!("{}", height),
}),
)
.into()
}

pub fn consensus_params(height: u64) -> PlannedInteraction {
Request::new(
"consensus_params",
json!({
"height": format!("{}", height),
}),
)
.into()
}

pub fn consensus_state() -> PlannedInteraction {
Request::new("consensus_state", json!(null)).into()
}

pub fn genesis() -> PlannedInteraction {
Request::new("genesis", json!(null)).into()
}

pub fn net_info() -> PlannedInteraction {
Request::new("net_info", json!(null)).into()
}

pub fn status() -> PlannedInteraction {
Request::new("status", json!(null)).into()
}

pub fn subscribe(query: &str) -> PlannedInteraction {
PlannedSubscription::new(query).into()
}

pub fn tx(hash: &str, prove: bool) -> PlannedInteraction {
Request::new(
"tx",
json!({
"hash": hash,
"prove": prove,
}),
)
.into()
}

pub fn tx_search(
query: &str,
prove: bool,
page: u32,
per_page: u8,
order_by: &str,
) -> PlannedInteraction {
Request::new(
"tx_search",
json!({
"query": query,
"prove": prove,
"page": format!("{}", page),
"per_page": format!("{}", per_page),
"order_by": order_by,
}),
)
.into()
}
35 changes: 35 additions & 0 deletions tools/rpc-probe/src/gaia.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! Plans for interacting with Tendermint nodes running
//! [Gaia](https://github.com/cosmos/gaia).

use std::path::Path;
use tokio::time::Duration;

use crate::common::*;
use crate::plan::in_series;
use crate::{error::Result, plan::Plan};

/// A simple plan that just queries a Gaia node, without attempting to make any
/// modifications (i.e. without attempting to submit transactions).
pub fn query_plan(output_path: &Path, request_wait: Duration) -> Result<Plan> {
Plan::new(
output_path,
request_wait,
vec![in_series(vec![
abci_info(),
block(0).with_name("block_at_height_0").expect_error(),
block(1).with_name("block_at_height_1"),
block(10)
.with_min_height(10)
.with_name("block_at_height_10"),
block_results(10).with_name("block_results_at_height_10"),
blockchain(1, 10).with_name("blockchain_from_1_to_10"),
commit(10).with_name("commit_at_height_10"),
consensus_params(10),
consensus_state(),
genesis(),
net_info(),
status(),
subscribe("tm.event = 'NewBlock'").with_name("subscribe_newblock"),
])],
)
}
Loading