Skip to content

Commit

Permalink
chore: make ckb-ics dep up-to-date
Browse files Browse the repository at this point in the history
  • Loading branch information
liyukun committed Aug 15, 2023
1 parent cfb1e3a commit 4b41e2f
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 37 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/ckb4ibc-test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Ckb4ibc
on:
pull_request:
path:
paths:
- .github/workflows/ckb4ibc-test.yaml
- Cargo.toml
- Cargo.lock
Expand All @@ -21,9 +21,8 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true


jobs:
integration-test:
ckb4ibc-test:
runs-on: ubuntu-20.04
timeout-minutes: 60
steps:
Expand All @@ -48,10 +47,10 @@ jobs:
with:
python-version: '3.10'
- uses: actions-rs/cargo@v1
- env:
CHAIN_COMMAND_PATHS=ckb
ACCOUNT_PREFIXES=ckb
RUST_LOG=info
env:
CHAIN_COMMAND_PATHS: ckb
ACCOUNT_PREFIXES: ckb
RUST_LOG: info
with:
command: test
args: -p ckb4ibc-test --all-features -- --nocapture
2 changes: 1 addition & 1 deletion .github/workflows/forcrerelay-test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Forcerelay
on:
pull_request:
path:
paths:
- .github/workflows/forcerelay-test.yaml
- Cargo.toml
- Cargo.lock
Expand Down
4 changes: 2 additions & 2 deletions crates/relayer/src/chain/ckb4ibc/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use ibc_relayer_types::core::ics04_channel::version::Version as ChanVersion;
use ibc_relayer_types::core::ics23_commitment::commitment::CommitmentPrefix;
use ibc_relayer_types::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId};

use super::utils::{generate_connection_id, get_channel_id};
use super::utils::{generate_channel_id, generate_connection_id};

