Skip to content

Commit

Permalink
Move ibc-testkit integration tests into tests-integration directo…
Browse files Browse the repository at this point in the history
…ry (#1233)

* Move ibc-testkit tests into tests-integration directory

* Fix include_str paths

* Remove unnecessary dependencies from ibc-testkit

* Remove unnecessary dev-dependencies from ibc-testkit

* Add ibc-testkit/serde to serde dependency

* Format ibc-testkit cargo.toml

* Remove unnecessary serde feature from tests-integration crate

* Fix typos

* Move json test data into ibc-testkit

* Move some tests around

* Cargo fmt check

* Gate tests behind serde feature

* Switch doc_comment to doc attribute

* Remove doc-comment dependency

* Move client state unit tests back to ibc-clients

* Add comment about internal crates

* Move test_serialization_roundtrip function to utils

* Assert that serialized string matches json input

* Change serde_json -> dep:serde_json

* Remove features section from cargo.toml

* Remove unused imports

* taplo fmt

* Add features section back to cargo.toml

* update readme and crate description

* format toml

* disable features

Signed-off-by: Rano | Ranadeep <ranadip.bswas@gmail.com>

---------

Signed-off-by: Rano | Ranadeep <ranadip.bswas@gmail.com>
Co-authored-by: Ranadeep Biswas <mail@rnbguy.at>
Co-authored-by: Rano | Ranadeep <ranadeep@informal.systems>
  • Loading branch information
3 people committed May 23, 2024
1 parent 2679767 commit 2378cd4
Show file tree
Hide file tree
Showing 51 changed files with 169 additions and 106 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ members = [
"ibc",
"ibc-query",
"ibc-testkit",

# internal crates that are not published
"tests-integration",
]
exclude = [
"ci/cw-check",
Expand Down
17 changes: 9 additions & 8 deletions ibc-clients/ics07-tendermint/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[package]
name = "ibc-client-tendermint"
version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }
name = "ibc-client-tendermint"
version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }
rust-version = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
readme = "./../README.md"
keywords = [ "blockchain", "consensus", "cosmos", "ibc", "tendermint" ]
license = { workspace = true }
repository = { workspace = true }
readme = "./../README.md"
keywords = [ "blockchain", "consensus", "cosmos", "ibc", "tendermint" ]

description = """
Maintained by `ibc-rs`, contains the implementation of the ICS-07 Tendermint Client logic
and re-exports essential data structures and domain types from `ibc-client-tendermint-types` crate.
Expand Down
44 changes: 0 additions & 44 deletions ibc-clients/ics07-tendermint/types/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,50 +365,6 @@ impl From<ClientState> for Any {
}
}

#[cfg(all(test, feature = "serde"))]
pub(crate) mod serde_tests {
use serde::de::DeserializeOwned;
use serde::Serialize;
use tendermint_rpc::endpoint::abci_query::AbciQuery;

pub fn test_serialization_roundtrip<T>(json_data: &str)
where
T: core::fmt::Debug + PartialEq + Serialize + DeserializeOwned,
{
let parsed0 = serde_json::from_str::<T>(json_data);
assert!(parsed0.is_ok());
let parsed0 = parsed0.unwrap();

let serialized = serde_json::to_string(&parsed0);
assert!(serialized.is_ok());
let serialized = serialized.unwrap();

let parsed1 = serde_json::from_str::<T>(&serialized);
assert!(parsed1.is_ok());
let parsed1 = parsed1.unwrap();

assert_eq!(parsed0, parsed1);
}

#[test]
fn serialization_roundtrip_no_proof() {
let json_data = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../ibc-testkit/tests/data/json/client_state.json"
));
test_serialization_roundtrip::<AbciQuery>(json_data);
}

#[test]
fn serialization_roundtrip_with_proof() {
let json_data = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../ibc-testkit/tests/data/json/client_state_proof.json"
));
test_serialization_roundtrip::<AbciQuery>(json_data);
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
25 changes: 0 additions & 25 deletions ibc-clients/ics07-tendermint/types/src/consensus_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,28 +147,3 @@ impl From<Header> for ConsensusState {
Self::from(header.signed_header.header)
}
}

#[cfg(all(test, feature = "serde"))]
mod tests {
use tendermint_rpc::endpoint::abci_query::AbciQuery;

use crate::serde_tests::test_serialization_roundtrip;

#[test]
fn serialization_roundtrip_no_proof() {
let json_data = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../ibc-testkit/tests/data/json/consensus_state.json"
));
test_serialization_roundtrip::<AbciQuery>(json_data);
}

#[test]
fn serialization_roundtrip_with_proof() {
let json_data = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../ibc-testkit/tests/data/json/consensus_state_proof.json"
));
test_serialization_roundtrip::<AbciQuery>(json_data);
}
}
17 changes: 9 additions & 8 deletions ibc-query/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[package]
name = "ibc-query"
version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }
name = "ibc-query"
version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }
rust-version = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
readme = "README.md"
keywords = [ "blockchain", "cosmos", "ibc", "rpc", "grpc" ]
license = { workspace = true }
repository = { workspace = true }
readme = "README.md"
keywords = [ "blockchain", "cosmos", "ibc", "rpc", "grpc" ]

description = """
Maintained by `ibc-rs`, contains essential IBC query types, utility functions and
gRPC service implementations for the IBC core.
Expand Down
20 changes: 5 additions & 15 deletions ibc-testkit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@ schemars = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
serde_json = { workspace = true, optional = true }
subtle-encoding = { workspace = true }
tracing = { version = "0.1.40", default-features = false }
typed-builder = { version = "0.18.0" }

