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 all 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
50 changes: 0 additions & 50 deletions .github/workflows/integration.yaml

This file was deleted.

24 changes: 24 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
71 changes: 10 additions & 61 deletions relayer-cli/tests/acceptance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,65 +31,16 @@ pub static RUNNER: Lazy<CmdRunner> = 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();
}
116 changes: 116 additions & 0 deletions relayer-cli/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -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::<ConnectionEnd>(
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::<ChannelEnd>(
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::<Vec<String>>(
ClientConnections(ClientId::from_str("clientidone").unwrap()),
0,
false,
)
.unwrap();

assert_eq!(query[0], "connections/connectionidone");
}