Skip to content

Commit

Permalink
chore: start cell-emitter in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
liyukun committed Dec 19, 2023
1 parent c7bb87c commit 2886cf4
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 9 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/ibc-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ jobs:
env:
SRC_DIR: ${{ github.workspace }}/ibc-test-src
# https://github.com/axonweb3/axon/commits/forcerelay-dev
AXON_COMMIT: 922fc3858b4c470a39b3ae98a479980e774896b5
AXON_COMMIT: 343f329b78b8187e28fdac9e9af6c28222656b92
IBC_CONTRACT_COMMIT: c5417573ec15c8aaab048caa1ec5f3bd50c2170e
CELL_EMITTER_COMMIT: 0a897111b389472a078512815d293703910c25d5
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -73,6 +74,9 @@ jobs:
- name: Prepare Axon source
run: git clone --recursive https://github.com/axonweb3/axon.git $SRC_DIR/axon && cd $SRC_DIR/axon && git checkout $AXON_COMMIT

- name: Prepare Cell Emitter
run: git clone --recursive https://github.com/axonweb3/emitter.git $SRC_DIR/emitter && cd $SRC_DIR/emitter && git checkout $CELL_EMITTER_COMMIT

- name: Rust cache
uses: Swatinem/rust-cache@v2
with:
Expand Down Expand Up @@ -110,6 +114,15 @@ jobs:
command: build
args: -p ibc-test --tests --jobs=4

- name: Build Cell Emitter
uses: actions-rs/cargo@v1
with:
command: build
args: --release --manifest-path ${{env.SRC_DIR}}/emitter/Cargo.toml

- name: Add cell-emitter bin to path
run: echo "${{env.SRC_DIR}}/emitter/target/release/" >> $GITHUB_PATH

- name: Run IBC tests
uses: actions-rs/cargo@v1
env:
Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock

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

23 changes: 21 additions & 2 deletions tools/ibc-test/src/framework/binary/node.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use ibc_test_framework::{
chain::builder::ChainBuilder,
chain::{builder::ChainBuilder, chain_type::ChainType},
framework::{
base::BasicTest,
binary::node::{NodeConfigOverride, NodeGenesisOverride},
},
prelude::*,
};

use crate::framework::bootstrap::node::bootstrap_single_node;
use crate::framework::{
bootstrap::node::bootstrap_single_node, utils::common::prepare_cell_emitter,
};

/**
A wrapper type that lifts a test case that implements [`BinaryNodeTest`]
Expand Down Expand Up @@ -46,6 +48,23 @@ where
let _node_process_a = node_a.process.clone();
let _node_process_b = node_b.process.clone();

// start cell-emitter if only one part of connected chains is Axon
let chain_types = (
&node_a.chain_driver.chain_type,
&node_b.chain_driver.chain_type,
);
if matches!(chain_types, (&ChainType::Axon, &ChainType::Ckb)) {
let axon_port = node_a.chain_driver.rpc_port;
let ckb_port = node_b.chain_driver.rpc_port;
println!("start cell-emiter for Axon:{axon_port} and CKB:{ckb_port}");
prepare_cell_emitter(axon_port, ckb_port);
} else if matches!(chain_types, (&ChainType::Ckb, &ChainType::Axon)) {
let axon_port = node_b.chain_driver.rpc_port;
let ckb_port = node_a.chain_driver.rpc_port;
println!("start cell-emiter for Axon:{axon_port} and CKB:{ckb_port}");
prepare_cell_emitter(axon_port, ckb_port);
}

eprintln!("Node is initialized, Starting running inner test..........");

self.test.run(config, node_a, node_b)
Expand Down
21 changes: 21 additions & 0 deletions tools/ibc-test/src/framework/utils/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ use ckb_types::prelude::Entity;
use futures::Future;
use ibc_test_framework::prelude::*;
use relayer::chain::ChainType;
use secp256k1::rand::rngs;
use secp256k1::Secp256k1;
use secp256k1::{
rand::{self, Rng},
SecretKey,
};
use std::path::PathBuf;
use std::process::{Command, Stdio};
use std::str::FromStr;
use tokio::runtime::Runtime;

Expand Down Expand Up @@ -62,3 +64,22 @@ pub fn transfer_port_id(chain_type: ChainType) -> PortId {
}
}
}

pub fn prepare_cell_emitter(axon_port: u16, ckb_port: u16) {
let listen_port = rngs::OsRng.gen_range(9000..10000);
let store_path = std::env::current_dir()
.unwrap()
.join(format!("emitter/store-{listen_port}"));
Command::new("emitter")
.arg("-c")
.arg(format!("http://localhost:{ckb_port}"))
.arg("--i")
.arg(format!("http://localhost:{axon_port}"))
.arg("-l")
.arg(format!("127.0.0.1:{listen_port}"))
.arg("-s")
.arg(store_path)
.stdout(Stdio::null())
.spawn()
.expect("cell emitter");
}

0 comments on commit 2886cf4

Please sign in to comment.