Skip to content

Commit 949bac7

Browse files
committed
generalize Store in exports
1 parent 9203695 commit 949bac7

22 files changed

+292
-204
lines changed

ibc-testkit/src/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ where
316316
&self,
317317
mut consensus_heights: Vec<Height>,
318318
client_params: &H::LightClientParams,
319-
) -> LightClientState<H> {
319+
) -> LightClientState<H, S> {
320320
let client_height = if let Some(&height) = consensus_heights.last() {
321321
height
322322
} else {
@@ -344,14 +344,15 @@ where
344344
LightClientState {
345345
client_state,
346346
consensus_states,
347+
_store: core::marker::PhantomData,
347348
}
348349
}
349350

350351
/// Bootstrap a light client with ClientState and its ConsensusState(s) to this context.
351352
pub fn with_light_client<RH>(
352353
mut self,
353354
client_id: &ClientId,
354-
light_client: LightClientState<RH>,
355+
light_client: LightClientState<RH, S>,
355356
) -> Self
356357
where
357358
RH: TestHost,

ibc-testkit/src/relayer/context.rs

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,88 @@
1+
use core::fmt::Debug;
2+
3+
use basecoin_store::context::ProvableStore;
14
use ibc::core::channel::types::packet::Packet;
25
use ibc::core::client::context::client_state::ClientStateValidation;
36
use ibc::core::host::types::identifiers::{ChannelId, ClientId, ConnectionId, PortId};
47
use ibc::core::host::types::path::ChannelEndPath;
58
use ibc::core::host::ValidationContext;
69
use ibc::primitives::Signer;
710

8-
use crate::context::TestContext;
11+
use crate::context::StoreGenericTestContext;
912
use crate::hosts::{HostClientState, HostConsensusState, TestHost};
1013
use crate::relayer::utils::TypedRelayerOps;
1114
use crate::testapp::ibc::clients::{AnyClientState, AnyConsensusState};
12-
use crate::testapp::ibc::core::types::DefaultIbcStore;
15+
use crate::testapp::ibc::core::types::MockIbcStore;
1316

1417
/// A relayer context that allows interaction between two [`TestContext`] instances.
15-
pub struct RelayerContext<A, B>
18+
pub struct RelayerContext<A, B, S>
1619
where
1720
A: TestHost,
1821
B: TestHost,
22+
S: ProvableStore + Debug,
1923
AnyClientState: From<HostClientState<A>>,
2024
AnyConsensusState: From<HostConsensusState<A>>,
2125
AnyClientState: From<HostClientState<B>>,
2226
AnyConsensusState: From<HostConsensusState<B>>,
23-
HostClientState<A>: ClientStateValidation<DefaultIbcStore>,
24-
HostClientState<B>: ClientStateValidation<DefaultIbcStore>,
27+
HostClientState<A>: ClientStateValidation<MockIbcStore<S, AnyClientState, AnyConsensusState>>,
28+
HostClientState<B>: ClientStateValidation<MockIbcStore<S, AnyClientState, AnyConsensusState>>,
2529
{
26-
ctx_a: TestContext<A>,
27-
ctx_b: TestContext<B>,
30+
ctx_a: StoreGenericTestContext<S, A>,
31+
ctx_b: StoreGenericTestContext<S, B>,
2832
}
2933

30-
impl<A, B> RelayerContext<A, B>
34+
impl<A, B, S> RelayerContext<A, B, S>
3135
where
3236
A: TestHost,
3337
B: TestHost,
38+
S: ProvableStore + Debug,
3439
AnyClientState: From<HostClientState<A>>,
3540
AnyConsensusState: From<HostConsensusState<A>>,
3641
AnyClientState: From<HostClientState<B>>,
3742
AnyConsensusState: From<HostConsensusState<B>>,
38-
HostClientState<A>: ClientStateValidation<DefaultIbcStore>,
39-
HostClientState<B>: ClientStateValidation<DefaultIbcStore>,
43+
HostClientState<A>: ClientStateValidation<MockIbcStore<S, AnyClientState, AnyConsensusState>>,
44+
HostClientState<B>: ClientStateValidation<MockIbcStore<S, AnyClientState, AnyConsensusState>>,
4045
{
4146
/// Creates a new relayer context with the given [`TestContext`] instances.
42-
pub fn new(ctx_a: TestContext<A>, ctx_b: TestContext<B>) -> Self {
47+
pub fn new(ctx_a: StoreGenericTestContext<S, A>, ctx_b: StoreGenericTestContext<S, B>) -> Self {
4348
Self { ctx_a, ctx_b }
4449
}
4550

4651
/// Returns an immutable reference to the first context.
47-
pub fn get_ctx_a(&self) -> &TestContext<A> {
52+
pub fn get_ctx_a(&self) -> &StoreGenericTestContext<S, A> {
4853
&self.ctx_a
4954
}
5055

5156
/// Returns an immutable reference to the second context.
52-
pub fn get_ctx_b(&self) -> &TestContext<B> {
57+
pub fn get_ctx_b(&self) -> &StoreGenericTestContext<S, B> {
5358
&self.ctx_b
5459
}
5560

5661
/// Returns a mutable reference to the first context.
57-
pub fn get_ctx_a_mut(&mut self) -> &mut TestContext<A> {
62+
pub fn get_ctx_a_mut(&mut self) -> &mut StoreGenericTestContext<S, A> {
5863
&mut self.ctx_a
5964
}
6065

6166
/// Returns a mutable reference to the second context.
62-
pub fn get_ctx_b_mut(&mut self) -> &mut TestContext<B> {
67+
pub fn get_ctx_b_mut(&mut self) -> &mut StoreGenericTestContext<S, B> {
6368
&mut self.ctx_b
6469
}
6570

6671
/// Creates a light client of second context on the first context.
6772
/// Returns the client identifier of the created client.
6873
pub fn create_client_on_a(&mut self, signer: Signer) -> ClientId {
69-
TypedRelayerOps::<A, B>::create_client_on_a(&mut self.ctx_a, &self.ctx_b, signer)
74+
TypedRelayerOps::<A, B, S>::create_client_on_a(&mut self.ctx_a, &self.ctx_b, signer)
7075
}
7176

7277
/// Creates a light client of first context on the second context.
7378
/// Returns the client identifier of the created client.
7479
pub fn create_client_on_b(&mut self, signer: Signer) -> ClientId {
75-
TypedRelayerOps::<B, A>::create_client_on_a(&mut self.ctx_b, &self.ctx_a, signer)
80+
TypedRelayerOps::<B, A, S>::create_client_on_a(&mut self.ctx_b, &self.ctx_a, signer)
7681
}
7782

7883
/// Updates the client on the first context with the latest header of the second context.
7984
pub fn update_client_on_a_with_sync(&mut self, client_id_on_a: ClientId, signer: Signer) {
80-
TypedRelayerOps::<A, B>::update_client_on_a_with_sync(
85+
TypedRelayerOps::<A, B, S>::update_client_on_a_with_sync(
8186
&mut self.ctx_a,
8287
&mut self.ctx_b,
8388
client_id_on_a,
@@ -87,7 +92,7 @@ where
8792

8893
/// Updates the client on the second context with the latest header of the first context.
8994
pub fn update_client_on_b_with_sync(&mut self, client_id_on_b: ClientId, signer: Signer) {
90-
TypedRelayerOps::<B, A>::update_client_on_a_with_sync(
95+
TypedRelayerOps::<B, A, S>::update_client_on_a_with_sync(
9196
&mut self.ctx_b,
9297
&mut self.ctx_a,
9398
client_id_on_b,
@@ -103,7 +108,7 @@ where
103108
client_id_on_b: ClientId,
104109
signer: Signer,
105110
) -> (ConnectionId, ConnectionId) {
106-
TypedRelayerOps::<A, B>::create_connection_on_a(
111+
TypedRelayerOps::<A, B, S>::create_connection_on_a(
107112
&mut self.ctx_a,
108113
&mut self.ctx_b,
109114
client_id_on_a,
@@ -120,7 +125,7 @@ where
120125
client_id_on_a: ClientId,
121126
signer: Signer,
122127
) -> (ConnectionId, ConnectionId) {
123-
TypedRelayerOps::<B, A>::create_connection_on_a(
128+
TypedRelayerOps::<B, A, S>::create_connection_on_a(
124129
&mut self.ctx_b,
125130
&mut self.ctx_a,
126131
client_id_on_b,
@@ -155,7 +160,7 @@ where
155160
.client_id()
156161
.clone();
157162

158-
TypedRelayerOps::<A, B>::create_channel_on_a(
163+
TypedRelayerOps::<A, B, S>::create_channel_on_a(
159164
&mut self.ctx_a,
160165
&mut self.ctx_b,
161166
client_id_on_a,
@@ -194,7 +199,7 @@ where
194199
.client_id()
195200
.clone();
196201

197-
TypedRelayerOps::<B, A>::create_channel_on_a(
202+
TypedRelayerOps::<B, A, S>::create_channel_on_a(
198203
&mut self.ctx_b,
199204
&mut self.ctx_a,
200205
client_id_on_b,
@@ -248,7 +253,7 @@ where
248253
.client_id()
249254
.clone();
250255

251-
TypedRelayerOps::<A, B>::close_channel_on_a(
256+
TypedRelayerOps::<A, B, S>::close_channel_on_a(
252257
&mut self.ctx_a,
253258
&mut self.ctx_b,
254259
client_id_on_a,
@@ -302,7 +307,7 @@ where
302307
.client_id()
303308
.clone();
304309

305-
TypedRelayerOps::<B, A>::close_channel_on_a(
310+
TypedRelayerOps::<B, A, S>::close_channel_on_a(
306311
&mut self.ctx_b,
307312
&mut self.ctx_a,
308313
client_id_on_b,
@@ -358,7 +363,7 @@ where
358363
.client_id()
359364
.clone();
360365

361-
TypedRelayerOps::<A, B>::submit_packet_on_b(
366+
TypedRelayerOps::<A, B, S>::submit_packet_on_b(
362367
&mut self.ctx_a,
363368
&mut self.ctx_b,
364369
packet,
@@ -411,7 +416,7 @@ where
411416
.client_id()
412417
.clone();
413418

414-
TypedRelayerOps::<A, B>::timeout_packet_from_a(
419+
TypedRelayerOps::<A, B, S>::timeout_packet_from_a(
415420
&mut self.ctx_a,
416421
&mut self.ctx_b,
417422
packet,
@@ -464,7 +469,7 @@ where
464469
.client_id()
465470
.clone();
466471

467-
TypedRelayerOps::<A, B>::timeout_packet_from_a_on_channel_close(
472+
TypedRelayerOps::<A, B, S>::timeout_packet_from_a_on_channel_close(
468473
&mut self.ctx_a,
469474
&mut self.ctx_b,
470475
packet,

ibc-testkit/src/relayer/integration.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
1+
use core::fmt::Debug;
2+
3+
use basecoin_store::context::ProvableStore;
14
use ibc::core::client::context::client_state::ClientStateValidation;
25
use ibc::core::host::types::identifiers::{ChannelId, ConnectionId, PortId};
36

4-
use crate::context::TestContext;
7+
use crate::context::StoreGenericTestContext;
58
use crate::fixtures::core::signer::dummy_account_id;
69
use crate::hosts::{HostClientState, HostConsensusState, TestHost};
710
use crate::relayer::context::RelayerContext;
811
use crate::testapp::ibc::clients::{AnyClientState, AnyConsensusState};
9-
use crate::testapp::ibc::core::types::DefaultIbcStore;
12+
use crate::testapp::ibc::core::types::MockIbcStore;
1013

1114
/// Integration test for IBC implementation. This test creates clients,
1215
/// connections, channels between two [`TestHost`]s.
1316
///
1417
/// If `serde` feature is enabled, this also exercises packet relay between [`TestHost`]s. This uses
1518
/// [`DummyTransferModule`](crate::testapp::ibc::applications::transfer::types::DummyTransferModule)
1619
/// to simulate the transfer of tokens between two contexts.
17-
pub fn ibc_integration_test<A, B>()
20+
pub fn ibc_integration_test<A, B, S>()
1821
where
1922
A: TestHost,
2023
B: TestHost,
24+
S: ProvableStore + Debug + Default,
2125
AnyClientState: From<HostClientState<A>>,
2226
AnyConsensusState: From<HostConsensusState<A>>,
2327
AnyClientState: From<HostClientState<B>>,
2428
AnyConsensusState: From<HostConsensusState<B>>,
25-
HostClientState<A>: ClientStateValidation<DefaultIbcStore>,
26-
HostClientState<B>: ClientStateValidation<DefaultIbcStore>,
29+
HostClientState<A>: ClientStateValidation<MockIbcStore<S, AnyClientState, AnyConsensusState>>,
30+
HostClientState<B>: ClientStateValidation<MockIbcStore<S, AnyClientState, AnyConsensusState>>,
2731
{
28-
let ctx_a = TestContext::<A>::default();
29-
let ctx_b = TestContext::<B>::default();
32+
let ctx_a = StoreGenericTestContext::<S, A>::default();
33+
let ctx_b = StoreGenericTestContext::<S, B>::default();
3034

3135
let signer = dummy_account_id();
3236

@@ -170,14 +174,15 @@ where
170174
#[cfg(test)]
171175
mod tests {
172176
use super::*;
177+
use crate::context::MockStore;
173178
use crate::hosts::{MockHost, TendermintHost};
174179

175180
// tests among all the `TestHost` implementations
176181
#[test]
177182
fn ibc_integration_test_for_all_pairs() {
178-
ibc_integration_test::<MockHost, MockHost>();
179-
ibc_integration_test::<MockHost, TendermintHost>();
180-
ibc_integration_test::<TendermintHost, MockHost>();
181-
ibc_integration_test::<TendermintHost, TendermintHost>();
183+
ibc_integration_test::<MockHost, MockHost, MockStore>();
184+
ibc_integration_test::<MockHost, TendermintHost, MockStore>();
185+
ibc_integration_test::<TendermintHost, MockHost, MockStore>();
186+
ibc_integration_test::<TendermintHost, TendermintHost, MockStore>();
182187
}
183188
}

0 commit comments

Comments
 (0)