Skip to content

Commit

Permalink
fix(ics008): make sure we are encoding snake case
Browse files Browse the repository at this point in the history
Signed-off-by: aeryz <abdullaheryz@protonmail.com>
  • Loading branch information
aeryz committed Sep 4, 2023
1 parent 29709b2 commit 337a43e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
29 changes: 15 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/ics-008-wasm-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ prost = { version = "0.11", default-features = false }
protos = { workspace = true, default-features = false, features = ["proto_full", "std"] }
serde = { version = "1.0", default-features = false, features = ["derive"] }
unionlabs = { workspace = true, default-features = false }

[dev-dependencies]
serde_json = "1.0.0"
30 changes: 30 additions & 0 deletions lib/ics-008-wasm-client/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct MerklePath {
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub enum ClientMessage {
Header(Header),
Misbehaviour(Misbehaviour),
Expand Down Expand Up @@ -136,3 +137,32 @@ impl From<Status> for QueryResponse {
}
}
}

#[cfg(test)]
mod tests {
use protos::ibc::lightclients::wasm::v1::Header;

use crate::{ClientMessage, ExecuteMsg};

#[test]
fn execute_msg_snake_case_encoded() {
let msg = ExecuteMsg::CheckSubstituteAndUpdateState {};
assert_eq!(
serde_json::to_string(&msg).unwrap(),
r#"{"check_substitute_and_update_state":{}}"#
)
}

#[test]
fn client_msg_snake_case_encoded() {
let msg = ClientMessage::Header(Header {
data: vec![],
height: None,
});

assert_eq!(
serde_json::to_string(&msg).unwrap(),
r#"{"header":{"data":"","height":null}}"#
)
}
}

0 comments on commit 337a43e

Please sign in to comment.