Skip to content

Commit

Permalink
Relayer tests for client update (ping pong) against MockChain (#440)
Browse files Browse the repository at this point in the history
* Introducing refs to be able to mutate the chains. done for clientCreate.

* Extending tests for client creationb.

* Introducing refs for update_client methods

* Extended tests for update client methods.

* Added more call by ref and tests for ForeignClient

* Recorded issue to changelog

* Better foreign client tests
  • Loading branch information
adizere authored Dec 8, 2020
1 parent 1bd058d commit 65e4f26
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 71 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
### IMPROVEMENTS

- Mock chain (implementing IBC handlers) and integration against CLI ([#158])
- Relayer tests for client update (ping pong) against MockChain ([#381])


[#158]: https://github.com/informalsystems/ibc-rs/issues/158
[#381]: https://github.com/informalsystems/ibc-rs/issues/381

## v0.0.5
*December 2, 2020*
Expand Down
3 changes: 2 additions & 1 deletion modules/src/ics07_tendermint/client_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ impl ClientDef for TendermintClient {
) -> Result<(Self::ClientState, Self::ConsensusState), Box<dyn std::error::Error>> {
if client_state.latest_height() >= header.height() {
return Err(
"received header height is lower than (or equal to) client latest height".into(),
format!("received header height ({:?}) is lower than (or equal to) client latest height ({:?})",
header.height(), client_state.latest_height).into(),
);
}

Expand Down
10 changes: 6 additions & 4 deletions relayer-cli/src/commands/tx/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ impl Runnable for TxCreateClientCmd {
let (src_chain, _) = ChainRuntime::<CosmosSDKChain>::spawn(src_chain_config).unwrap();
let (dst_chain, _) = ChainRuntime::<CosmosSDKChain>::spawn(dst_chain_config).unwrap();

let res: Result<String, Error> = build_create_client_and_send(dst_chain, src_chain, &opts)
.map_err(|e| Kind::Tx.context(e).into());
let res: Result<String, Error> =
build_create_client_and_send(&dst_chain, &src_chain, &opts)
.map_err(|e| Kind::Tx.context(e).into());

match res {
Ok(receipt) => status_ok!("Success", "client created: {:?}", receipt),
Expand Down Expand Up @@ -101,8 +102,9 @@ impl Runnable for TxUpdateClientCmd {
let (src_chain, _) = ChainRuntime::<CosmosSDKChain>::spawn(src_chain_config).unwrap();
let (dst_chain, _) = ChainRuntime::<CosmosSDKChain>::spawn(dst_chain_config).unwrap();

let res: Result<String, Error> = build_update_client_and_send(dst_chain, src_chain, &opts)
.map_err(|e| Kind::Tx.context(e).into());
let res: Result<String, Error> =
build_update_client_and_send(&dst_chain, &src_chain, &opts)
.map_err(|e| Kind::Tx.context(e).into());

match res {
Ok(receipt) => status_ok!("Success client updated: {:?}", receipt),
Expand Down
12 changes: 6 additions & 6 deletions relayer-cli/src/commands/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ pub fn v0_task(config: &Config) -> Result<(), BoxError> {

let path = &conn.paths.clone().ok_or("No paths configured")?[0];

let connection = ConnectionConfig::new(&conn.clone())?;
let channel = ChannelConfig::new(&connection, &path)?;
let connection_cfg = ConnectionConfig::new(&conn.clone())?;
let channel_cfg = ChannelConfig::new(&connection_cfg, &path)?;

let src_chain_config = config
.chains
.clone()
.into_iter()
.find(|c| c.id == connection.src().chain_id().clone())
.find(|c| c.id == connection_cfg.src().chain_id().clone())
.ok_or("Configuration for source chain not found")?;

let dst_chain_config = config
.chains
.clone()
.into_iter()
.find(|c| c.id == connection.dst().chain_id().clone())
.find(|c| c.id == connection_cfg.dst().chain_id().clone())
.ok_or("Configuration for source chain not found")?;

let (src_chain_handle, _) = ChainRuntime::<CosmosSDKChain>::spawn(src_chain_config)?;
Expand All @@ -64,7 +64,7 @@ pub fn v0_task(config: &Config) -> Result<(), BoxError> {
Ok(channel_relay(
src_chain_handle,
dst_chain_handle,
connection,
channel,
connection_cfg,
channel_cfg,
)?)
}
10 changes: 0 additions & 10 deletions relayer/src/chain/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,12 @@ pub trait ChainHandle: Clone + Send + Sync {
/// Send a transaction with `msgs` to chain.
fn send_tx(&self, proto_msgs: Vec<prost_types::Any>) -> Result<String, Error>;

// Inclusion proofs
// It might be good to include an inclusion proof method which abstracts over the light client
// to prove that a piece of data is stored on the chain

// fn get_header(&self, height: Height) -> Result<AnyHeader, Error>;

fn get_minimal_set(&self, from: Height, to: Height) -> Result<Vec<AnyHeader>, Error>;

fn get_signer(&self) -> Result<AccountId, Error>;

fn get_key(&self) -> Result<KeyEntry, Error>;

// fn submit(&self, transaction: EncodedTransaction) -> Result<(), Error>;

// fn create_packet(&self, event: IBCEvent) -> Result<Packet, Error>;

fn module_version(&self, port_id: &PortId) -> Result<String, Error>;

fn query_latest_height(&self) -> Result<Height, Error>;
Expand Down
14 changes: 11 additions & 3 deletions relayer/src/chain/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,18 @@ impl Chain for MockChain {

fn build_header(
&self,
_trusted_light_block: Self::LightBlock,
_target_light_block: Self::LightBlock,
trusted_light_block: Self::LightBlock,
target_light_block: Self::LightBlock,
) -> Result<Self::Header, Error> {
unimplemented!()
Ok(Self::Header {
signed_header: target_light_block.signed_header.clone(),
validator_set: target_light_block.validators,
trusted_height: Height::new(
self.id().version(),
u64::from(trusted_light_block.signed_header.header.height),
),
trusted_validator_set: trusted_light_block.validators,
})
}

fn query_latest_height(&self) -> Result<Height, Error> {
Expand Down
12 changes: 6 additions & 6 deletions relayer/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,8 @@ pub fn build_chan_try(

// Build message to update client on destination
let mut msgs = build_update_client(
dst_chain.clone(),
src_chain.clone(),
&dst_chain,
&src_chain,
&dest_connection.client_id(),
ics_target_height,
)?;
Expand Down Expand Up @@ -611,8 +611,8 @@ pub fn build_chan_ack(

// Build message to update client on destination
let mut msgs = build_update_client(
dst_chain.clone(),
src_chain.clone(),
&dst_chain,
&src_chain,
&dest_connection.client_id(),
ics_target_height,
)?;
Expand Down Expand Up @@ -694,8 +694,8 @@ pub fn build_chan_confirm(

// Build message to update client on destination
let mut msgs = build_update_client(
dst_chain.clone(),
src_chain.clone(),
&dst_chain,
&src_chain,
&dest_connection.client_id(),
ics_target_height,
)?;
Expand Down
20 changes: 10 additions & 10 deletions relayer/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ pub fn build_conn_try(
// TODO - add check if it is required
let src_client_target_height = dst_chain.query_latest_height()?;
let client_msgs = build_update_client(
src_chain.clone(),
dst_chain.clone(),
&src_chain,
&dst_chain,
&opts.src().client_id(),
src_client_target_height,
)?;
Expand All @@ -479,8 +479,8 @@ pub fn build_conn_try(
let ics_target_height = src_chain.query_latest_height()?;

let mut msgs = build_update_client(
dst_chain.clone(),
src_chain.clone(),
&dst_chain,
&src_chain,
&opts.dst().client_id(),
ics_target_height,
)?;
Expand Down Expand Up @@ -568,8 +568,8 @@ pub fn build_conn_ack(
// TODO - add check if it is required
let src_client_target_height = dst_chain.query_latest_height()?;
let client_msgs = build_update_client(
src_chain.clone(),
dst_chain.clone(),
&src_chain,
&dst_chain,
&opts.src().client_id(),
src_client_target_height,
)?;
Expand All @@ -579,8 +579,8 @@ pub fn build_conn_ack(
let ics_target_height = src_chain.query_latest_height()?;

let mut msgs = build_update_client(
dst_chain.clone(),
src_chain.clone(),
&dst_chain,
&src_chain,
&opts.dst().client_id(),
ics_target_height,
)?;
Expand Down Expand Up @@ -659,8 +659,8 @@ pub fn build_conn_confirm(
let ics_target_height = src_chain.query_latest_height()?;

let mut msgs = build_update_client(
dst_chain.clone(),
src_chain.clone(),
&dst_chain,
&src_chain,
&opts.dst().client_id(),
ics_target_height,
)?;
Expand Down
Loading

0 comments on commit 65e4f26

Please sign in to comment.