# ibc dependencies
ibc = { workspace = true, features = [ "std" ] }
ibc-proto = { workspace = true }
ibc-client-cw = { workspace = true }
ibc-client-tendermint-cw = { workspace = true }
ibc-query = { workspace = true }
ibc = { workspace = true, features = [ "std" ] }
ibc-proto = { workspace = true }
ibc-query = { workspace = true }

# basecoin dependencies
basecoin-store = { version = "0.1.0" }
Expand All @@ -43,20 +40,13 @@ tendermint = { workspace = true }
tendermint-testgen = { workspace = true }

[dev-dependencies]
env_logger = { version = "0.11.0" }
tracing-subscriber = { version = "0.3.17", features = [ "fmt", "env-filter", "json" ] }
test-log = { version = "0.2.13", features = [ "trace" ] }
hex = { version = "0.4.2" }
rstest = { workspace = true }
cosmwasm-vm = { workspace = true }
cosmwasm-std = { workspace = true }
hex = { version = "0.4.2" }
rstest = { workspace = true }

[features]
default = [ "std" ]
std = [
"serde/std",
"tracing/std",
"tracing-subscriber/std",
"serde_json/std",
"ibc/std",
"ibc-proto/std",
Expand Down
5 changes: 2 additions & 3 deletions ibc-testkit/src/fixtures/clients/tendermint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub fn dummy_tendermint_header() -> tendermint::block::Header {

serde_json::from_str::<SignedHeader>(include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/data/json/signed_header.json"
"/src/data/json/signed_header.json"
)))
.expect("Never fails")
.header
Expand Down Expand Up @@ -147,7 +147,7 @@ pub fn dummy_ics07_header() -> Header {
// Build a SignedHeader from a JSON file.
let shdr = serde_json::from_str::<SignedHeader>(include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/data/json/signed_header.json"
"/src/data/json/signed_header.json"
)))
.expect("Never fails");

