From 01ad3ca04239b450a16ade8942662af6c1ac507d Mon Sep 17 00:00:00 2001 From: srdtrk Date: Sat, 20 Jul 2024 15:46:29 +0800 Subject: [PATCH] imp: using Status enum in StatusResponse --- ibc-clients/cw-context/src/handlers.rs | 13 ++----------- ibc-clients/cw-context/src/types/response.rs | 5 ++--- tests-integration/tests/cosmwasm/fixture.rs | 2 +- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/ibc-clients/cw-context/src/handlers.rs b/ibc-clients/cw-context/src/handlers.rs index 10220a987..76b07e1b2 100644 --- a/ibc-clients/cw-context/src/handlers.rs +++ b/ibc-clients/cw-context/src/handlers.rs @@ -165,14 +165,8 @@ where match msg { QueryMsg::Status(StatusMsg {}) => { - to_json_binary(&client_state.status(self, &client_id).map_or_else( - |e| StatusResponse { - status: e.to_string(), - }, - |s| StatusResponse { - status: s.to_string(), - }, - )) + let status = client_state.status(self, &client_id)?; + to_json_binary(&StatusResponse { status }) } QueryMsg::TimestampAtHeight(msg) => { let client_cons_state_path = ClientConsensusStatePath::new( @@ -183,7 +177,6 @@ where let consensus_state = self.consensus_state(&client_cons_state_path)?; let timestamp = consensus_state.timestamp().nanoseconds(); - to_json_binary(&TimestampAtHeightResponse { timestamp }) } QueryMsg::VerifyClientMessage(msg) => { @@ -192,7 +185,6 @@ where let is_valid = client_state .verify_client_message(self, &client_id, msg.client_message) .is_ok(); - to_json_binary(&VerifyClientMessageResponse { is_valid }) } QueryMsg::CheckForMisbehaviour(msg) => { @@ -200,7 +192,6 @@ where let found_misbehaviour = client_state.check_for_misbehaviour(self, &client_id, msg.client_message)?; - to_json_binary(&CheckForMisbehaviourResponse { found_misbehaviour }) } } diff --git a/ibc-clients/cw-context/src/types/response.rs b/ibc-clients/cw-context/src/types/response.rs index b98f6dccc..84dc3a0f0 100644 --- a/ibc-clients/cw-context/src/types/response.rs +++ b/ibc-clients/cw-context/src/types/response.rs @@ -1,13 +1,12 @@ //! Contains the response types for the CosmWasm contract. use cosmwasm_schema::cw_serde; -use ibc_core::client::types::Height; +use ibc_core::client::types::{Height, Status}; /// The response to [`super::msgs::QueryMsg::Status`] #[cw_serde] pub struct StatusResponse { /// The status of the client - // TODO: Turn this into an enum - pub status: String, + pub status: Status, } /// The response to [`super::msgs::QueryMsg::TimestampAtHeight`] diff --git a/tests-integration/tests/cosmwasm/fixture.rs b/tests-integration/tests/cosmwasm/fixture.rs index 8d585d1a7..90d590dca 100644 --- a/tests-integration/tests/cosmwasm/fixture.rs +++ b/tests-integration/tests/cosmwasm/fixture.rs @@ -168,7 +168,7 @@ impl Fixture { pub fn check_client_status(&self, deps: Deps<'_>, expected: Status) { let resp: StatusResponse = self.query(deps, StatusMsg {}).and_then(from_json).unwrap(); - assert_eq!(resp.status, expected.to_string()); + assert_eq!(resp.status, expected); } pub fn query(&self, deps: Deps<'_>, msg: impl Into) -> StdResult {