Skip to content

Commit

Permalink
test: updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Jul 15, 2024
1 parent 21b5cc8 commit 5a5f63e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ibc-clients/cw-context/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ where
}
QueryMsg::ExportMetadata(ExportMetadataMsg {}) => {
to_json_binary(&ExportMetadataResponse {
metadata: self.get_metadata()?,
genesis_metadata: self.get_metadata()?,
})
}
QueryMsg::TimestampAtHeight(msg) => {
Expand Down
2 changes: 1 addition & 1 deletion ibc-clients/cw-context/src/types/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct StatusResponse {
pub struct ExportMetadataResponse {
/// The genesis metadata
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Vec<GenesisMetadata>>,
pub genesis_metadata: Option<Vec<GenesisMetadata>>,
}

/// The response to [`super::msgs::QueryMsg::TimestampAtHeight`]
Expand Down
27 changes: 14 additions & 13 deletions tests-integration/tests/cosmwasm/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ use ibc::core::client::types::{Height, Status};
use ibc::core::host::types::identifiers::ChainId;
use ibc::core::primitives::Timestamp;
use ibc_client_cw::types::{
CheckForMisbehaviourMsgRaw, ContractError, ExportMetadataMsg, GenesisMetadata, InstantiateMsg,
MigrationPrefix, QueryMsg, QueryResponse, StatusMsg, UpdateStateMsgRaw,
UpdateStateOnMisbehaviourMsgRaw, VerifyClientMessageRaw,
CheckForMisbehaviourMsgRaw, CheckForMisbehaviourResponse, ContractError, ExportMetadataMsg,
ExportMetadataResponse, GenesisMetadata, InstantiateMsg, MigrationPrefix, QueryMsg, StatusMsg,
StatusResponse, UpdateStateMsgRaw, UpdateStateOnMisbehaviourMsgRaw, VerifyClientMessageRaw,
VerifyClientMessageResponse,
};
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,7 +141,7 @@ impl Fixture {

pub fn verify_client_message(&self, deps: Deps<'_>, client_message: Vec<u8>) {
let resp = self
.query(
.query::<VerifyClientMessageResponse>(
deps,
VerifyClientMessageRaw {
client_message: client_message.into(),
Expand All @@ -149,13 +151,11 @@ impl Fixture {
.unwrap();

assert!(resp.is_valid);
assert!(resp.status.is_none());
assert!(resp.found_misbehaviour.is_none());
}

pub fn check_for_misbehaviour(&self, deps: Deps<'_>, client_message: Vec<u8>) {
let resp = self
.query(
.query::<CheckForMisbehaviourResponse>(
deps,
CheckForMisbehaviourMsgRaw {
client_message: client_message.into(),
Expand All @@ -164,23 +164,24 @@ impl Fixture {
)
.unwrap();

assert!(resp.is_valid);
assert_eq!(resp.found_misbehaviour, Some(true));
assert!(resp.found_misbehaviour);
}

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

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

pub fn get_metadata(&self, deps: Deps<'_>) -> Option<Vec<GenesisMetadata>> {
self.query(deps, ExportMetadataMsg {}.into())
self.query::<ExportMetadataResponse>(deps, ExportMetadataMsg {}.into())
.map(|resp| resp.genesis_metadata)
.unwrap()
}

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

let resp_bytes = ctx
Expand Down
5 changes: 3 additions & 2 deletions tests-integration/tests/cosmwasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use fixture::Fixture;
use ibc::core::client::types::{Height, Status};
use ibc_client_cw::types::{
ContractResult, MigrateClientStoreMsg, MigrationPrefix, VerifyClientMessageRaw,
VerifyClientMessageResponse,
};
use ibc_client_tendermint_cw::entrypoint::sudo;

Expand Down Expand Up @@ -107,15 +108,15 @@ fn test_cw_client_expiry() {

let client_message = fxt.dummy_client_message(target_height);

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

assert!(resp.is_err());
assert!(!resp.unwrap().is_valid);

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

Expand Down

0 comments on commit 5a5f63e

Please sign in to comment.