diff --git a/crates/ibc/src/client_state.rs b/crates/ibc/src/client_state.rs index e93ca65..9af104b 100644 --- a/crates/ibc/src/client_state.rs +++ b/crates/ibc/src/client_state.rs @@ -123,7 +123,7 @@ impl &[u8] { + let mut pos = 0; + for v in value { + if *v != 0 { + break; + } + pos += 1; + } + &value[pos..] +} + #[cfg(test)] mod tests { use super::*; @@ -978,4 +989,15 @@ mod tests { panic!("expected error"); } } + + #[test] + fn test_trim_left_zero() { + assert_eq!(trim_left_zero(&[1, 2, 3, 4]), [1, 2, 3, 4]); + assert_eq!(trim_left_zero(&[1, 2, 3, 0]), [1, 2, 3, 0]); + assert_eq!(trim_left_zero(&[0, 2, 3, 0]), [2, 3, 0]); + assert_eq!(trim_left_zero(&[0, 0, 3, 0]), [3, 0]); + assert_eq!(trim_left_zero(&[0, 0, 0, 4]), [4]); + assert!(trim_left_zero(&[0, 0, 0, 0]).is_empty()); + assert!(trim_left_zero(&[]).is_empty()); + } }