Skip to content

Commit

Permalink
Enable integration tests + GitHub Actions Service for Tendermint node (
Browse files Browse the repository at this point in the history
…#183)

* Enable integration tests + GitHub Actions Service for Tendermint node

* Additional clarifying comments
  • Loading branch information
greg-szabo authored Mar 16, 2020
1 parent 00f4390 commit 50cd585
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 14 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,32 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: build
args: --all --all-targets
args: --workspace --all-targets
- uses: actions-rs/cargo@v1
with:
command: test
args: --all-features --no-fail-fast

test-integration-ignored:
runs-on: ubuntu-latest
services:
tendermint:
image: interchainio/tendermint
ports:
- 26656:26656
- 26657:26657
- 26660:26660
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test
args: -p tendermint --test integration --no-fail-fast -- --ignored

test-nightly-coverage:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Dependencies
- Update to bytes `0.5` and amino_rs `0.5`.
- Tokens for amino_rs are now fully non-conflicting with prost. Allowing both to be used together

- Made RPC type values optional for full compatibility with tendermint-go@v0.32: `abci_info`, `abci_query` [#120]

## [0.11.0] (2019-12-11)

Expand Down
2 changes: 1 addition & 1 deletion tendermint/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ pub struct Genesis<AppState = serde_json::Value> {
pub app_hash: Option<Hash>,

/// App state
pub app_state: AppState,
pub app_state: Option<AppState>,
}
37 changes: 28 additions & 9 deletions tendermint/src/rpc/endpoint/abci_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,60 @@ impl rpc::Response for Response {}

/// ABCI information
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(default)]
pub struct AbciInfo {
/// Name of the application
pub data: String,

/// Version
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,

/// Last block height
pub last_block_height: block::Height,
/// Last block height, omit empty
#[serde(skip_serializing_if = "Option::is_none")]
pub last_block_height: Option<block::Height>,

/// Last app hash for the block
/// Last app hash for the block, omit empty
#[serde(
serialize_with = "serialize_app_hash",
deserialize_with = "parse_app_hash"
deserialize_with = "parse_app_hash",
skip_serializing_if = "Option::is_none"
)]
pub last_block_app_hash: Hash,
pub last_block_app_hash: Option<Hash>,
}

/// Parse Base64-encoded app hash
pub(crate) fn parse_app_hash<'de, D>(deserializer: D) -> Result<Hash, D::Error>
pub(crate) fn parse_app_hash<'de, D>(deserializer: D) -> Result<Option<Hash>, D::Error>
where
D: Deserializer<'de>,
{
let bytes = base64::decode(String::deserialize(deserializer)?.as_bytes())
.map_err(|e| D::Error::custom(format!("{}", e)))?;

Hash::new(hash::Algorithm::Sha256, &bytes).map_err(|e| D::Error::custom(format!("{}", e)))
Hash::new(hash::Algorithm::Sha256, &bytes) // This never returns None
.map(Some) // Return Option<Hash> (syntactic sugar so the value can be omitted in the struct)
.map_err(|e| D::Error::custom(format!("{}", e))) // or return custom Error
}

/// Serialize Base64-encoded app hash
pub(crate) fn serialize_app_hash<S>(hash: &Hash, serializer: S) -> Result<S::Ok, S::Error>
pub(crate) fn serialize_app_hash<S>(hash: &Option<Hash>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
String::from_utf8(base64::encode(hash.as_bytes()))
String::from_utf8(base64::encode(hash.unwrap().as_bytes()))
.unwrap()
.serialize(serializer)
}

/// Default trait implements default values for the optional last_block_height and last_block_app_hash
/// for cases where they were omitted from the JSON.
impl Default for AbciInfo {
fn default() -> Self {
AbciInfo {
data: "".to_string(),
version: None,
last_block_height: None,
last_block_app_hash: None,
}
}
}
2 changes: 2 additions & 0 deletions tendermint/src/rpc/endpoint/abci_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Request {
/// Path to the data
#[serde(skip_serializing_if = "Option::is_none")]
path: Option<Path>,

/// Data to query
Expand All @@ -20,6 +21,7 @@ pub struct Request {
data: Vec<u8>,

/// Block height
#[serde(skip_serializing_if = "Option::is_none")]
height: Option<block::Height>,

/// Include proof in response
Expand Down
2 changes: 1 addition & 1 deletion tendermint/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mod rpc {
async fn abci_info() {
let abci_info = localhost_rpc_client().abci_info().await.unwrap();

assert_eq!(&abci_info.data, "GaiaApp");
assert_eq!(&abci_info.data, "{\"size\":0}");
}

/// `/abci_query` endpoint
Expand Down
2 changes: 1 addition & 1 deletion tendermint/tests/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod endpoints {
.response;

assert_eq!(response.data.as_str(), EXAMPLE_APP);
assert_eq!(response.last_block_height.value(), 488_120);
assert_eq!(response.last_block_height.unwrap().value(), 488_120);
}

#[test]
Expand Down

0 comments on commit 50cd585

Please sign in to comment.