Skip to content

Commit 476937b

Browse files
authored
test: tendermint client update when client expires or validator set has changed (#921)
* add client expiry test * tm hostblock supports trusted next validator set * fix validator change update test * fix incorrect validator updates at each block * add sad client update for validator change * cargo fmt * catch up with main branch changes * update MockContextConfig with validator set history * refactor tests with updated MockContextConfig * rm duplicate def of `on` * add todo for max_history_size and validator_set_history * consistent variable naming in tests * bump typed-builder version * rm redundant builder arguments * replace todo with panic * mv Tendermint ClientStateConfig under ics07 * use ctx_a with ctx_b instead of only ctx * use client_id consistently * use mocks feature directly in dev-deps * include trusting_period and max_clock_drift in mock light client config * revert advance chain height with timestamp * update client expiry test * add test to check max_clock_drift * rm TODO comments in favor of gh issue * revert ctx_a renaming * add changelog entry
1 parent 26c7ba6 commit 476937b

File tree

8 files changed

+556
-72
lines changed

8 files changed

+556
-72
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Add test for expired client status.
2+
([\#538](https://github.com/cosmos/ibc-rs/issues/538))

.github/workflows/cw-check.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ on:
44
paths:
55
- .github/workflows/cw-check.yml
66
- ci/cw-check/**
7-
8-
on:
97
push:
108
tags:
119
- v[0-9]+.*

crates/ibc/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ schema = ["dep:schemars", "serde", "std"]
4646

4747
# This feature grants access to development-time mocking libraries, such as `MockContext` or `MockHeader`.
4848
# Depends on the `testgen` suite for generating Tendermint light blocks.
49-
mocks = ["tendermint-testgen", "tendermint/clock", "parking_lot"]
49+
mocks = ["tendermint-testgen", "tendermint/clock", "parking_lot", "typed-builder"]
5050

5151
[dependencies]
5252
# Proto definitions for all IBC-related interfaces, e.g., connections or channels.
@@ -73,6 +73,7 @@ scale-info = { version = "2.1.2", default-features = false, features = ["derive"
7373
## for borsh encode or decode
7474
borsh = {version = "0.10", default-features = false, optional = true }
7575
parking_lot = { version = "0.12.1", default-features = false, optional = true }
76+
typed-builder = { version = "0.17.0", optional = true }
7677

7778
ibc-derive = { version ="0.3.0", path = "../ibc-derive" }
7879

@@ -102,5 +103,4 @@ rstest = "0.18.1"
102103
tracing-subscriber = { version = "0.3.14", features = ["fmt", "env-filter", "json"]}
103104
test-log = { version = "0.2.10", features = ["trace"] }
104105
tendermint-rpc = { version = "0.34", features = ["http-client", "websocket-client"] }
105-
tendermint-testgen = { version = "0.34" } # Needed for generating (synthetic) light blocks.
106-
parking_lot = { version = "0.12.1" }
106+
ibc = { path = ".", features = ["mocks"] }

crates/ibc/src/clients/ics07_tendermint/client_state.rs

+40-1
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,8 @@ pub mod test_util {
11291129
use tendermint::block::Header;
11301130

11311131
use crate::clients::ics07_tendermint::client_state::{AllowUpdate, ClientState};
1132-
use crate::clients::ics07_tendermint::error::Error;
1132+
use crate::clients::ics07_tendermint::error::{Error as ClientError, Error};
1133+
use crate::clients::ics07_tendermint::trust_threshold::TrustThreshold;
11331134
use crate::core::ics02_client::height::Height;
11341135
use crate::core::ics23_commitment::specs::ProofSpecs;
11351136
use crate::core::ics24_host::identifier::ChainId;
@@ -1180,4 +1181,42 @@ pub mod test_util {
11801181
allow_update_after_misbehaviour: false,
11811182
}
11821183
}
1184+
1185+
#[derive(typed_builder::TypedBuilder, Debug)]
1186+
pub struct ClientStateConfig {
1187+
pub chain_id: ChainId,
1188+
#[builder(default)]
1189+
pub trust_level: TrustThreshold,
1190+
#[builder(default = Duration::from_secs(64000))]
1191+
pub trusting_period: Duration,
1192+
#[builder(default = Duration::from_secs(128000))]
1193+
pub unbonding_period: Duration,
1194+
#[builder(default = Duration::from_millis(3000))]
1195+
max_clock_drift: Duration,
1196+
pub latest_height: Height,
1197+
#[builder(default)]
1198+
pub proof_specs: ProofSpecs,
1199+
#[builder(default)]
1200+
pub upgrade_path: Vec<String>,
1201+
#[builder(default = AllowUpdate { after_expiry: false, after_misbehaviour: false })]
1202+
allow_update: AllowUpdate,
1203+
}
1204+
1205+
impl TryFrom<ClientStateConfig> for ClientState {
1206+
type Error = ClientError;
1207+
1208+
fn try_from(config: ClientStateConfig) -> Result<Self, Self::Error> {
1209+
ClientState::new(
1210+
config.chain_id,
1211+
config.trust_level,
1212+
config.trusting_period,
1213+
config.unbonding_period,
1214+
config.max_clock_drift,
1215+
config.latest_height,
1216+
config.proof_specs,
1217+
config.upgrade_path,
1218+
config.allow_update,
1219+
)
1220+
}
1221+
}
11831222
}

crates/ibc/src/clients/ics07_tendermint/header.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,14 @@ pub mod test_util {
318318
fn from(light_block: SyntheticTmBlock) -> Self {
319319
let SyntheticTmBlock {
320320
trusted_height,
321+
trusted_next_validators,
321322
light_block,
322323
} = light_block;
323324
Self {
324325
signed_header: light_block.signed_header,
325326
validator_set: light_block.validators,
326327
trusted_height,
327-
trusted_next_validator_set: light_block.next_validators,
328+
trusted_next_validator_set: trusted_next_validators,
328329
}
329330
}
330331
}

0 commit comments

Comments
 (0)