Skip to content

Commit 2378cd4

Browse files
seanchen1991rnbguy
andauthored
Move ibc-testkit integration tests into tests-integration directory (#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 <[email protected]> --------- Signed-off-by: Rano | Ranadeep <[email protected]> Co-authored-by: Ranadeep Biswas <[email protected]> Co-authored-by: Rano | Ranadeep <[email protected]>
1 parent 2679767 commit 2378cd4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+169
-106
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ members = [
3535
"ibc",
3636
"ibc-query",
3737
"ibc-testkit",
38+
39+
# internal crates that are not published
40+
"tests-integration",
3841
]
3942
exclude = [
4043
"ci/cw-check",

ibc-clients/ics07-tendermint/Cargo.toml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
[package]
2-
name = "ibc-client-tendermint"
3-
version = { workspace = true }
4-
authors = { workspace = true }
5-
edition = { workspace = true }
2+
name = "ibc-client-tendermint"
3+
version = { workspace = true }
4+
authors = { workspace = true }
5+
edition = { workspace = true }
66
rust-version = { workspace = true }
7-
license = { workspace = true }
8-
repository = { workspace = true }
9-
readme = "./../README.md"
10-
keywords = [ "blockchain", "consensus", "cosmos", "ibc", "tendermint" ]
7+
license = { workspace = true }
8+
repository = { workspace = true }
9+
readme = "./../README.md"
10+
keywords = [ "blockchain", "consensus", "cosmos", "ibc", "tendermint" ]
11+
1112
description = """
1213
Maintained by `ibc-rs`, contains the implementation of the ICS-07 Tendermint Client logic
1314
and re-exports essential data structures and domain types from `ibc-client-tendermint-types` crate.

ibc-clients/ics07-tendermint/types/src/client_state.rs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -365,50 +365,6 @@ impl From<ClientState> for Any {
365365
}
366366
}
367367

368-
#[cfg(all(test, feature = "serde"))]
369-
pub(crate) mod serde_tests {
370-
use serde::de::DeserializeOwned;
371-
use serde::Serialize;
372-
use tendermint_rpc::endpoint::abci_query::AbciQuery;
373-
374-
pub fn test_serialization_roundtrip<T>(json_data: &str)
375-
where
376-
T: core::fmt::Debug + PartialEq + Serialize + DeserializeOwned,
377-
{
378-
let parsed0 = serde_json::from_str::<T>(json_data);
379-
assert!(parsed0.is_ok());
380-
let parsed0 = parsed0.unwrap();
381-
382-
let serialized = serde_json::to_string(&parsed0);
383-
assert!(serialized.is_ok());
384-
let serialized = serialized.unwrap();
385-
386-
let parsed1 = serde_json::from_str::<T>(&serialized);
387-
assert!(parsed1.is_ok());
388-
let parsed1 = parsed1.unwrap();
389-
390-
assert_eq!(parsed0, parsed1);
391-
}
392-
393-
#[test]
394-
fn serialization_roundtrip_no_proof() {
395-
let json_data = include_str!(concat!(
396-
env!("CARGO_MANIFEST_DIR"),
397-
"/../../../ibc-testkit/tests/data/json/client_state.json"
398-
));
399-
test_serialization_roundtrip::<AbciQuery>(json_data);
400-
}
401-
402-
#[test]
403-
fn serialization_roundtrip_with_proof() {
404-
let json_data = include_str!(concat!(
405-
env!("CARGO_MANIFEST_DIR"),
406-
"/../../../ibc-testkit/tests/data/json/client_state_proof.json"
407-
));
408-
test_serialization_roundtrip::<AbciQuery>(json_data);
409-
}
410-
}
411-
412368
#[cfg(test)]
413369
mod tests {
414370
use super::*;

ibc-clients/ics07-tendermint/types/src/consensus_state.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -147,28 +147,3 @@ impl From<Header> for ConsensusState {
147147
Self::from(header.signed_header.header)
148148
}
149149
}
150-
151-
#[cfg(all(test, feature = "serde"))]
152-
mod tests {
153-
use tendermint_rpc::endpoint::abci_query::AbciQuery;
154-
155-
use crate::serde_tests::test_serialization_roundtrip;
156-
157-
#[test]
158-
fn serialization_roundtrip_no_proof() {
159-
let json_data = include_str!(concat!(
160-
env!("CARGO_MANIFEST_DIR"),
161-
"/../../../ibc-testkit/tests/data/json/consensus_state.json"
162-
));
163-
test_serialization_roundtrip::<AbciQuery>(json_data);
164-
}
165-
166-
#[test]
167-
fn serialization_roundtrip_with_proof() {
168-
let json_data = include_str!(concat!(
169-
env!("CARGO_MANIFEST_DIR"),
170-
"/../../../ibc-testkit/tests/data/json/consensus_state_proof.json"
171-
));
172-
test_serialization_roundtrip::<AbciQuery>(json_data);
173-
}
174-
}

ibc-query/Cargo.toml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
[package]
2-
name = "ibc-query"
3-
version = { workspace = true }
4-
authors = { workspace = true }
5-
edition = { workspace = true }
2+
name = "ibc-query"
3+
version = { workspace = true }
4+
authors = { workspace = true }
5+
edition = { workspace = true }
66
rust-version = { workspace = true }
7-
license = { workspace = true }
8-
repository = { workspace = true }
9-
readme = "README.md"
10-
keywords = [ "blockchain", "cosmos", "ibc", "rpc", "grpc" ]
7+
license = { workspace = true }
8+
repository = { workspace = true }
9+
readme = "README.md"
10+
keywords = [ "blockchain", "cosmos", "ibc", "rpc", "grpc" ]
11+
1112
description = """
1213
Maintained by `ibc-rs`, contains essential IBC query types, utility functions and
1314
gRPC service implementations for the IBC core.

ibc-testkit/Cargo.toml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@ schemars = { workspace = true, optional = true }
2525
serde = { workspace = true, optional = true }
2626
serde_json = { workspace = true, optional = true }
2727
subtle-encoding = { workspace = true }
28-
tracing = { version = "0.1.40", default-features = false }
2928
typed-builder = { version = "0.18.0" }
3029

3130
# ibc dependencies
32-
ibc = { workspace = true, features = [ "std" ] }
33-
ibc-proto = { workspace = true }
34-
ibc-client-cw = { workspace = true }
35-
ibc-client-tendermint-cw = { workspace = true }
36-
ibc-query = { workspace = true }
31+
ibc = { workspace = true, features = [ "std" ] }
32+
ibc-proto = { workspace = true }
33+
ibc-query = { workspace = true }
3734

3835
# basecoin dependencies
3936
basecoin-store = { version = "0.1.0" }
@@ -43,20 +40,13 @@ tendermint = { workspace = true }
4340
tendermint-testgen = { workspace = true }
4441

4542
[dev-dependencies]
46-
env_logger = { version = "0.11.0" }
47-
tracing-subscriber = { version = "0.3.17", features = [ "fmt", "env-filter", "json" ] }
48-
test-log = { version = "0.2.13", features = [ "trace" ] }
49-
hex = { version = "0.4.2" }
50-
rstest = { workspace = true }
51-
cosmwasm-vm = { workspace = true }
52-
cosmwasm-std = { workspace = true }
43+
hex = { version = "0.4.2" }
44+
rstest = { workspace = true }
5345

5446
[features]
5547
default = [ "std" ]
5648
std = [
5749
"serde/std",
58-
"tracing/std",
59-
"tracing-subscriber/std",
6050
"serde_json/std",
6151
"ibc/std",
6252
"ibc-proto/std",

ibc-testkit/src/fixtures/clients/tendermint.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub fn dummy_tendermint_header() -> tendermint::block::Header {
117117

118118
serde_json::from_str::<SignedHeader>(include_str!(concat!(
119119
env!("CARGO_MANIFEST_DIR"),
120-
"/tests/data/json/signed_header.json"
120+
"/src/data/json/signed_header.json"
121121
)))
122122
.expect("Never fails")
123123
.header
@@ -147,7 +147,7 @@ pub fn dummy_ics07_header() -> Header {
147147
// Build a SignedHeader from a JSON file.
148148
let shdr = serde_json::from_str::<SignedHeader>(include_str!(concat!(
149149
env!("CARGO_MANIFEST_DIR"),
150-
"/tests/data/json/signed_header.json"
150+
"/src/data/json/signed_header.json"
151151
)))
152152
.expect("Never fails");
153153

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

175175
#[cfg(all(test, feature = "serde"))]
176176
mod tests {
177-
178177
use ibc::primitives::proto::Any;
179178
use rstest::rstest;
180179

ibc-testkit/src/utils/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use ibc::primitives::Timestamp;
2+
#[cfg(feature = "serde")]
3+
use serde::{de::DeserializeOwned, Serialize};
24
use tendermint::Time;
35

46
/// Returns a `Timestamp` representation of the beginning of year 2023.
@@ -15,3 +17,26 @@ pub fn year_2023() -> Timestamp {
1517
.expect("should be a valid time")
1618
.into()
1719
}
20+
21+
/// Utility function that asserts that the given JSON input can be
22+
/// serialized into and deserialized from the specified type `T`.
23+
#[cfg(feature = "serde")]
24+
pub fn test_serialization_roundtrip<T>(json_data: &str)
25+
where
26+
T: core::fmt::Debug + PartialEq + Serialize + DeserializeOwned,
27+
{
28+
let parsed0 = serde_json::from_str::<T>(json_data);
29+
assert!(parsed0.is_ok());
30+
let parsed0 = parsed0.expect("should not fail");
31+
32+
let serialized = serde_json::to_string(&parsed0);
33+
assert!(serialized.is_ok());
34+
let serialized = serialized.expect("should not fail");
35+
assert_eq!(serialized, json_data);
36+
37+
let parsed1 = serde_json::from_str::<T>(&serialized);
38+
assert!(parsed1.is_ok());
39+
let parsed1 = parsed1.expect("should not fail");
40+
41+
assert_eq!(parsed0, parsed1);
42+
}

tests-integration/Cargo.toml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[package]
2+
name = "tests-integration"
3+
version = "0.1.0"
4+
authors = { workspace = true }
5+
license = { workspace = true }
6+
edition = { workspace = true }
7+
repository = { workspace = true }
8+
readme = "README.md"
9+
keywords = [ "blockchain", "consensus", "cosmos", "ibc", "tendermint" ]
10+
publish = false
11+
description = "Integration tests using `ibc-testkit` and the other IBC crates."
12+
13+
[dependencies]
14+
# external dependencies
15+
serde = { workspace = true, optional = true }
16+
serde_json = { workspace = true, optional = true }
17+
subtle-encoding = { workspace = true }
18+
tracing = { version = "0.1.40", default-features = false }
19+
20+
# ibc dependencies
21+
ibc = { workspace = true }
22+
ibc-core-client-types = { workspace = true }
23+
ibc-core-commitment-types = { workspace = true }
24+
ibc-client-cw = { workspace = true }
25+
ibc-client-tendermint-cw = { workspace = true }
26+
ibc-client-tendermint-types = { workspace = true }
27+
ibc-core-host-types = { workspace = true }
28+
ibc-primitives = { workspace = true }
29+
ibc-query = { workspace = true }
30+
ibc-testkit = { workspace = true }
31+
32+
# basecoin dependencies
33+
basecoin-store = { version = "0.1.0" }
34+
35+
# cosmos dependencies
36+
tendermint = { workspace = true }
37+
tendermint-testgen = { workspace = true }
38+
39+
[dev_dependencies]
40+
cosmwasm-std = { workspace = true }
41+
hex = { version = "0.4.2" }
42+
rstest = { workspace = true }
43+
test-log = { version = "0.2.13", features = [ "trace" ] }
44+
tendermint-rpc = { workspace = true }
45+
46+
[features]
47+
default = [ "std" ]
48+
std = [
49+
"serde/std",
50+
"serde_json/std",
51+
"ibc/std",
52+
"ibc/serde",
53+
"ibc-testkit/serde",
54+
"tendermint/std",
55+
"dep:serde",
56+
"dep:serde_json",
57+
]

0 commit comments

Comments
 (0)