Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
blewater committed Oct 7, 2021
1 parent 6f68b2a commit b69e58f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions relayer/src/chain/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2118,6 +2118,17 @@ fn mul_ceil(a: u64, f: f64) -> u64 {

#[cfg(test)]
mod tests {
use ibc::{
Height,
ics02_client::client_state::{AnyClientState, IdentifiedAnyClientState},
ics02_client::client_type::ClientType,
ics24_host::identifier::ClientId,
mock::client_state::MockClientState,
mock::header::MockHeader
};

use crate::chain::cosmos::client_id_suffix;

#[test]
fn mul_ceil() {
assert_eq!(super::mul_ceil(300_000, 0.001), 300);
Expand All @@ -2128,4 +2139,31 @@ mod tests {
assert_eq!(super::mul_ceil(340_000, 0.001), 340);
assert_eq!(super::mul_ceil(340_001, 0.001), 341);
}

#[test]
fn sort_clients_id_suffix() {
let mut clients: Vec<IdentifiedAnyClientState> = vec![
IdentifiedAnyClientState::new(
ClientId::new(ClientType::Tendermint, 4).unwrap(),
AnyClientState::Mock(
MockClientState(
MockHeader::new(Height::new(0, 0))))),
IdentifiedAnyClientState::new(
ClientId::new(ClientType::Tendermint, 1).unwrap(),
AnyClientState::Mock(
MockClientState(
MockHeader::new(Height::new(0, 0))))),
IdentifiedAnyClientState::new(
ClientId::new(ClientType::Tendermint, 7).unwrap(),
AnyClientState::Mock(
MockClientState(
MockHeader::new(Height::new(0, 0))))),
];
clients.sort_by_cached_key(|c|
client_id_suffix(&c.client_id)
.unwrap_or(0));
assert_eq!(client_id_suffix(&clients.first().unwrap().client_id).unwrap(), 1);
assert_eq!(client_id_suffix(&clients[1].client_id).unwrap(), 4);
assert_eq!(client_id_suffix(&clients.last().unwrap().client_id).unwrap(), 7);
}
}

0 comments on commit b69e58f

Please sign in to comment.