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 14 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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ members = [
"ibc",
"ibc-query",
"ibc-testkit",
"tests-integration",
seanchen1991 marked this conversation as resolved.
Show resolved Hide resolved
]
exclude = [
"ci/cw-check",
Expand Down
220 changes: 0 additions & 220 deletions ibc-clients/ics07-tendermint/types/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,223 +364,3 @@ 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::*;

#[derive(Clone, Debug, PartialEq)]
pub struct ClientStateParams {
pub id: ChainId,
pub trust_level: TrustThreshold,
pub trusting_period: Duration,
pub unbonding_period: Duration,
pub max_clock_drift: Duration,
pub latest_height: Height,
pub proof_specs: ProofSpecs,
pub upgrade_path: Vec<String>,
pub allow_update: AllowUpdate,
}

#[test]
fn client_state_new() {
// Define a "default" set of parameters to reuse throughout these tests.
let default_params: ClientStateParams = ClientStateParams {
id: ChainId::new("ibc-0").unwrap(),
trust_level: TrustThreshold::ONE_THIRD,
trusting_period: Duration::new(64000, 0),
unbonding_period: Duration::new(128_000, 0),
max_clock_drift: Duration::new(3, 0),
latest_height: Height::new(0, 10).expect("Never fails"),
proof_specs: ProofSpecs::cosmos(),
upgrade_path: Vec::new(),
allow_update: AllowUpdate {
after_expiry: false,
after_misbehaviour: false,
},
};

struct Test {
name: String,
params: ClientStateParams,
want_pass: bool,
}

let tests: Vec<Test> = vec![
Test {
name: "Valid parameters".to_string(),
params: default_params.clone(),
want_pass: true,
},
Test {
name: "Valid (empty) upgrade-path".to_string(),
params: ClientStateParams {
upgrade_path: vec![],
..default_params.clone()
},
want_pass: true,
},
Test {
name: "Valid upgrade-path".to_string(),
params: ClientStateParams {
upgrade_path: vec!["upgrade".to_owned(), "upgradedIBCState".to_owned()],
..default_params.clone()
},
want_pass: true,
},
Test {
name: "Valid long (50 chars) chain-id that satisfies revision_number length < `u64::MAX` length".to_string(),
params: ClientStateParams {
id: ChainId::new(&format!("{}-{}", "a".repeat(29), 0)).unwrap(),
..default_params.clone()
},
want_pass: true,
},
Test {
name: "Invalid too-long (51 chars) chain-id".to_string(),
params: ClientStateParams {
id: ChainId::new(&format!("{}-{}", "a".repeat(30), 0)).unwrap(),
..default_params.clone()
},
want_pass: false,
},
Test {
name: "Invalid (zero) max-clock-drift period".to_string(),
params: ClientStateParams {
max_clock_drift: ZERO_DURATION,
..default_params.clone()
},
want_pass: false,
},
Test {
name: "Invalid unbonding period".to_string(),
params: ClientStateParams {
unbonding_period: ZERO_DURATION,
..default_params.clone()
},
want_pass: false,
},
Test {
name: "Invalid (too small) trusting period".to_string(),
params: ClientStateParams {
trusting_period: ZERO_DURATION,
..default_params.clone()
},
want_pass: false,
},
Test {
name: "Invalid (too large) trusting period w.r.t. unbonding period".to_string(),
params: ClientStateParams {
trusting_period: Duration::new(11, 0),
unbonding_period: Duration::new(10, 0),
..default_params.clone()
},
want_pass: false,
},
Test {
name: "Invalid (equal) trusting period w.r.t. unbonding period".to_string(),
params: ClientStateParams {
trusting_period: Duration::new(10, 0),
unbonding_period: Duration::new(10, 0),
..default_params.clone()
},
want_pass: false,
},
Test {
name: "Invalid (zero) trusting trust threshold".to_string(),
params: ClientStateParams {
trust_level: TrustThreshold::ZERO,
..default_params.clone()
},
want_pass: false,
},
Test {
name: "Invalid (too small) trusting trust threshold".to_string(),
params: ClientStateParams {
trust_level: TrustThreshold::new(1, 4).expect("Never fails"),
..default_params.clone()
},
want_pass: false,
},
Test {
name: "Invalid latest height revision number (doesn't match chain)".to_string(),
params: ClientStateParams {
latest_height: Height::new(1, 1).expect("Never fails"),
..default_params.clone()
},
want_pass: false,
},
]
.into_iter()
.collect();

for test in tests {
let p = test.params.clone();

let cs_result: Result<ClientState, Error> = ClientState::new(
p.id,
p.trust_level,
p.trusting_period,
p.unbonding_period,
p.max_clock_drift,
p.latest_height,
p.proof_specs,
p.upgrade_path,
p.allow_update,
);

assert_eq!(
test.want_pass,
cs_result.is_ok(),
"ClientState::new() failed for test {}, \nmsg{:?} with error {:?}",
test.name,
test.params.clone(),
cs_result.err(),
);
}
}
}
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);
}
}
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
27 changes: 24 additions & 3 deletions ibc-testkit/src/fixtures/clients/tendermint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use ibc::core::commitment_types::specs::ProofSpecs;
use ibc::core::host::types::identifiers::ChainId;
use ibc::core::primitives::prelude::*;
#[cfg(feature = "serde")]
use serde::{de::DeserializeOwned, Serialize};
use tendermint::block::Header as TmHeader;
use typed_builder::TypedBuilder;

Expand Down Expand Up @@ -117,7 +119,7 @@

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 +149,7 @@
// 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 @@ -172,9 +174,28 @@
}
}

#[cfg(feature = "serde")]
pub fn test_serialization_roundtrip<T>(json_data: &str)
seanchen1991 marked this conversation as resolved.
Show resolved Hide resolved
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");
seanchen1991 marked this conversation as resolved.
Show resolved Hide resolved

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 195 in ibc-testkit/src/fixtures/clients/tendermint.rs

View check run for this annotation

Codecov / codecov/patch

ibc-testkit/src/fixtures/clients/tendermint.rs#L178-L195

Added lines #L178 - L195 were not covered by tests

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

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

Expand Down
Loading
Loading