Skip to content

Commit

Permalink
Replaced Vec<String> with Vec<ConnectionId> (#196)
Browse files Browse the repository at this point in the history
* Replaced Vec<String> with Vec<ConnectionId> #185

* Fixing integration test #185

* Fixing fmt issue #185

* Fixing missing import #196
  • Loading branch information
andynog authored Aug 14, 2020
1 parent 9d2b59f commit 4bd67d7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
14 changes: 12 additions & 2 deletions modules/src/ics02_client/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::ics03_connection::error::Kind;
use crate::ics24_host::identifier::ConnectionId;
use crate::try_from_raw::TryFromRaw;
use std::str::FromStr;

//TODO: This might need to be migrated to ibc-proto crate. But ClientConnections (as array of strings)
// might not be part of an official proto file
Expand All @@ -9,12 +11,20 @@ pub struct RawClientConnections {
pub connections: ::std::vec::Vec<String>,
}

impl TryFromRaw for Vec<String> {
impl TryFromRaw for Vec<ConnectionId> {
type RawType = RawClientConnections;
type Error = anomaly::Error<Kind>;
fn try_from(value: RawClientConnections) -> Result<Self, Self::Error> {
if !value.connections.is_empty() {
Ok(value.connections)
let mut connections: Vec<ConnectionId> = vec![];
for value in value.connections {
let conn_id = ConnectionId::from_str(&value.replace("connections/", ""));
match conn_id {
Ok(c) => connections.push(c),
Err(_e) => return Err(Kind::IdentifierError.into()),
}
}
Ok(connections)
} else {
Err(Kind::ConnectionNotFound.into())
}
Expand Down
11 changes: 7 additions & 4 deletions relayer-cli/src/commands/query/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use abscissa_core::{Command, Options, Runnable};
use relayer::config::{ChainConfig, Config};

use ibc::ics24_host::error::ValidationError;
use ibc::ics24_host::identifier::ClientId;
use ibc::ics24_host::identifier::{ClientId, ConnectionId};
use ibc::ics24_host::Path::ClientConnections;
use relayer::chain::Chain;
use relayer::chain::CosmosSDKChain;
Expand Down Expand Up @@ -274,7 +274,7 @@ impl QueryClientConnectionsCmd {

/// Command to handle query for client connections
/// To run without proof:
/// cargo run --bin relayer -- -c relayer/tests/config/fixtures/relayer_conf_example.toml query client connections chain_A clientidone -h 4 -p false
/// relayer -c relayer/tests/config/fixtures/relayer_conf_example.toml query client connections chain_A clientidone -h 4 -p false
impl Runnable for QueryClientConnectionsCmd {
fn run(&self) {
let config = app_config();
Expand All @@ -289,8 +289,11 @@ impl Runnable for QueryClientConnectionsCmd {
status_info!("Options", "{:?}", opts);

let chain = CosmosSDKChain::from_config(chain_config).unwrap();
let res =
chain.query::<Vec<String>>(ClientConnections(opts.client_id), opts.height, opts.proof);
let res = chain.query::<Vec<ConnectionId>>(
ClientConnections(opts.client_id),
opts.height,
opts.proof,
);
match res {
Ok(cs) => status_info!("client connections query result: ", "{:?}", cs),
Err(e) => status_info!("client connections query error", "{}", e),
Expand Down
7 changes: 5 additions & 2 deletions relayer-cli/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,15 @@ fn query_channel_id() {
fn query_client_id() {
let chain = simd_chain();
let query = chain
.query::<Vec<String>>(
.query::<Vec<ConnectionId>>(
ClientConnections(ClientId::from_str("clientidone").unwrap()),
0,
false,
)
.unwrap();

assert_eq!(query[0], "connections/connectionidone");
assert_eq!(
query[0],
ConnectionId::from_str("connections/connectionidone").unwrap()
);
}

0 comments on commit 4bd67d7

Please sign in to comment.