Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query tests #184

Merged
merged 8 commits into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 32 additions & 30 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
name: Integration test
on: [push]
on: [pull_request]
jobs:
test-integration-stable:
runs-on: ubuntu-latest
services:
chain1:
image: informaldev/chain_a
# chain_a:
# image: informaldev/chain_a
# ports:
# - 26656:26656
# - 26657:26657
# chain_b:
# image: informaldev/chain_b
# ports:
# - 26556:26656
# - 26557:26657
simd:
image: informaldev/simd
ports:
- 1317:1317
- 26656:26656
- 26657:26657
chain2:
image: informaldev/chain_b
ports:
- 26556:26656
- 26557:26657
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -24,27 +30,23 @@ jobs:
with:
command: build
args: -p relayer-cli --bins
- name: Set up chain_a
run: |
TRUSTED_HEADER="$(curl -s http://localhost:26657/status)"
HASH="$(echo "${TRUSTED_HEADER}" | jq -r .result.sync_info.latest_block_hash)"
HEIGHT="$(echo "${TRUSTED_HEADER}" | jq -r .result.sync_info.latest_block_height)"
cargo run --bin relayer -- -c relayer/tests/config/fixtures/relayer_conf_example.toml light init -x "${HASH}" -h "${HEIGHT}" chain_A
- name: Set up chain_b
run: |
TRUSTED_HEADER="$(curl -s http://localhost:26557/status)"
HASH="$(echo "${TRUSTED_HEADER}" | jq -r .result.sync_info.latest_block_hash)"
HEIGHT="$(echo "${TRUSTED_HEADER}" | jq -r .result.sync_info.latest_block_height)"
cargo run --bin relayer -- -c relayer/tests/config/fixtures/relayer_conf_example.toml light init -x "${HASH}" -h "${HEIGHT}" chain_B
- name: Run relayer in the background
run: |
cargo run --bin relayer -- -c relayer/tests/config/fixtures/relayer_conf_example.toml start --reset &
sleep 3
# - name: Set up chain_a
# run: |
# TRUSTED_HEADER="$(curl -s http://localhost:26657/status)"
# HASH="$(echo "${TRUSTED_HEADER}" | jq -r .result.sync_info.latest_block_hash)"
# HEIGHT="$(echo "${TRUSTED_HEADER}" | jq -r .result.sync_info.latest_block_height)"
# cargo run --bin relayer-cli -- -c relayer/tests/config/fixtures/relayer_conf_example.toml light init -x "${HASH}" -h "${HEIGHT}" chain_A
# - name: Set up chain_b
# run: |
# TRUSTED_HEADER="$(curl -s http://localhost:26557/status)"
# HASH="$(echo "${TRUSTED_HEADER}" | jq -r .result.sync_info.latest_block_hash)"
# HEIGHT="$(echo "${TRUSTED_HEADER}" | jq -r .result.sync_info.latest_block_height)"
# cargo run --bin relayer-cli -- -c relayer/tests/config/fixtures/relayer_conf_example.toml light init -x "${HASH}" -h "${HEIGHT}" chain_B
# - name: Run relayer in the background
# run: |
# cargo run --bin relayer -- -c relayer/tests/config/fixtures/relayer_conf_example.toml start --reset &
# sleep 3
- uses: actions-rs/cargo@v1
with:
command: run
args: --bin relayer -- -v -c relayer/tests/config/fixtures/relayer_conf_example.toml query connection end chain_A testconnection
# - uses: actions-rs/cargo@v1
# with:
# command: test
# args: --test integration --no-fail-fast
command: test
args: -p relayer-cli --test acceptance --no-fail-fast -- --ignored
128 changes: 80 additions & 48 deletions relayer-cli/tests/acceptance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
use abscissa_core::testing::prelude::*;
use once_cell::sync::Lazy;

// use relayer_cli::config::Config;
use relayer::config::{ChainConfig, Config};
use std::str::FromStr;
use tendermint::chain::Id;
use tendermint::net::Address;

/// Executes your application binary via `cargo run`.
///
Expand All @@ -31,67 +34,96 @@ use once_cell::sync::Lazy;
/// invocations as `cargo test` executes tests in parallel by default.
pub static RUNNER: Lazy<CmdRunner> = Lazy::new(|| CmdRunner::default());

/// Configuration that connects to the informaldev/simd DockerHub image running on localhost.
fn simd_config() -> Config {
let mut config = Config::default();
config.chains = vec![ChainConfig {
id: Id::from("ibc-test"),
rpc_addr: Address::from_str("127.0.0.1:26657").unwrap(),
account_prefix: "cosmos".to_string(),
key_name: "testkey".to_string(),
store_prefix: "ibc".to_string(),
client_ids: vec!["ethbridge".to_string()],
gas: 200000,
trusting_period: Default::default(),
}];
config
}

