-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for connection and channel workers
- Loading branch information
1 parent
490b8df
commit 7c1803a
Showing
13 changed files
with
296 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use ibc::core::ics04_channel::channel::{ChannelEnd, Order}; | ||
use ibc::Height; | ||
use ibc_relayer::chain::handle::ChainHandle; | ||
use ibc_relayer::channel::{extract_channel_id, Channel, ChannelSide}; | ||
|
||
use crate::error::Error; | ||
use crate::types::id::{ | ||
TaggedChannelId, TaggedChannelIdRef, TaggedClientIdRef, TaggedConnectionIdRef, TaggedPortIdRef, | ||
}; | ||
use crate::types::tagged::DualTagged; | ||
|
||
pub trait TaggedChannelEndExt<ChainA, ChainB> { | ||
fn tagged_counterparty_channel_id(&self) -> Option<TaggedChannelId<ChainB, ChainA>>; | ||
} | ||
|
||
impl<ChainA, ChainB> TaggedChannelEndExt<ChainA, ChainB> | ||
for DualTagged<ChainA, ChainB, ChannelEnd> | ||
{ | ||
fn tagged_counterparty_channel_id(&self) -> Option<TaggedChannelId<ChainB, ChainA>> { | ||
self.contra_map(|c| c.counterparty().channel_id.clone()) | ||
.transpose() | ||
} | ||
} | ||
|
||
pub fn init_channel<ChainA: ChainHandle, ChainB: ChainHandle>( | ||
handle_a: &ChainA, | ||
handle_b: &ChainB, | ||
client_id_a: &TaggedClientIdRef<ChainA, ChainB>, | ||
client_id_b: &TaggedClientIdRef<ChainB, ChainA>, | ||
connection_id_a: &TaggedConnectionIdRef<ChainA, ChainB>, | ||
connection_id_b: &TaggedConnectionIdRef<ChainB, ChainA>, | ||
src_port_id: &TaggedPortIdRef<ChainA, ChainB>, | ||
dst_port_id: &TaggedPortIdRef<ChainB, ChainA>, | ||
) -> Result<TaggedChannelId<ChainB, ChainA>, Error> { | ||
let channel = Channel { | ||
connection_delay: Default::default(), | ||
ordering: Order::Unordered, | ||
a_side: ChannelSide::new( | ||
handle_a.clone(), | ||
client_id_a.cloned_value(), | ||
connection_id_a.cloned_value(), | ||
src_port_id.cloned_value(), | ||
None, | ||
None, | ||
), | ||
b_side: ChannelSide::new( | ||
handle_b.clone(), | ||
client_id_b.cloned_value(), | ||
connection_id_b.cloned_value(), | ||
dst_port_id.cloned_value(), | ||
None, | ||
None, | ||
), | ||
}; | ||
|
||
let event = channel.build_chan_open_init_and_send()?; | ||
|
||
let channel_id = extract_channel_id(&event)?; | ||
|
||
Ok(DualTagged::new(channel_id.clone())) | ||
} | ||
|
||
pub fn query_channel_end<ChainA: ChainHandle, ChainB>( | ||
handle: &ChainA, | ||
channel_id: &TaggedChannelIdRef<ChainA, ChainB>, | ||
port_id: &TaggedPortIdRef<ChainA, ChainB>, | ||
) -> Result<DualTagged<ChainA, ChainB, ChannelEnd>, Error> { | ||
let channel_end = handle.query_channel(port_id.value(), channel_id.value(), Height::zero())?; | ||
|
||
Ok(DualTagged::new(channel_end)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
*/ | ||
|
||
pub mod chain; | ||
pub mod channel; | ||
pub mod connection; | ||
pub mod foreign_client; | ||
pub mod transfer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
*/ | ||
|
||
pub mod memo; | ||
pub mod supervisor; | ||
pub mod transfer; | ||
|
||
#[cfg(any(doc, feature = "manual"))] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
use core::time::Duration; | ||
use ibc::core::ics03_connection::connection::State as ConnectionState; | ||
use ibc::core::ics04_channel::channel::State as ChannelState; | ||
use ibc_relayer::config::{self, Config, ModeConfig}; | ||
|
||
use crate::prelude::*; | ||
pub use crate::relayer::channel::{init_channel, query_channel_end}; | ||
pub use crate::relayer::connection::{init_connection, query_connection_end}; | ||
|
||
#[test] | ||
fn test_supervisor() -> Result<(), Error> { | ||
run_binary_chain_test(&SupervisorTest) | ||
} | ||
|
||
struct SupervisorTest; | ||
|
||
impl TestOverrides for SupervisorTest { | ||
fn modify_relayer_config(&self, config: &mut Config) { | ||
config.mode = ModeConfig { | ||
clients: config::Clients { | ||
enabled: true, | ||
refresh: true, | ||
misbehaviour: true, | ||
}, | ||
connections: config::Connections { enabled: true }, | ||
channels: config::Channels { enabled: true }, | ||
packets: config::Packets { | ||
enabled: true, | ||
clear_interval: 102 | ||
clear_on_start: true, | ||
filter: false, | ||
tx_confirmation: true, | ||
}, | ||
}; | ||
} | ||
} | ||
|
||
impl BinaryChainTest for SupervisorTest { | ||
fn run<ChainA: ChainHandle, ChainB: ChainHandle>( | ||
&self, | ||
_config: &TestConfig, | ||
chains: ConnectedChains<ChainA, ChainB>, | ||
) -> Result<(), Error> { | ||
let connection_id_b = init_connection( | ||
&chains.handle_a, | ||
&chains.handle_b, | ||
&chains.client_b_to_a.tagged_client_id(), | ||
&chains.client_a_to_b.tagged_client_id(), | ||
)?; | ||
|
||
let connection_id_a = assert_eventually_succeed( | ||
"connection should eventually open", | ||
|| { | ||
let connection_end_b = | ||
query_connection_end(&chains.handle_b, &connection_id_b.as_ref())?; | ||
|
||
if !connection_end_b | ||
.value() | ||
.state_matches(&ConnectionState::Open) | ||
{ | ||
return Err(eyre!("expeted connection end A to be in open state")); | ||
} | ||
|
||
let connection_id_a = connection_end_b | ||
.tagged_counterparty_connection_id() | ||
.ok_or_else(|| { | ||
eyre!("expected counterparty connection id to present on open connection") | ||
})?; | ||
|
||
let connection_end_a = | ||
query_connection_end(&chains.handle_a, &connection_id_a.as_ref())?; | ||
|
||
if !connection_end_a | ||
.value() | ||
.state_matches(&ConnectionState::Open) | ||
{ | ||
return Err(eyre!("expeted connection end B to be in open state")); | ||
} | ||
|
||
Ok(connection_id_a) | ||
}, | ||
20, | ||
Duration::from_secs(1), | ||
)?; | ||
|
||
let port_a = tagged_transfer_port(); | ||
let port_b = tagged_transfer_port(); | ||
|
||
let channel_id_b = init_channel( | ||
&chains.handle_a, | ||
&chains.handle_b, | ||
&chains.client_id_a(), | ||
&chains.client_id_b(), | ||
&connection_id_a.as_ref(), | ||
&connection_id_b.as_ref(), | ||
&port_a.as_ref(), | ||
&port_b.as_ref(), | ||
)?; | ||
|
||
assert_eventually_succeed( | ||
"channel should eventually open", | ||
|| { | ||
let channel_end_b = | ||
query_channel_end(&chains.handle_b, &channel_id_b.as_ref(), &port_b.as_ref())?; | ||
|
||
if !channel_end_b.value().state_matches(&ChannelState::Open) { | ||
return Err(eyre!("expeted channel end A to be in open state")); | ||
} | ||
|
||
let channel_id_a = | ||
channel_end_b | ||
.tagged_counterparty_channel_id() | ||
.ok_or_else(|| { | ||
eyre!("expected counterparty channel id to present on open channel") | ||
})?; | ||
|
||
let channel_end_a = | ||
query_channel_end(&chains.handle_a, &channel_id_a.as_ref(), &port_a.as_ref())?; | ||
|
||
if !channel_end_a.value().state_matches(&ChannelState::Open) { | ||
return Err(eyre!("expeted channel end B to be in open state")); | ||
} | ||
|
||
Ok(channel_id_a) | ||
}, | ||
20, | ||
Duration::from_secs(1), | ||
)?; | ||
|
||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.