From b69e58f7b7f15857a9e25b02e866614e67118235 Mon Sep 17 00:00:00 2001 From: Mario Karagiorgas Date: Thu, 7 Oct 2021 09:42:20 +0300 Subject: [PATCH] #1024 Unit test --- relayer/src/chain/cosmos.rs | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/relayer/src/chain/cosmos.rs b/relayer/src/chain/cosmos.rs index fb6ba6ba4c..4bda455e42 100644 --- a/relayer/src/chain/cosmos.rs +++ b/relayer/src/chain/cosmos.rs @@ -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); @@ -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 = 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); + } }