From 9482fd25b2342c3d1a9446614153676faf6d845c Mon Sep 17 00:00:00 2001 From: Greg Szabo <16846635+greg-szabo@users.noreply.github.com> Date: Fri, 31 Jul 2020 10:06:56 -0400 Subject: [PATCH] Query tests (#184) * Query tests using abscissa * Old integration test disabled for now * Sad typo fix * Disabled color on acceptance tests * Retarget integration tests to pull_requests * Added query tests without using abscissa * Removed Abscissa testing, cleaned up CI folder * fmt sad fix --- .github/workflows/integration.yaml | 50 ------------- .github/workflows/rust.yml | 24 ++++++ relayer-cli/tests/acceptance.rs | 71 +++--------------- relayer-cli/tests/integration.rs | 116 +++++++++++++++++++++++++++++ 4 files changed, 150 insertions(+), 111 deletions(-) delete mode 100644 .github/workflows/integration.yaml create mode 100644 relayer-cli/tests/integration.rs diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml deleted file mode 100644 index 7ca207537e..0000000000 --- a/.github/workflows/integration.yaml +++ /dev/null @@ -1,50 +0,0 @@ -name: Integration test -on: [push] -jobs: - test-integration-stable: - runs-on: ubuntu-latest - services: - chain1: - image: informaldev/chain_a - ports: - - 26656:26656 - - 26657:26657 - chain2: - image: informaldev/chain_b - ports: - - 26556:26656 - - 26557:26657 - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - uses: actions-rs/cargo@v1 - 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 - - 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 diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0d8db99130..583d717a95 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -53,6 +53,30 @@ jobs: command: test args: --all-features --no-fail-fast + test-integration-stable: + runs-on: ubuntu-latest + services: + simd: + image: informaldev/simd + ports: + - 1317:1317 + - 26656:26656 + - 26657:26657 + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - uses: actions-rs/cargo@v1 + with: + command: build + args: -p relayer-cli --bins + - uses: actions-rs/cargo@v1 + with: + command: test + args: -p relayer-cli --test acceptance --no-fail-fast -- --ignored + test-nightly-coverage: runs-on: ubuntu-latest steps: diff --git a/relayer-cli/tests/acceptance.rs b/relayer-cli/tests/acceptance.rs index c1d4a94c46..2da38d04ca 100644 --- a/relayer-cli/tests/acceptance.rs +++ b/relayer-cli/tests/acceptance.rs @@ -21,8 +21,6 @@ use abscissa_core::testing::prelude::*; use once_cell::sync::Lazy; -// use relayer_cli::config::Config; - /// Executes your application binary via `cargo run`. /// /// Storing this value as a [`Lazy`] static ensures that all instances of @@ -33,65 +31,16 @@ pub static RUNNER: Lazy = Lazy::new(|| CmdRunner::default()); /// 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(); -} - -/// Use command-line argument value -#[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(); -} - -/// Use configured value -#[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(); -} - -/// Override configured value with command-line argument -#[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() { 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.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(); } diff --git a/relayer-cli/tests/integration.rs b/relayer-cli/tests/integration.rs new file mode 100644 index 0000000000..58b08c434e --- /dev/null +++ b/relayer-cli/tests/integration.rs @@ -0,0 +1,116 @@ +//! Integration test: runs the application against a live service + +// Tip: Deny warnings with `RUSTFLAGS="-D warnings"` environment variable in CI + +#![forbid(unsafe_code)] +#![warn( + missing_docs, + rust_2018_idioms, + trivial_casts, + unused_lifetimes, + unused_qualifications +)] + +use relayer::chain::{Chain, CosmosSDKChain}; +use relayer::config::{ChainConfig, Config}; +use relayer_modules::ics03_connection::connection::ConnectionEnd; +use relayer_modules::ics03_connection::exported::Connection; +use relayer_modules::ics03_connection::exported::State as ConnectionState; +use relayer_modules::ics04_channel::channel::ChannelEnd; +use relayer_modules::ics04_channel::exported::Channel; +use relayer_modules::ics04_channel::exported::Order; +use relayer_modules::ics04_channel::exported::State as ChannelState; +use relayer_modules::ics23_commitment::CommitmentPrefix; +use relayer_modules::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId}; +use relayer_modules::ics24_host::Path::{ChannelEnds, ClientConnections, Connections}; +use std::str::FromStr; +use tendermint::chain::Id; +use tendermint::net::Address; + +/// 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 +} + +/// Chain created for the informaldev/simd DockerHub image running on localhost. +fn simd_chain() -> CosmosSDKChain { + CosmosSDKChain::from_config(simd_config().chains[0].clone()).unwrap() +} + +/// Query connection ID. Requires the informaldev/simd Docker image running on localhost. +#[test] +#[ignore] +fn query_connection_id() { + let chain = simd_chain(); + let query = chain + .query::( + Connections(ConnectionId::from_str("connectionidone").unwrap()), + 0, + false, + ) + .unwrap(); + + assert_eq!(query.state(), &ConnectionState::Init); + assert_eq!(query.client_id(), "clientidone"); + assert_eq!(query.counterparty().client_id(), "clientidtwo"); + assert_eq!(query.counterparty().connection_id(), "connectionidtwo"); + assert_eq!( + query.counterparty().prefix(), + &CommitmentPrefix::new("prefix".as_bytes().to_vec()) + ); + assert_eq!( + query.versions(), + vec!["(1,[ORDER_ORDERED,ORDER_UNORDERED])"] + ); +} + +/// Query channel ID. Requires the informaldev/simd Docker image running on localhost. +#[test] +#[ignore] +fn query_channel_id() { + let chain = simd_chain(); + let query = chain + .query::( + ChannelEnds( + PortId::from_str("firstport").unwrap(), + ChannelId::from_str("firstchannel").unwrap(), + ), + 0, + false, + ) + .unwrap(); + + assert_eq!(query.state(), &ChannelState::Init); + assert_eq!(query.ordering(), &Order::Ordered); + assert_eq!(query.counterparty().port_id(), "secondport"); + assert_eq!(query.counterparty().channel_id(), "secondchannel"); + assert_eq!(query.connection_hops()[0].as_str(), "connectionidatob"); + assert_eq!(query.version(), "1.0"); +} + +/// Query client connections ID. Requires the informaldev/simd Docker image running on localhost. +#[test] +#[ignore] +fn query_client_id() { + let chain = simd_chain(); + let query = chain + .query::>( + ClientConnections(ClientId::from_str("clientidone").unwrap()), + 0, + false, + ) + .unwrap(); + + assert_eq!(query[0], "connections/connectionidone"); +}