Skip to content

Commit

Permalink
Merge pull request #292 from synapseweb3/fix-ibc-test-channel-error
Browse files Browse the repository at this point in the history
bug: fix ibc test channel error
  • Loading branch information
Flouse authored Aug 14, 2023
2 parents 21b9026 + 4b9c445 commit dd8863b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
15 changes: 12 additions & 3 deletions tools/ckb4ibc-test/src/framework/utils/ckb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use ckb_types::packed::Script;
use ckb_types::prelude::{Builder, Entity, Pack};
use ckb_types::{h256, H256};
use futures::Future;
use ibc_test_framework::prelude::Wallet;
use ibc_test_framework::prelude::{ChannelId, Wallet};
use ibc_test_framework::types::process::ChildProcess;
use relayer::chain::ckb::prelude::CkbReader;
use relayer::chain::ckb4ibc::extractor::{
Expand Down Expand Up @@ -338,7 +338,16 @@ pub fn fetch_ibc_connections(port: u32) -> IbcConnections {
}
}

pub fn fetch_ibc_channel_cell(port: u32, port_id: [u8; 32]) -> IbcChannel {
fn channel_id_to_u16(channel_id: &ChannelId) -> u16 {
let channel_str = channel_id.to_string();
let mut parts = channel_str.split('-');
assert_eq!(parts.next().unwrap(), "channel", "expect prefix channel");
let channel_id_num = parts.next().unwrap().parse().unwrap();
assert!(parts.next().is_none(), "unknown parts in the string");
channel_id_num
}

pub fn fetch_ibc_channel_cell(port: u32, port_id: [u8; 32], channel_id: &ChannelId) -> IbcChannel {
let rpc_client = get_client(port);
let mut loop_count = 0;
loop {
Expand All @@ -350,7 +359,7 @@ pub fn fetch_ibc_channel_cell(port: u32, port_id: [u8; 32]) -> IbcChannel {
ChannelArgs {
client_id: CLIENT_TYPE_ARGS.into(),
open: true,
channel_id: 0,
channel_id: channel_id_to_u16(channel_id),
port_id,
}
.to_args()
Expand Down
27 changes: 9 additions & 18 deletions tools/ckb4ibc-test/src/tests/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,7 @@ impl BinaryChannelTest for CKB4IbcChannelTest {
let a_connection = fetch_ibc_connections(rpc_port_a);
let b_connection = fetch_ibc_connections(rpc_port_b);

// FIXME @jjy
// node_a contains exactly 1 connection, but node_b contains two connections.
// the reason is a and b both initialize connection to counter party at the test beginning.
// node a's init connection has been correctly handled,
// but node b's init connection is failed, then b receives connection from a,
// in `convert_conn_open_init_to_tx` function, the second connection is appended to vector,
// but the first one is still exist.
// IBC test-framework will open a dummy connection on chain B before the test started, so chain B has two connections
if !check_ibc_connection(a_connection, 1) || !check_ibc_connection(b_connection, 2) {
panic!("create connection failed");
}
Expand All @@ -67,18 +61,15 @@ impl BinaryChannelTest for CKB4IbcChannelTest {
let port_a = H256::from_str(channel.port_a.into_value().to_string().as_str())
.unwrap()
.into();
// let port_b = H256::from_str(channel.port_b.into_value().to_string().as_str())
// .unwrap()
// .into();
let a_channel = fetch_ibc_channel_cell(rpc_port_a, port_a);
// FIXME @jjy this function panick because can't find a channel cell.
// notice the changes here, after we switched to ibc test framework
// the channel is opened both from a side and b side, seems this behavior caused a hidden bug
// let b_channel = fetch_ibc_channel_cell(rpc_port_b, port_b);
let port_b = H256::from_str(channel.port_b.into_value().to_string().as_str())
.unwrap()
.into();
let a_channel =
fetch_ibc_channel_cell(rpc_port_a, port_a, &channel.channel_id_a.into_value());
let b_channel =
fetch_ibc_channel_cell(rpc_port_b, port_b, &channel.channel_id_b.into_value());

if !check_channel(&a_channel)
// || !check_channel(&b_channel)
{
if !check_channel(&a_channel) || !check_channel(&b_channel) {
panic!("create channel failed")
}

Expand Down

0 comments on commit dd8863b

Please sign in to comment.