/// Use `Config::default()` value if no config or args
#[test]
#[ignore]
fn start_no_args() {
// let mut runner = RUNNER.clone();
// let mut cmd = runner.arg("start").capture_stdout().run();
// cmd.stdout().expect_line("Hello, world!");
// cmd.wait().unwrap().expect_success();
let mut runner = RUNNER.clone();
let mut cmd = runner.capture_stdout().run();
cmd.stdout().expect_regex(
format!(
"^[^ ]*{} {}$",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION")
)
.as_str(),
); // Todo: find out how to disable colored output and then remove the `[^ ]*` part from the regexp.
cmd.wait().unwrap().expect_success();
}

/// Use command-line argument value
/// Query connection ID. Requires the informaldev/simd Docker image running on localhost.
#[test]
#[ignore]
fn start_with_args() {
// let mut runner = RUNNER.clone();
// let mut cmd = runner
// .args(&["start", "acceptance", "test"])
// .capture_stdout()
// .run();

// cmd.stdout().expect_line("Hello, acceptance test!");
// cmd.wait().unwrap().expect_success();
fn query_connection_id() {
let mut runner = RUNNER.clone();
let mut cmd = runner
.config(&simd_config())
.args(&["query", "connection", "end", "ibc-test", "connectionidone"])
.capture_stdout()
.run();
// Todo: find out how to disable colored output
// Local execution: (with color)
// cmd.stdout().expect_line("\u{1b}[0m\u{1b}[0m\u{1b}[1m\u{1b}[36m Options\u{1b}[0m QueryConnectionOptions { connection_id: ConnectionId(\"connectionidone\"), height: 0, proof: true }", );
// CI: (without color)
cmd.stdout().expect_line(" Options QueryConnectionOptions { connection_id: ConnectionId(\"connectionidone\"), height: 0, proof: true }", );
cmd.wait().unwrap().expect_success();
}

/// Use configured value
/// Query channel ID. Requires the informaldev/simd Docker image running on localhost.
#[test]
#[ignore]
fn start_with_config_no_args() {
// let mut config = Config::default();
// config.hello.recipient = "configured recipient".to_owned();

// let expected_line = format!("Hello, {}!", &config.hello.recipient);

// let mut runner = RUNNER.clone();
// let mut cmd = runner.config(&config).arg("start").capture_stdout().run();
// cmd.stdout().expect_line(&expected_line);
// cmd.wait().unwrap().expect_success();
fn query_channel_id() {
let mut runner = RUNNER.clone();
let mut cmd = runner
.config(&simd_config())
.args(&[
"query",
"channel",
"end",
"ibc-test",
"firstport",
"firstchannel",
])
.capture_stdout()
.run();
// Todo: find out how to disable colored output
// Local execution: (with color)
// cmd.stdout().expect_line("\u{1b}[0m\u{1b}[0m\u{1b}[1m\u{1b}[36m Options\u{1b}[0m QueryChannelOptions { port_id: PortId(\"firstport\"), channel_id: ChannelId(\"firstchannel\"), height: 0, proof: true }", );
// CI: (without color)
cmd.stdout().expect_line(" Options QueryChannelOptions { port_id: PortId(\"firstport\"), channel_id: ChannelId(\"firstchannel\"), height: 0, proof: true }", );
cmd.wait().unwrap().expect_success();
}

/// Override configured value with command-line argument
/// Query channel ID. Requires the informaldev/simd Docker image running on localhost.
#[test]
#[ignore]
fn start_with_config_and_args() {
// let mut config = Config::default();
// config.hello.recipient = "configured recipient".to_owned();

// let mut runner = RUNNER.clone();
// let mut cmd = runner
// .config(&config)
// .args(&["start", "acceptance", "test"])
// .capture_stdout()
// .run();

// cmd.stdout().expect_line("Hello, acceptance test!");
// cmd.wait().unwrap().expect_success();
}

/// Example of a test which matches a regular expression
#[test]
fn version_no_args() {
fn query_client_id() {
let mut runner = RUNNER.clone();
let mut cmd = runner.arg("version").capture_stdout().run();
cmd.stdout().expect_regex(r"\A[\w-]+ [\d\.\-]+\z");
let mut cmd = runner
.config(&simd_config())
.args(&["query", "client", "connections", "ibc-test", "clientidone"])
.args(&["--proof", "false"])
.capture_stdout()
.run();
// Todo: find out how to disable colored output
// Local execution: (with color)
// cmd.stdout().expect_line("\u{1b}[0m\u{1b}[0m\u{1b}[1m\u{1b}[36m Options\u{1b}[0m QueryClientConnectionsOptions { client_id: ClientId(\"clientidone\"), height: 0, proof: false }", );
// CI: (without color)
cmd.stdout().expect_line(" Options QueryClientConnectionsOptions { client_id: ClientId(\"clientidone\"), height: 0, proof: false }", );
cmd.wait().unwrap().expect_success();
}