Skip to content

Commit

Permalink
test proto::Any json ser-der
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Apr 26, 2024
1 parent 81c7481 commit bad974c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
19 changes: 19 additions & 0 deletions ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,22 @@ impl From<MockConsensusState> for MockClientState {
Self::new(cs.header)
}
}

#[cfg(test)]
mod test {
use ibc::primitives::proto::Any;

use super::{MockClientState, MockHeader};

#[cfg(feature = "serde")]
#[test]
fn test_any_client_state_to_json() {
let client_state = MockClientState::new(MockHeader::default());
let expected = r#"{"typeUrl":"/ibc.mock.ClientState","value":"CgQKAhABEIDIr6Al"}"#;
let json = serde_json::to_string(&Any::from(client_state)).unwrap();
assert_eq!(json, expected);

let proto_any = serde_json::from_str::<Any>(expected).unwrap();
assert_eq!(proto_any, Any::from(client_state));
}
}
19 changes: 0 additions & 19 deletions ibc-testkit/src/testapp/ibc/clients/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,3 @@ impl TryFrom<AnyConsensusState> for MockConsensusState {
}
}
}

#[cfg(test)]
mod test {
use ibc::primitives::proto::Any;

use super::mock::header::MockHeader;
use crate::testapp::ibc::clients::mock::client_state::MockClientState;

#[test]
fn test_any_client_state_to_json() {
let client_state = MockClientState::new(MockHeader::default());
let expected = r#"{"typeUrl":"/ibc.mock.ClientState","value":"CgQKAhABEIDIr6Al"}"#;
let json = serde_json::to_string(&Any::from(client_state)).unwrap();
assert_eq!(json, expected);

let proto_any = serde_json::from_str::<Any>(expected).unwrap();
assert_eq!(proto_any, Any::from(client_state));
}
}

0 comments on commit bad974c

Please sign in to comment.