pub fn extract_channel_end_from_tx(
tx: TransactionView,
Expand Down Expand Up @@ -192,7 +192,7 @@ fn convert_channel_end(ckb_channel_end: CkbIbcChannel) -> Result<IdentifiedChann

let port_id =
PortId::from_str(&ckb_channel_end.port_id).map_err(|_| Error::convert_channel_end())?;
let channel_id = get_channel_id(ckb_channel_end.number);
let channel_id = generate_channel_id(ckb_channel_end.number);

let result = IdentifiedChannelEnd {
port_id,
Expand Down
6 changes: 3 additions & 3 deletions crates/relayer/src/chain/ckb4ibc/message/chan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::str::FromStr;
use super::{CkbTxInfo, MsgToTxConverter};
use crate::chain::ckb4ibc::utils::{
convert_port_id_to_array, convert_proof, extract_client_id_by_connection_id,
get_channel_capacity, get_channel_id, get_channel_idx, get_client_id_from_channel,
generate_channel_id, get_channel_capacity, get_channel_idx, get_client_id_from_channel,
get_client_outpoint, get_connection_capacity, get_connection_lock_script, get_encoded_object,
get_packet_capacity,
};
Expand Down Expand Up @@ -133,7 +133,7 @@ pub fn convert_chan_open_init_to_tx<C: MsgToTxConverter>(
.build();
let event = IbcEvent::OpenInitChannel(OpenInit {
port_id: msg.port_id,
channel_id: Some(get_channel_id(next_channel_num)),
channel_id: Some(generate_channel_id(next_channel_num)),
connection_id: msg.channel.connection_hops[0].clone(),
counterparty_port_id: msg.channel.remote.port_id,
counterparty_channel_id: msg.channel.remote.channel_id,
Expand Down Expand Up @@ -234,7 +234,7 @@ pub fn convert_chan_open_try_to_tx<C: MsgToTxConverter>(
.build();
let event = IbcEvent::OpenTryChannel(OpenTry {
port_id: msg.port_id,
channel_id: Some(get_channel_id(next_channel_num)),
channel_id: Some(generate_channel_id(next_channel_num)),
connection_id: msg.channel.connection_hops[0].clone(),
counterparty_port_id: msg.channel.remote.port_id,
counterparty_channel_id: msg.channel.remote.channel_id,
Expand Down
12 changes: 5 additions & 7 deletions crates/relayer/src/chain/ckb4ibc/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,14 @@ impl Ckb4IbcEventMonitor {

async fn fetch_connection_events(&self) -> Result<EventBatch> {
let connection_code_hash = get_script_hash(&self.config.connection_type_args);
let client_id = self
.config
.lc_client_type_args(self.counterparty_client_type)
.map_err(|e| Error::collect_events_failed(e.to_string()))?;
let script = Script::new_builder()
.code_hash(connection_code_hash)
.hash_type(ScriptHashType::Type.into())
.args(
self.config
.lc_client_type_args(self.counterparty_client_type)
.unwrap()
.as_slice()
.pack(),
)
.args(client_id.as_slice().pack())
.build();
let key = get_search_key(script);
let (ibc_connection_cell, tx_hash) = self
Expand Down
8 changes: 4 additions & 4 deletions crates/relayer/src/chain/ckb4ibc/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ pub fn get_script_hash(type_args: &H256) -> Byte32 {
script.calc_script_hash()
}

pub fn get_channel_id(idx: u16) -> ChannelId {
ChannelId::from_str(&format!("{CHANNEL_ID_PREFIX}-{idx}")).unwrap()
}

pub fn get_channel_idx(id: &ChannelId) -> Result<u16, Error> {
let s = id.as_str();
let result = s
Expand All @@ -95,6 +91,10 @@ pub fn generate_connection_id(idx: u16, client_id: &str) -> ConnectionId {
ConnectionId::from_str(&format!("{}{idx}", get_connection_id_prefix(client_id))).unwrap()
}

pub fn generate_channel_id(idx: u16) -> ChannelId {
ChannelId::from_str(&format!("{CHANNEL_ID_PREFIX}{idx}")).unwrap()
}

pub fn get_connection_index_by_id(id: &ConnectionId) -> Result<u16, Error> {
let s = id.as_str();
let result = s
Expand Down
File renamed without changes.
File renamed without changes.
18 changes: 7 additions & 11 deletions tools/ckb4ibc-test/src/framework/utils/ckb.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::consts::{CHANNEL_CODE_HASH, CLIENT_TYPE_ARGS, CONNECTION_CODE_HASH};
use crate::generator::GENESIS_TXHASH;
use crate::rpc_client::RpcClient;

use anyhow::Result;
Expand All @@ -13,7 +14,7 @@ use ckb_sdk::*;
use ckb_types::core::ScriptHashType;
use ckb_types::packed::Script;
use ckb_types::prelude::{Builder, Entity, Pack};
use ckb_types::{h256, H256};
use ckb_types::H256;
use futures::Future;
use ibc_test_framework::prelude::{ChannelId, Wallet};
use ibc_test_framework::types::process::ChildProcess;
Expand Down Expand Up @@ -173,9 +174,7 @@ pub fn prepare_ckb_chain(
fs::write(dev_spec_path, content).unwrap();
}

if port != 8114 {
modify_ckb_config_port(Path::new(ckb_path), port).unwrap();
}
modify_ckb_config_port(Path::new(ckb_path), port).unwrap();

let ckb_process = ChildProcess::new(
Command::new("ckb")
Expand All @@ -200,17 +199,14 @@ pub fn prepare_ckb_chain(
);

// check transaction in genesis
check_and_wait_ckb_transaction(
h256!("0x227de871ce6ab120a67960f831b04148bf79b4e56349dde7a8001f93191736ed"),
port,
);
check_and_wait_ckb_transaction(GENESIS_TXHASH, port);

let output = send_tx(
fs::read_to_string("txs/deploy_conn_chan.json").unwrap(),
port,
)
.unwrap();
print!("deploying conn and channel: {output}");
println!("deploying conn and channel: {output}");

// check `txs/deploy_conn_chan.json`
check_and_wait_ckb_transaction(output.result, port);
Expand All @@ -220,7 +216,7 @@ pub fn prepare_ckb_chain(
port,
)
.unwrap();
print!("deploying packet and metadata: {output}");
println!("deploying packet and metadata: {output}");

// check `txs/deploy_packet_metadata.json`
check_and_wait_ckb_transaction(output.result, port);
Expand All @@ -230,7 +226,7 @@ pub fn prepare_ckb_chain(
port,
)
.unwrap();
print!("deploying create connection: {output}");
println!("deploying create connection: {output}");

// check `txs/create_connection.json`
check_and_wait_ckb_transaction(output.result, port);
Expand Down
4 changes: 2 additions & 2 deletions tools/ckb4ibc-test/src/generator/deploy_conn_chan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ pub fn generate_deploy_conn_chan() -> ConnChanAttribute {
.output(connection_output)
.output(channel_output)
.output(change_output)
.output_data(std::fs::read("./contracts/ics-conn").unwrap().pack())
.output_data(std::fs::read("./contracts/ics-chan").unwrap().pack())
.output_data(std::fs::read("./contracts/ics-connection").unwrap().pack())
.output_data(std::fs::read("./contracts/ics-channel").unwrap().pack())
.output_data(empty_data)
.build();

Expand Down

0 comments on commit 4b41e2f

Please sign in to comment.