Skip to content

Commit

Permalink
fix and test
Browse files Browse the repository at this point in the history
  • Loading branch information
blckngm committed Nov 23, 2023
1 parent 8098f4e commit ef69b91
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 84 deletions.
72 changes: 14 additions & 58 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jsonrpc-core = "18.0"
strum = { version = "0.24.1", features = ["derive"] }
lazy_static = "1.4.0"

ckb-ics-axon = { git = "https://github.com/synapseweb3/ckb-ics.git", rev = "45cdaa470cb" }
ckb-ics-axon = { git = "https://github.com/synapseweb3/ckb-ics.git", rev = "01de79165394103" }
cstr_core = "0.2.6"
rlp = "0.5.2"

Expand Down
3 changes: 0 additions & 3 deletions crates/relayer/src/chain/ckb4ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,6 @@ impl Ckb4IbcChain {
.and_then(|response| async {
let mut resps = vec![];
for cell in response.objects {
if cell.output.lock.args.len() != 32 {
continue;
}
let tx = self
.rpc_client
.get_transaction(&cell.out_point.tx_hash)
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 @@ -23,7 +23,6 @@ use ibc_relayer_types::core::ics04_channel::channel::{
ChannelEnd, Counterparty as ChannelCounterparty, IdentifiedChannelEnd, Order,
State as ChannelState,
};
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, PortId};

Expand Down Expand Up @@ -168,6 +167,7 @@ fn convert_channel_end(ckb_channel_end: CkbIbcChannel) -> Result<IdentifiedChann
};
let remote_port_id = PortId::from_str(&ckb_channel_end.counterparty.port_id)
.map_err(|_| Error::convert_channel_end())?;
let version = ckb_channel_end.version.parse().map_err(|_| Error::convert_channel_end())?;
let remote_channel_id = if ckb_channel_end.counterparty.channel_id.is_empty() {
None
} else {
Expand All @@ -193,7 +193,7 @@ fn convert_channel_end(ckb_channel_end: CkbIbcChannel) -> Result<IdentifiedChann
ordering,
remote,
connection_hops,
version: ChanVersion::empty(),
version,
};

let port_id =
Expand Down
3 changes: 2 additions & 1 deletion crates/relayer/src/chain/ckb4ibc/message/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ pub fn convert_chan_open_ack_to_tx<C: MsgToTxConverter>(
let counterparty_port_id = PortId::from_str(&old_channel.counterparty.port_id).unwrap();
let mut new_channel = old_channel.clone();
new_channel.state = CkbState::Open;
new_channel.counterparty.channel_id = msg.counterparty_channel_id.as_str().to_string();
new_channel.counterparty.channel_id = msg.counterparty_channel_id.to_string();
new_channel.version = msg.counterparty_version.to_string();

let envelope = Envelope {
msg_type: MsgType::MsgChannelOpenAck,
Expand Down
4 changes: 2 additions & 2 deletions tools/ibc-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jsonrpc-core = "18.0"
futures = "0.3.27"
serde_json = { version = "1", default-features = false }
serde = { version = "1.0", default-features = false }
ckb-ics-axon = { git = "https://github.com/synapseweb3/ckb-ics.git", rev = "45cdaa470cb" }
ckb-ics-axon = { git = "https://github.com/synapseweb3/ckb-ics.git", rev = "01de79165394103" }
rlp = "0.5.2"
secp256k1 = "0.24"
ckb-hash = "0.106"
Expand All @@ -45,7 +45,7 @@ toml_edit = "0.19.14"
lazy_static = "1.4.0"
ethers = { version = "2.0.2", features = ["rustls", "ws"] }

forcerelay-ckb-sdk = { git = "https://github.com/synapseweb3/forcerelay-ckb-sdk", rev = "64978b97" }
forcerelay-ckb-sdk = { git = "https://github.com/synapseweb3/forcerelay-ckb-sdk", rev = "39f0203bcbfcb5c8" }

[dependencies]
bytes = "1.5.0"
Expand Down
Binary file modified tools/ibc-test/contracts/ibc-sudt-transfer
Binary file not shown.
Binary file modified tools/ibc-test/contracts/ics-channel
100644 → 100755
Binary file not shown.
Binary file modified tools/ibc-test/contracts/ics-connection
100644 → 100755
Binary file not shown.
Binary file modified tools/ibc-test/contracts/ics-packet
100644 → 100755
Binary file not shown.
14 changes: 9 additions & 5 deletions tools/ibc-test/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
use ckb_types::{h256, H256};
use ckb_types::{h160, h256, H160, H256};

pub const SUDT_CODE_HASH: H256 =
h256!("0xcf6e0c0148123081af1deda0ef162d39cfdfe1ea6565d3689009c1f3562a5e82");
pub const CONNECTION_CODE_HASH: H256 =
h256!("0xe802fa98adeed078eb39225f6d7759ceeeecc32fa28942f2d2c6a158ec40cebb");
pub const CHANNEL_CODE_HASH: H256 =
h256!("0x489e3d7d39bc1fb4266185ae45f5e858e9d4040c0f0748502cb4a3df40fb0ead");
h256!("0x2c0ef0b26daa000b0f7a66899fd0da13038b8cc6240d3d721254dd46ff38ff83");

pub const SUDT_TYPE_ARGS: H256 =
h256!("0xf49ce32397c6741998b04d7548c5ed372007424daf67ee5bfadaefec3c865781");
pub const CONNECTION_TYPE_ARGS: H256 =
h256!("0x9d46ad77b8f5107d5898d7e7ad82be206c4fd95f562004efe32488605e8846c7");
pub const CHANNEL_TYPE_ARGS: H256 =
h256!("0x51fe9269fa2c1b9dc69e754ce6d1e0ae67f8787113e19d7c45878bc0756d87b0");
h256!("0xffa65d9d4779bb1f91eed5295d115c7e8f8770852a2942b9732550a8feb619a9");
pub const PACKET_TYPE_ARGS: H256 =
h256!("0xe95d570225c192fe50274764f5b722f536c27713932e4ed3eefbe2c501cbf0c1");
h256!("0x244771c385df2fb426a6658957b3c9f07820daea5ed0f537ce0cb5b4b49ca447");
pub const CLIENT_TYPE_ARGS: H256 =
h256!("0x49e52c85b82caef2b69dfc8774b932fabca48c64c0f9f778f83ac6605fe48cd2");
h256!("0x0bce5d9d16bdedb01fc47b8101de0dbd182f9195c3950fda2cac63cc1e284c02");

// Don't know how to pass this from axon to ckb. It doesn't change often, so
// let's hardcode it for now.
pub const AXON_IBC_HANDLER_ADDRESS: H160 = h160!("0xdc64a140aa3e981100a9beca4e685f962f0cf6c9");
5 changes: 3 additions & 2 deletions tools/ibc-test/src/framework/utils/ckb.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::consts::{CHANNEL_CODE_HASH, CLIENT_TYPE_ARGS, CONNECTION_CODE_HASH};
use crate::consts::{CHANNEL_CODE_HASH, CLIENT_TYPE_ARGS, CONNECTION_CODE_HASH, AXON_IBC_HANDLER_ADDRESS};
use crate::generator::{calc_script_hash, GENESIS_TXHASH};
use crate::rpc_client::RpcClient;

Expand Down Expand Up @@ -334,7 +334,8 @@ fn channel_id_to_u16(channel_id: &ChannelId) -> u16 {
pub fn fetch_ibc_channel_cell(port: u32, port_id: [u8; 32], channel_id: &ChannelId) -> IbcChannel {
let rpc_client = get_client(port);
let channel_args = ChannelArgs {
client_id: get_test_client_id().into(),
metadata_type_id: get_test_client_id().into(),
ibc_handler_address: AXON_IBC_HANDLER_ADDRESS.0,
open: true,
channel_id: channel_id_to_u16(channel_id),
port_id,
Expand Down
6 changes: 5 additions & 1 deletion tools/ibc-test/src/generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn generate_consts_file(
packet_metadata_attr: &PacketMetataAttribute,
) {
let consts_rs = format!(
r#"use ckb_types::{{h256, H256}};
r#"use ckb_types::{{h160, h256, H160, H256}};
pub const SUDT_CODE_HASH: H256 =
h256!("0x{}");
Expand All @@ -61,6 +61,10 @@ pub const PACKET_TYPE_ARGS: H256 =
h256!("0x{}");
pub const CLIENT_TYPE_ARGS: H256 =
h256!("0x{}");
// Don't know how to pass this from axon to ckb. It doesn't change often, so
// let's hardcode it for now.
pub const AXON_IBC_HANDLER_ADDRESS: H160 = h160!("0xdc64a140aa3e981100a9beca4e685f962f0cf6c9");
"#,
sudt_attr.sudt_code_hash,
connection_attr.connection_code_hash,
Expand Down
3 changes: 2 additions & 1 deletion tools/ibc-test/src/tests/ckb/packet/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use std::str::FromStr;
use tiny_keccak::Hasher;
use tokio::runtime::Runtime;

use crate::consts::{CLIENT_TYPE_ARGS, SUDT_CODE_HASH, SUDT_TYPE_ARGS};
use crate::consts::{CLIENT_TYPE_ARGS, SUDT_CODE_HASH, SUDT_TYPE_ARGS, AXON_IBC_HANDLER_ADDRESS};
use crate::generator::{get_lock_script, PRIVKEY};

#[derive(Serialize, Deserialize, PartialEq)]
Expand Down Expand Up @@ -262,6 +262,7 @@ pub fn prepare_artificials(
let sdk_config = SdkConfig {
module_lock_script: AddressOrScript::Script(relayer_script.into()),
axon_metadata_type_script: AddressOrScript::Script(metadata_script.into()),
axon_ibc_handler_address: AXON_IBC_HANDLER_ADDRESS,
channel_contract_type_id_args: ckb4ibc_config.channel_type_args.clone(),
packet_contract_type_id_args: ckb4ibc_config.packet_type_args.clone(),
channel_id: channel_number,
Expand Down
3 changes: 2 additions & 1 deletion tools/ibc-test/src/tests/ibc/sudt_erc20_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use prost::Message;
use tokio::runtime::Runtime;

use crate::{
consts::CLIENT_TYPE_ARGS,
consts::{CLIENT_TYPE_ARGS, AXON_IBC_HANDLER_ADDRESS},
generator::{get_lock_script, PRIVKEY},
tests::ckb::packet::utils::search_sudt_cells,
};
Expand Down Expand Up @@ -151,6 +151,7 @@ impl BinaryConnectionTest for SudtErc20TransferTest {
let sdk_config = forcerelay_ckb_sdk::config::Config {
module_lock_script: AddressOrScript::Script(ibc_sudt_transfer_lock.clone().into()),
axon_metadata_type_script: AddressOrScript::Script(metadata_script.clone().into()),
axon_ibc_handler_address: AXON_IBC_HANDLER_ADDRESS,
channel_contract_type_id_args: ckb_config.channel_type_args.clone(),
packet_contract_type_id_args: ckb_config.packet_type_args.clone(),
channel_id: channels
Expand Down
3 changes: 2 additions & 1 deletion tools/ibc-test/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ckb_sdk::constants::TYPE_ID_CODE_HASH;
use ibc_test_framework::prelude::Error;

use crate::consts::{CHANNEL_TYPE_ARGS, CLIENT_TYPE_ARGS, CONNECTION_TYPE_ARGS, PACKET_TYPE_ARGS};
use crate::consts::*;
use crate::framework::binary::channel::{
run_arbitrary_binary_channel_test, run_arbitrary_binary_connection_test,
};
Expand All @@ -25,6 +25,7 @@ fn init_envs() -> Result<(), Error> {
{"CHANNEL_TYPE_ARGS", hex::encode(CHANNEL_TYPE_ARGS)},
{"PACKET_TYPE_ARGS", hex::encode(PACKET_TYPE_ARGS)},
{"CLIENT_TYPE_ARGS", hex::encode(CLIENT_TYPE_ARGS)},
{"AXON_IBC_HANDLER_ADDRESS", hex::encode(AXON_IBC_HANDLER_ADDRESS)},
);
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion tools/ibc-test/txs/deploy_channel.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tools/ibc-test/txs/deploy_connection.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tools/ibc-test/txs/deploy_packet_metadata.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tools/ibc-test/txs/issue_sudt.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"id": 5, "jsonrpc": "2.0", "method": "send_transaction", "params": [{"version":"0x0","cell_deps":[{"out_point":{"tx_hash":"0x29ed5663501cd171513155f8939ad2c9ffeb92aa4879d39cde987f8eb6274407","index":"0x0"},"dep_type":"dep_group"},{"out_point":{"tx_hash":"0xd9812f0aaa786955967cf9ad69b959d97a9ea5a7b3df76b6f900c6ad622a2ad5","index":"0x0"},"dep_type":"code"}],"header_deps":[],"inputs":[{"since":"0x0","previous_output":{"tx_hash":"0xd30b3c0f17193aecdebbca1484903b8cac664df633753332c2455ab1af08d997","index":"0x2"}}],"outputs":[{"capacity":"0x34e62ce00","lock":{"code_hash":"0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8","hash_type":"type","args":"0x470dcdc5e44064909650113a274b3b36aecb6dc7"},"type":{"code_hash":"0xcf6e0c0148123081af1deda0ef162d39cfdfe1ea6565d3689009c1f3562a5e82","hash_type":"type","args":"0xc219351b150b900e50a7039f1e448b844110927e5fd9bd30425806cb8ddff1fd"}},{"capacity":"0x16bcc41e90000","lock":{"code_hash":"0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8","hash_type":"type","args":"0x470dcdc5e44064909650113a274b3b36aecb6dc7"},"type":null}],"outputs_data":["0x10270000000000000000000000000000","0x"],"witnesses":["0x5500000010000000550000005500000041000000fb5b17fd5cefc4b6f65aa1f21b6b0caa406689f6eaff0bb707f6717a95ab813b7b59d20f217bc1bcdfba517ccbb2c6ced9300df481a95a0ba384e8097ee4b48601"]}]}
{"id": 5, "jsonrpc": "2.0", "method": "send_transaction", "params": [{"version":"0x0","cell_deps":[{"out_point":{"tx_hash":"0x29ed5663501cd171513155f8939ad2c9ffeb92aa4879d39cde987f8eb6274407","index":"0x0"},"dep_type":"dep_group"},{"out_point":{"tx_hash":"0xd9812f0aaa786955967cf9ad69b959d97a9ea5a7b3df76b6f900c6ad622a2ad5","index":"0x0"},"dep_type":"code"}],"header_deps":[],"inputs":[{"since":"0x0","previous_output":{"tx_hash":"0x1f3cd745ca781e24edd27195f64a38b37b8160c2ba36edd386164790d2d0bf71","index":"0x2"}}],"outputs":[{"capacity":"0x34e62ce00","lock":{"code_hash":"0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8","hash_type":"type","args":"0x470dcdc5e44064909650113a274b3b36aecb6dc7"},"type":{"code_hash":"0xcf6e0c0148123081af1deda0ef162d39cfdfe1ea6565d3689009c1f3562a5e82","hash_type":"type","args":"0xc219351b150b900e50a7039f1e448b844110927e5fd9bd30425806cb8ddff1fd"}},{"capacity":"0x16bcc41e90000","lock":{"code_hash":"0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8","hash_type":"type","args":"0x470dcdc5e44064909650113a274b3b36aecb6dc7"},"type":null}],"outputs_data":["0x10270000000000000000000000000000","0x"],"witnesses":["0x55000000100000005500000055000000410000007087773b6ff3f385e74f02eede73892994a6c0c9e23b077496d28cfbdf6a575a4c51a3ca1f2ab4740f502c03c70cc7fc98df7dbb4876dc7712d4ae7a7594ee4100"]}]}
Loading

0 comments on commit ef69b91

Please sign in to comment.