Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move ibc-testkit integration tests into tests-integration directory #1233

Merged
merged 30 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
20b8be5
Move ibc-testkit tests into tests-integration directory
seanchen1991 May 21, 2024
a4fe084
Fix include_str paths
seanchen1991 May 21, 2024
4f2aeeb
Remove unnecessary dependencies from ibc-testkit
seanchen1991 May 21, 2024
5ce098a
Remove unnecessary dev-dependencies from ibc-testkit
seanchen1991 May 21, 2024
91a36cc
Add ibc-testkit/serde to serde dependency
seanchen1991 May 21, 2024
3a95e85
Merge branch 'main' into sean/move-integration-tests
seanchen1991 May 21, 2024
8982f02
Format ibc-testkit cargo.toml
seanchen1991 May 21, 2024
f1ec56a
Merge branch 'sean/move-integration-tests' of https://github.com/cosm…
seanchen1991 May 21, 2024
ae3b0dc
Remove unnecessary serde feature from tests-integration crate
seanchen1991 May 22, 2024
baa31dd
Fix typos
seanchen1991 May 22, 2024
1065055
Move json test data into ibc-testkit
seanchen1991 May 22, 2024
668df68
Move some tests around
seanchen1991 May 22, 2024
f92561b
Cargo fmt check
seanchen1991 May 22, 2024
5bd1b7d
Gate tests behind serde feature
seanchen1991 May 22, 2024
58c6a24
Switch doc_comment to doc attribute
seanchen1991 May 22, 2024
de2cb21
Remove doc-comment dependency
seanchen1991 May 22, 2024
4fe1394
Move client state unit tests back to ibc-clients
seanchen1991 May 22, 2024
9a4abfd
Add comment about internal crates
seanchen1991 May 22, 2024
4211e04
Move test_serialization_roundtrip function to utils
seanchen1991 May 22, 2024
a9dc193
Assert that serialized string matches json input
seanchen1991 May 22, 2024
09bf968
Change serde_json -> dep:serde_json
seanchen1991 May 22, 2024
921e192
Merge branch 'main' of https://github.com/cosmos/ibc-rs into sean/mov…
seanchen1991 May 22, 2024
bdec466
Remove features section from cargo.toml
seanchen1991 May 22, 2024
774a50f
Remove unused imports
seanchen1991 May 22, 2024
4647e72
taplo fmt
seanchen1991 May 22, 2024
b6ac491
Add features section back to cargo.toml
seanchen1991 May 22, 2024
d4ece8f
update readme and crate description
rnbguy May 23, 2024
b4e8a56
format toml
rnbguy May 23, 2024
db5e09e
disable features
rnbguy May 23, 2024
a2174a8
Merge branch 'main' into sean/move-integration-tests
rnbguy May 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
seanchen1991 marked this conversation as resolved.
Show resolved Hide resolved
]
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 {
seanchen1991 marked this conversation as resolved.
Show resolved Hide resolved
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 @@
.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);

Check warning on line 35 in ibc-testkit/src/utils/mod.rs

View check run for this annotation

Codecov / codecov/patch

ibc-testkit/src/utils/mod.rs#L24-L35

Added lines #L24 - L35 were not covered by tests

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

assert_eq!(parsed0, parsed1);
}

Check warning on line 42 in ibc-testkit/src/utils/mod.rs

View check run for this annotation

Codecov / codecov/patch

ibc-testkit/src/utils/mod.rs#L37-L42

Added lines #L37 - L42 were not covered by tests
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")]
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.
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;
Loading