Expand All @@ -174,7 +174,6 @@ pub fn dummy_ics07_header() -> Header {

#[cfg(all(test, feature = "serde"))]
mod tests {

use ibc::primitives::proto::Any;
use rstest::rstest;

Expand Down
25 changes: 25 additions & 0 deletions ibc-testkit/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use ibc::primitives::Timestamp;
#[cfg(feature = "serde")]
use serde::{de::DeserializeOwned, Serialize};
use tendermint::Time;

/// Returns a `Timestamp` representation of the beginning of year 2023.
Expand All @@ -15,3 +17,26 @@ pub fn year_2023() -> Timestamp {
.expect("should be a valid time")
.into()
}

/// Utility function that asserts that the given JSON input can be
/// serialized into and deserialized from the specified type `T`.
#[cfg(feature = "serde")]
pub fn test_serialization_roundtrip<T>(json_data: &str)
where
T: core::fmt::Debug + PartialEq + Serialize + DeserializeOwned,
{
let parsed0 = serde_json::from_str::<T>(json_data);
assert!(parsed0.is_ok());
let parsed0 = parsed0.expect("should not fail");

let serialized = serde_json::to_string(&parsed0);
assert!(serialized.is_ok());
let serialized = serialized.expect("should not fail");
assert_eq!(serialized, json_data);

let parsed1 = serde_json::from_str::<T>(&serialized);
assert!(parsed1.is_ok());
let parsed1 = parsed1.expect("should not fail");

assert_eq!(parsed0, parsed1);
}
57 changes: 57 additions & 0 deletions tests-integration/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[package]
name = "tests-integration"
version = "0.1.0"
authors = { workspace = true }
license = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }
readme = "README.md"
keywords = [ "blockchain", "consensus", "cosmos", "ibc", "tendermint" ]
publish = false
description = "Integration tests using `ibc-testkit` and the other IBC crates."

[dependencies]
# external dependencies
serde = { workspace = true, optional = true }
serde_json = { workspace = true, optional = true }
subtle-encoding = { workspace = true }
tracing = { version = "0.1.40", default-features = false }

# ibc dependencies
ibc = { workspace = true }
ibc-core-client-types = { workspace = true }
ibc-core-commitment-types = { workspace = true }
ibc-client-cw = { workspace = true }
ibc-client-tendermint-cw = { workspace = true }
ibc-client-tendermint-types = { workspace = true }
ibc-core-host-types = { workspace = true }
ibc-primitives = { workspace = true }
ibc-query = { workspace = true }
ibc-testkit = { workspace = true }

# basecoin dependencies
basecoin-store = { version = "0.1.0" }

# cosmos dependencies
tendermint = { workspace = true }
tendermint-testgen = { workspace = true }

[dev_dependencies]
cosmwasm-std = { workspace = true }
hex = { version = "0.4.2" }
rstest = { workspace = true }
test-log = { version = "0.2.13", features = [ "trace" ] }
tendermint-rpc = { workspace = true }

[features]
default = [ "std" ]
std = [
"serde/std",
"serde_json/std",
"ibc/std",
"ibc/serde",
"ibc-testkit/serde",
"tendermint/std",
"dep:serde",
"dep:serde_json",
]
3 changes: 3 additions & 0 deletions tests-integration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Integration tests that make use of the types exposed by `ibc-testkit`. These
tests also depend upon the other IBC crates. They live in a separate crate, that
is not meant to be published, to avoid circular dependencies.
1 change: 1 addition & 0 deletions tests-integration/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#![doc = include_str!("../README.md")]
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions tests-integration/tests/clients/ics07_tendermint/client_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#[cfg(all(test, feature = "serde"))]
mod tests {
use ibc_testkit::utils::test_serialization_roundtrip;
use tendermint_rpc::endpoint::abci_query::AbciQuery;

#[test]
fn serialization_roundtrip_no_proof() {
let json_data = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/data/json/client_state.json"
));
test_serialization_roundtrip::<AbciQuery>(json_data);
}

#[test]
fn serialization_roundtrip_with_proof() {
let json_data = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/data/json/client_state_proof.json"
));
test_serialization_roundtrip::<AbciQuery>(json_data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#[cfg(feature = "serde")]
mod tests {
use ibc_testkit::utils::test_serialization_roundtrip;
use tendermint_rpc::endpoint::abci_query::AbciQuery;

#[test]
fn serialization_roundtrip_no_proof() {
let json_data = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/data/json/consensus_state.json"
));
test_serialization_roundtrip::<AbciQuery>(json_data);
}

#[test]
fn serialization_roundtrip_with_proof() {
let json_data = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/data/json/consensus_state_proof.json"
));
test_serialization_roundtrip::<AbciQuery>(json_data);
}
}
2 changes: 2 additions & 0 deletions tests-integration/tests/clients/ics07_tendermint/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod client_state;
pub mod consensus_state;
1 change: 1 addition & 0 deletions tests-integration/tests/clients/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod ics07_tendermint;
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use ibc::core::host::types::path::{ClientConsensusStatePath, NextClientSequenceP
use ibc::core::host::{ClientStateRef, ValidationContext};
use ibc_query::core::context::ProvableContext;
use ibc_testkit::context::{MockContext, TendermintContext};
use ibc_testkit::fixtures::clients::tendermint::{
dummy_tendermint_header, dummy_tm_client_state_from_header,
};
#[cfg(feature = "serde")]
use ibc_testkit::fixtures::clients::tendermint::dummy_tendermint_header;
use ibc_testkit::fixtures::clients::tendermint::dummy_tm_client_state_from_header;
use ibc_testkit::fixtures::core::context::TestContextConfig;
use ibc_testkit::fixtures::core::signer::dummy_account_id;
use ibc_testkit::testapp::ibc::clients::mock::client_state::{
Expand Down Expand Up @@ -63,6 +63,7 @@ fn test_create_client_ok() {
assert_eq!(ctx.client_state(&client_id).unwrap(), expected_client_state);
}

#[cfg(feature = "serde")]
#[test]
fn test_tm_create_client_ok() {
let signer = dummy_account_id();
Expand Down Expand Up @@ -100,6 +101,7 @@ fn test_tm_create_client_ok() {
assert_eq!(ctx.client_state(&client_id).unwrap(), expected_client_state);
}

#[cfg(feature = "serde")]
#[test]
fn test_invalid_frozen_tm_client_creation() {
let signer = dummy_account_id();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
rust_2018_idioms
)]
pub mod applications;
pub mod clients;
pub mod core;
pub mod cosmwasm;

0 comments on commit 2378cd4

Please sign in to comment.