Skip to content

Commit

Permalink
fix /abci_info & /genesis:
Browse files Browse the repository at this point in the history
 - add app_version & use #[serde(default)] to deal with omitted fields in JSON
 - make app_state in /genesis reply optional
 - fix string in abci_info test (kvstore wont reply with "GaiaApp")

 verify tests pass via running `tendermint node --proxy_app=kvstore` and
 `cargo test -- --nocapture --ignored
  • Loading branch information
liamsi committed Dec 12, 2019
1 parent 7b26481 commit 87e888b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tendermint/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ pub struct Genesis<AppState = serde_json::Value> {
pub app_hash: Hash,

/// App state
pub app_state: AppState,
pub app_state: Option<AppState>,
}
16 changes: 13 additions & 3 deletions tendermint/src/rpc/endpoint/abci_info.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! `/abci_info` endpoint JSONRPC wrapper

use crate::{block, hash, rpc, Hash};
use crate::{block, rpc, Hash};
use crate::{hash, serializers};
use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer};

use subtle_encoding::base64;

/// Request ABCI information from a node
Expand All @@ -26,16 +28,24 @@ pub struct Response {
impl rpc::Response for Response {}

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

/// Version
pub version: Option<String>,

/// App version
#[serde(
serialize_with = "serializers::serialize_u64",
deserialize_with = "serializers::parse_u64"
)]
pub app_version: u64,

/// Last block height
pub last_block_height: block::Height,
pub last_block_height: Option<block::Height>,

/// Last app hash for the block
#[serde(
Expand Down
6 changes: 4 additions & 2 deletions tendermint/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ mod rpc {
#[ignore]
fn abci_info() {
let abci_info = block_on(localhost_rpc_client().abci_info()).unwrap();
assert_eq!(&abci_info.data, "GaiaApp");
assert_eq!(&abci_info.version.unwrap(), "0.16.1");
assert_eq!(abci_info.app_version, 1u64);
// the kvstore app's reply will contain "{\"size\":0}" as data right from the start
assert_eq!(abci_info.data.is_empty(), false);
}

/// `/abci_query` endpoint
Expand Down Expand Up @@ -83,7 +86,6 @@ mod rpc {

/// `/genesis` endpoint
#[test]
#[ignore]
fn genesis() {
let genesis = block_on(localhost_rpc_client().genesis()).unwrap();
assert_eq!(
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 87e888b

Please sign in to comment.