Skip to content

Commit 9b21c33

Browse files
committed
rm AnyClientState and AnyConsensusState deps in TestHost
1 parent 7ff41b3 commit 9b21c33

File tree

8 files changed

+72
-19
lines changed

8 files changed

+72
-19
lines changed

ibc-testkit/src/context.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use ibc::primitives::Timestamp;
2424

2525
use super::testapp::ibc::core::types::{LightClientState, MockIbcStore};
2626
use crate::fixtures::core::context::TestContextConfig;
27-
use crate::hosts::{HostClientState, MockHost, TendermintHost, TestBlock, TestHeader, TestHost};
27+
use crate::hosts::{
28+
HostClientState, HostConsensusState, MockHost, TendermintHost, TestBlock, TestHeader, TestHost,
29+
};
2830
use crate::relayer::error::RelayerError;
2931
use crate::testapp::ibc::clients::{AnyClientState, AnyConsensusState};
3032
use crate::testapp::ibc::core::router::MockRouter;
@@ -36,6 +38,8 @@ pub struct StoreGenericTestContext<S, H>
3638
where
3739
S: ProvableStore + Debug,
3840
H: TestHost,
41+
AnyClientState: From<HostClientState<H>>,
42+
AnyConsensusState: From<HostConsensusState<H>>,
3943
HostClientState<H>: ClientStateValidation<MockIbcStore<S>>,
4044
{
4145
/// The multi store of the context.
@@ -68,6 +72,8 @@ impl<S, H> Default for StoreGenericTestContext<S, H>
6872
where
6973
S: ProvableStore + Debug + Default,
7074
H: TestHost,
75+
AnyClientState: From<HostClientState<H>>,
76+
AnyConsensusState: From<HostConsensusState<H>>,
7177
HostClientState<H>: ClientStateValidation<MockIbcStore<S>>,
7278
{
7379
fn default() -> Self {
@@ -82,6 +88,8 @@ where
8288
S: ProvableStore + Debug,
8389
H: TestHost,
8490
HostClientState<H>: ClientStateValidation<MockIbcStore<S>>,
91+
AnyClientState: From<HostClientState<H>>,
92+
AnyConsensusState: From<HostConsensusState<H>>,
8593
{
8694
/// Returns an immutable reference to the IBC store.
8795
pub fn ibc_store(&self) -> &MockIbcStore<S> {
@@ -170,12 +178,12 @@ where
170178
/// and consensus, and prepares the context for the next block. This includes
171179
/// the latest consensus state and the latest IBC commitment proof.
172180
pub fn begin_block(&mut self) {
173-
let consensus_state = self
174-
.host
175-
.latest_block()
176-
.into_header()
177-
.into_consensus_state()
178-
.into();
181+
let consensus_state = AnyConsensusState::from(
182+
self.host
183+
.latest_block()
184+
.into_header()
185+
.into_consensus_state(),
186+
);
179187

180188
let ibc_commitment_proof = self
181189
.multi_store
@@ -347,11 +355,17 @@ where
347355
) -> Self
348356
where
349357
RH: TestHost,
358+
AnyClientState: From<HostClientState<RH>>,
359+
AnyConsensusState: From<HostConsensusState<RH>>,
350360
{
351-
self = self.with_client_state(client_id, light_client.client_state.into());
361+
self = self.with_client_state(client_id, AnyClientState::from(light_client.client_state));
352362

353363
for (height, consensus_state) in light_client.consensus_states {
354-
self = self.with_consensus_state(client_id, height, consensus_state.into());
364+
self = self.with_consensus_state(
365+
client_id,
366+
height,
367+
AnyConsensusState::from(consensus_state),
368+
);
355369

356370
self.ibc_store
357371
.store_update_meta(
@@ -512,6 +526,8 @@ mod tests {
512526
pub struct Test<H: TestHost>
513527
where
514528
H: TestHost,
529+
AnyClientState: From<HostClientState<H>>,
530+
AnyConsensusState: From<HostConsensusState<H>>,
515531
HostConsensusState<H>: ConsensusState,
516532
HostClientState<H>: ClientStateValidation<DefaultIbcStore>,
517533
{
@@ -522,6 +538,8 @@ mod tests {
522538
fn run_tests<H>(sub_title: &str)
523539
where
524540
H: TestHost,
541+
AnyClientState: From<HostClientState<H>>,
542+
AnyConsensusState: From<HostConsensusState<H>>,
525543
HostConsensusState<H>: ConsensusState,
526544
HostClientState<H>: ClientStateValidation<DefaultIbcStore>,
527545
{

ibc-testkit/src/fixtures/core/context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use ibc::core::primitives::Timestamp;
99
use typed_builder::TypedBuilder;
1010

1111
use crate::context::StoreGenericTestContext;
12-
use crate::hosts::{HostClientState, TestBlock, TestHost};
12+
use crate::hosts::{HostClientState, HostConsensusState, TestBlock, TestHost};
13+
use crate::testapp::ibc::clients::{AnyClientState, AnyConsensusState};
1314
use crate::testapp::ibc::core::router::MockRouter;
1415
use crate::testapp::ibc::core::types::{MockIbcStore, DEFAULT_BLOCK_TIME_SECS};
1516
use crate::utils::year_2023;
@@ -41,6 +42,8 @@ impl<S, H> From<TestContextConfig<H>> for StoreGenericTestContext<S, H>
4142
where
4243
S: ProvableStore + Debug + Default,
4344
H: TestHost,
45+
AnyClientState: From<HostClientState<H>>,
46+
AnyConsensusState: From<HostConsensusState<H>>,
4447
HostClientState<H>: ClientStateValidation<MockIbcStore<S>>,
4548
{
4649
fn from(params: TestContextConfig<H>) -> Self {

ibc-testkit/src/hosts/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use ibc::primitives::proto::Any;
1313

1414
pub use self::mock::MockHost;
1515
pub use self::tendermint::TendermintHost;
16-
use crate::testapp::ibc::clients::{AnyClientState, AnyConsensusState};
1716

1817
pub type HostClientState<H> = <H as TestHost>::ClientState;
1918
pub type HostBlock<H> = <H as TestHost>::Block;
@@ -28,7 +27,7 @@ pub trait TestHost: Default + Debug + Sized {
2827
type Block: TestBlock;
2928

3029
/// The type of client state produced by the host.
31-
type ClientState: Into<AnyClientState> + Debug;
30+
type ClientState: Debug;
3231

3332
/// The type of block parameter to produce a block.
3433
type BlockParams: Debug + Default;
@@ -142,7 +141,7 @@ pub trait TestBlock: Clone + Debug {
142141
/// submitted by relayer from the host blockchain.
143142
pub trait TestHeader: Clone + Debug + Into<Any> {
144143
/// The type of consensus state can be extracted from the header.
145-
type ConsensusState: ConsensusState + Into<AnyConsensusState> + From<Self> + Clone + Debug;
144+
type ConsensusState: ConsensusState + From<Self> + Clone + Debug;
146145

147146
/// The height of the block, as recorded in the header.
148147
fn height(&self) -> Height;

ibc-testkit/src/relayer/context.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@ use ibc::core::host::ValidationContext;
66
use ibc::primitives::Signer;
77

88
use crate::context::TestContext;
9-
use crate::hosts::{HostClientState, TestHost};
9+
use crate::hosts::{HostClientState, HostConsensusState, TestHost};
1010
use crate::relayer::utils::TypedRelayerOps;
11+
use crate::testapp::ibc::clients::{AnyClientState, AnyConsensusState};
1112
use crate::testapp::ibc::core::types::DefaultIbcStore;
1213

1314
/// A relayer context that allows interaction between two [`TestContext`] instances.
1415
pub struct RelayerContext<A, B>
1516
where
1617
A: TestHost,
1718
B: TestHost,
19+
AnyClientState: From<HostClientState<A>>,
20+
AnyConsensusState: From<HostConsensusState<A>>,
21+
AnyClientState: From<HostClientState<B>>,
22+
AnyConsensusState: From<HostConsensusState<B>>,
1823
HostClientState<A>: ClientStateValidation<DefaultIbcStore>,
1924
HostClientState<B>: ClientStateValidation<DefaultIbcStore>,
2025
{
@@ -26,6 +31,10 @@ impl<A, B> RelayerContext<A, B>
2631
where
2732
A: TestHost,
2833
B: TestHost,
34+
AnyClientState: From<HostClientState<A>>,
35+
AnyConsensusState: From<HostConsensusState<A>>,
36+
AnyClientState: From<HostClientState<B>>,
37+
AnyConsensusState: From<HostConsensusState<B>>,
2938
HostClientState<A>: ClientStateValidation<DefaultIbcStore>,
3039
HostClientState<B>: ClientStateValidation<DefaultIbcStore>,
3140
{

ibc-testkit/src/relayer/integration.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use ibc::core::host::types::identifiers::{ChannelId, ConnectionId, PortId};
33

44
use crate::context::TestContext;
55
use crate::fixtures::core::signer::dummy_account_id;
6-
use crate::hosts::{HostClientState, TestHost};
6+
use crate::hosts::{HostClientState, HostConsensusState, TestHost};
77
use crate::relayer::context::RelayerContext;
8+
use crate::testapp::ibc::clients::{AnyClientState, AnyConsensusState};
89
use crate::testapp::ibc::core::types::DefaultIbcStore;
910

1011
/// Integration test for IBC implementation. This test creates clients,
@@ -17,6 +18,10 @@ pub fn ibc_integration_test<A, B>()
1718
where
1819
A: TestHost,
1920
B: TestHost,
21+
AnyClientState: From<HostClientState<A>>,
22+
AnyConsensusState: From<HostConsensusState<A>>,
23+
AnyClientState: From<HostClientState<B>>,
24+
AnyConsensusState: From<HostConsensusState<B>>,
2025
HostClientState<A>: ClientStateValidation<DefaultIbcStore>,
2126
HostClientState<B>: ClientStateValidation<DefaultIbcStore>,
2227
{

ibc-testkit/src/relayer/utils.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ use ibc::primitives::Signer;
3333
use ibc_query::core::context::ProvableContext;
3434

3535
use crate::context::TestContext;
36-
use crate::hosts::{HostClientState, TestBlock, TestHost};
36+
use crate::hosts::{HostClientState, HostConsensusState, TestBlock, TestHost};
37+
use crate::testapp::ibc::clients::{AnyClientState, AnyConsensusState};
3738
use crate::testapp::ibc::core::types::{DefaultIbcStore, LightClientBuilder, LightClientState};
3839

3940
/// Implements IBC relayer functions for a pair of [`TestHost`] implementations: `A` and `B`.
@@ -47,13 +48,21 @@ pub struct TypedRelayerOps<A, B>(PhantomData<A>, PhantomData<B>)
4748
where
4849
A: TestHost,
4950
B: TestHost,
51+
AnyClientState: From<HostClientState<A>>,
52+
AnyConsensusState: From<HostConsensusState<A>>,
53+
AnyClientState: From<HostClientState<B>>,
54+
AnyConsensusState: From<HostConsensusState<B>>,
5055
HostClientState<A>: ClientStateValidation<DefaultIbcStore>,
5156
HostClientState<B>: ClientStateValidation<DefaultIbcStore>;
5257

5358
impl<A, B> TypedRelayerOps<A, B>
5459
where
5560
A: TestHost,
5661
B: TestHost,
62+
AnyClientState: From<HostClientState<A>>,
63+
AnyConsensusState: From<HostConsensusState<A>>,
64+
AnyClientState: From<HostClientState<B>>,
65+
AnyConsensusState: From<HostConsensusState<B>>,
5766
HostClientState<A>: ClientStateValidation<DefaultIbcStore>,
5867
HostClientState<B>: ClientStateValidation<DefaultIbcStore>,
5968
{

ibc-testkit/src/testapp/ibc/core/types.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use typed_builder::TypedBuilder;
3131

3232
use crate::context::{MockStore, TestContext};
3333
use crate::fixtures::core::context::TestContextConfig;
34-
use crate::hosts::{HostClientState, TestBlock, TestHeader, TestHost};
34+
use crate::hosts::{HostClientState, HostConsensusState, TestBlock, TestHeader, TestHost};
3535
use crate::testapp::ibc::clients::mock::header::MockHeader;
3636
use crate::testapp::ibc::clients::{AnyClientState, AnyConsensusState};
3737
pub const DEFAULT_BLOCK_TIME_SECS: u64 = 3;
@@ -452,6 +452,8 @@ pub struct LightClientState<H: TestHost> {
452452
impl<H> Default for LightClientState<H>
453453
where
454454
H: TestHost,
455+
AnyClientState: From<HostClientState<H>>,
456+
AnyConsensusState: From<HostConsensusState<H>>,
455457
HostClientState<H>: ClientStateValidation<DefaultIbcStore>,
456458
{
457459
fn default() -> Self {
@@ -463,6 +465,8 @@ where
463465
impl<H> LightClientState<H>
464466
where
465467
H: TestHost,
468+
AnyClientState: From<HostClientState<H>>,
469+
AnyConsensusState: From<HostConsensusState<H>>,
466470
HostClientState<H>: ClientStateValidation<DefaultIbcStore>,
467471
{
468472
pub fn with_latest_height(height: Height) -> Self {
@@ -478,6 +482,8 @@ where
478482
pub struct LightClientBuilder<'a, H>
479483
where
480484
H: TestHost,
485+
AnyClientState: From<HostClientState<H>>,
486+
AnyConsensusState: From<HostConsensusState<H>>,
481487
HostClientState<H>: ClientStateValidation<DefaultIbcStore>,
482488
{
483489
context: &'a TestContext<H>,
@@ -490,6 +496,8 @@ where
490496
impl<'a, H> From<LightClientBuilder<'a, H>> for LightClientState<H>
491497
where
492498
H: TestHost,
499+
AnyClientState: From<HostClientState<H>>,
500+
AnyConsensusState: From<HostConsensusState<H>>,
493501
HostClientState<H>: ClientStateValidation<DefaultIbcStore>,
494502
{
495503
fn from(builder: LightClientBuilder<'a, H>) -> Self {

tests-integration/tests/core/ics02_client/update_client.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ use ibc_testkit::fixtures::core::context::TestContextConfig;
3030
use ibc_testkit::fixtures::core::signer::dummy_account_id;
3131
use ibc_testkit::hosts::tendermint::BlockParams;
3232
use ibc_testkit::hosts::{
33-
HostClientState, MockHost, TendermintHost, TestBlock, TestHeader, TestHost,
33+
HostClientState, HostConsensusState, MockHost, TendermintHost, TestBlock, TestHeader, TestHost,
3434
};
3535
use ibc_testkit::relayer::error::RelayerError;
3636
use ibc_testkit::testapp::ibc::clients::mock::client_state::{
3737
client_type as mock_client_type, MockClientState,
3838
};
3939
use ibc_testkit::testapp::ibc::clients::mock::header::MockHeader;
4040
use ibc_testkit::testapp::ibc::clients::mock::misbehaviour::Misbehaviour as MockMisbehaviour;
41-
use ibc_testkit::testapp::ibc::clients::AnyConsensusState;
41+
use ibc_testkit::testapp::ibc::clients::{AnyClientState, AnyConsensusState};
4242
use ibc_testkit::testapp::ibc::core::router::MockRouter;
4343
use ibc_testkit::testapp::ibc::core::types::{
4444
DefaultIbcStore, LightClientBuilder, LightClientState, MockIbcStore,
@@ -1530,6 +1530,8 @@ pub(crate) fn build_client_update_datagram<H: TestHeader, Dst: TestHost>(
15301530
src_header: &H,
15311531
) -> Result<ClientMsg, RelayerError>
15321532
where
1533+
AnyClientState: From<HostClientState<Dst>>,
1534+
AnyConsensusState: From<HostConsensusState<Dst>>,
15331535
HostClientState<Dst>: ClientStateValidation<DefaultIbcStore>,
15341536
{
15351537
// Check if client for ibc0 on ibc1 has been updated to latest height:

0 commit comments

Comments
 (0)