Skip to content

Commit

Permalink
imp: all tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Jul 15, 2024
1 parent 586ed88 commit 3854090
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
32 changes: 13 additions & 19 deletions tests-integration/tests/cosmwasm/fixture.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::Duration;

use cosmwasm_std::{from_json, Deps, DepsMut, Empty, Response, StdError, StdResult};
use cosmwasm_std::{from_json, Binary, Deps, DepsMut, Empty, Response, StdError, StdResult};
use ibc::clients::tendermint::client_state::ClientState as TmClientState;
use ibc::clients::tendermint::consensus_state::ConsensusState as TmConsensusState;
use ibc::clients::tendermint::types::Header;
Expand All @@ -15,7 +15,6 @@ use ibc_client_cw::types::{
use ibc_client_cw::utils::AnyCodec;
use ibc_client_tendermint_cw::entrypoint::TendermintContext;
use ibc_testkit::fixtures::clients::tendermint::ClientStateConfig;
use serde::de::DeserializeOwned;
use tendermint::Time;
use tendermint_testgen::{Generator, Validator};

Expand Down Expand Up @@ -139,49 +138,44 @@ impl Fixture {
}

pub fn verify_client_message(&self, deps: Deps<'_>, client_message: Vec<u8>) {
let resp = self
.query::<VerifyClientMessageResponse>(
let resp: VerifyClientMessageResponse = self
.query(
deps,
VerifyClientMessageRaw {
client_message: client_message.into(),
}
.into(),
},
)
.and_then(from_json)
.unwrap();

assert!(resp.is_valid);
}

pub fn check_for_misbehaviour(&self, deps: Deps<'_>, client_message: Vec<u8>) {
let resp = self
.query::<CheckForMisbehaviourResponse>(
let resp: CheckForMisbehaviourResponse = self
.query(
deps,
CheckForMisbehaviourMsgRaw {
client_message: client_message.into(),
}
.into(),
},
)
.and_then(from_json)
.unwrap();

assert!(resp.found_misbehaviour);
}

pub fn check_client_status(&self, deps: Deps<'_>, expected: Status) {
let resp = self
.query::<StatusResponse>(deps, StatusMsg {}.into())
.unwrap();
let resp: StatusResponse = self.query(deps, StatusMsg {}).and_then(from_json).unwrap();

assert_eq!(resp.status, expected.to_string());
}

pub fn query<T: DeserializeOwned>(&self, deps: Deps<'_>, msg: QueryMsg) -> StdResult<T> {
pub fn query(&self, deps: Deps<'_>, msg: impl Into<QueryMsg>) -> StdResult<Binary> {
let ctx = self.ctx_ref(deps);

let resp_bytes = ctx
.query(msg)
.map_err(|e| StdError::generic_err(e.to_string()))?;

from_json(resp_bytes)
ctx.query(msg.into())
.map_err(|e| StdError::generic_err(e.to_string()))
}

pub fn create_client(&self, deps_mut: DepsMut<'_>) -> Result<Response, ContractError> {
Expand Down
20 changes: 11 additions & 9 deletions tests-integration/tests/cosmwasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,17 @@ fn test_cw_client_expiry() {

let client_message = fxt.dummy_client_message(target_height);

let resp = fxt.query::<VerifyClientMessageResponse>(
deps.as_ref(),
VerifyClientMessageRaw {
client_message: client_message.into(),
}
.into(),
);

assert!(!resp.unwrap().is_valid);
let resp: VerifyClientMessageResponse = fxt
.query(
deps.as_ref(),
VerifyClientMessageRaw {
client_message: client_message.into(),
},
)
.and_then(from_json)
.unwrap();

assert!(!resp.is_valid);

// ------------------- Check client status -------------------

Expand Down

0 comments on commit 3854090

Please sign in to comment.