Skip to content

Commit

Permalink
test: tendermint client update when client expires or validator set h…
Browse files Browse the repository at this point in the history
…as 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
  • Loading branch information
rnbguy authored Oct 18, 2023
1 parent 26c7ba6 commit 476937b
Show file tree
Hide file tree
Showing 8 changed files with 556 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add test for expired client status.
([\#538](https://github.com/cosmos/ibc-rs/issues/538))
2 changes: 0 additions & 2 deletions .github/workflows/cw-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
paths:
- .github/workflows/cw-check.yml
- ci/cw-check/**

on:
push:
tags:
- v[0-9]+.*
Expand Down
6 changes: 3 additions & 3 deletions crates/ibc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ schema = ["dep:schemars", "serde", "std"]

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

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

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

Expand Down Expand Up @@ -102,5 +103,4 @@ rstest = "0.18.1"
tracing-subscriber = { version = "0.3.14", features = ["fmt", "env-filter", "json"]}
test-log = { version = "0.2.10", features = ["trace"] }
tendermint-rpc = { version = "0.34", features = ["http-client", "websocket-client"] }
tendermint-testgen = { version = "0.34" } # Needed for generating (synthetic) light blocks.
parking_lot = { version = "0.12.1" }
ibc = { path = ".", features = ["mocks"] }
41 changes: 40 additions & 1 deletion crates/ibc/src/clients/ics07_tendermint/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,8 @@ pub mod test_util {
use tendermint::block::Header;

use crate::clients::ics07_tendermint::client_state::{AllowUpdate, ClientState};
use crate::clients::ics07_tendermint::error::Error;
use crate::clients::ics07_tendermint::error::{Error as ClientError, Error};
use crate::clients::ics07_tendermint::trust_threshold::TrustThreshold;
use crate::core::ics02_client::height::Height;
use crate::core::ics23_commitment::specs::ProofSpecs;
use crate::core::ics24_host::identifier::ChainId;
Expand Down Expand Up @@ -1180,4 +1181,42 @@ pub mod test_util {
allow_update_after_misbehaviour: false,
}
}

#[derive(typed_builder::TypedBuilder, Debug)]
pub struct ClientStateConfig {
pub chain_id: ChainId,
#[builder(default)]
pub trust_level: TrustThreshold,
#[builder(default = Duration::from_secs(64000))]
pub trusting_period: Duration,
#[builder(default = Duration::from_secs(128000))]
pub unbonding_period: Duration,
#[builder(default = Duration::from_millis(3000))]
max_clock_drift: Duration,
pub latest_height: Height,
#[builder(default)]
pub proof_specs: ProofSpecs,
#[builder(default)]
pub upgrade_path: Vec<String>,
#[builder(default = AllowUpdate { after_expiry: false, after_misbehaviour: false })]
allow_update: AllowUpdate,
}

impl TryFrom<ClientStateConfig> for ClientState {
type Error = ClientError;

fn try_from(config: ClientStateConfig) -> Result<Self, Self::Error> {
ClientState::new(
config.chain_id,
config.trust_level,
config.trusting_period,
config.unbonding_period,
config.max_clock_drift,
config.latest_height,
config.proof_specs,
config.upgrade_path,
config.allow_update,
)
}
}
}
3 changes: 2 additions & 1 deletion crates/ibc/src/clients/ics07_tendermint/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,14 @@ pub mod test_util {
fn from(light_block: SyntheticTmBlock) -> Self {
let SyntheticTmBlock {
trusted_height,
trusted_next_validators,
light_block,
} = light_block;
Self {
signed_header: light_block.signed_header,
validator_set: light_block.validators,
trusted_height,
trusted_next_validator_set: light_block.next_validators,
trusted_next_validator_set: trusted_next_validators,
}
}
}
Expand Down
Loading

0 comments on commit 476937b

Please sign in to comment.