Skip to content

Commit

Permalink
imp: using Status enum in StatusResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Jul 20, 2024
1 parent 2ec47c0 commit 01ad3ca
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
13 changes: 2 additions & 11 deletions ibc-clients/cw-context/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 })

Check warning on line 180 in ibc-clients/cw-context/src/handlers.rs

View check run for this annotation

Codecov / codecov/patch

ibc-clients/cw-context/src/handlers.rs#L179-L180

Added lines #L179 - L180 were not covered by tests
}
QueryMsg::VerifyClientMessage(msg) => {
Expand All @@ -192,15 +185,13 @@ 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) => {
let msg = CheckForMisbehaviourMsg::try_from(msg)?;

let found_misbehaviour =
client_state.check_for_misbehaviour(self, &client_id, msg.client_message)?;

to_json_binary(&CheckForMisbehaviourResponse { found_misbehaviour })
}
}
Expand Down
5 changes: 2 additions & 3 deletions ibc-clients/cw-context/src/types/response.rs
Original file line number Diff line number Diff line change
@@ -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`]
Expand Down
2 changes: 1 addition & 1 deletion tests-integration/tests/cosmwasm/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<QueryMsg>) -> StdResult<Binary> {
Expand Down

0 comments on commit 01ad3ca

Please sign in to comment.