From 69dd94b72787cd5a37f7332eb2d7373ed2d561b2 Mon Sep 17 00:00:00 2001 From: yoshidan Date: Tue, 27 Feb 2024 22:41:04 +0900 Subject: [PATCH 1/2] trim left zero from expected value Signed-off-by: yoshidan --- crates/ibc/src/client_state.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/ibc/src/client_state.rs b/crates/ibc/src/client_state.rs index e93ca65..370f8d9 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::*; From bef26b3df5317fcf7192635bfc10af3c5a3f5f9b Mon Sep 17 00:00:00 2001 From: yoshidan Date: Tue, 27 Feb 2024 23:13:52 +0900 Subject: [PATCH 2/2] add test Signed-off-by: yoshidan --- crates/ibc/src/client_state.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/ibc/src/client_state.rs b/crates/ibc/src/client_state.rs index 370f8d9..9af104b 100644 --- a/crates/ibc/src/client_state.rs +++ b/crates/ibc/src/client_state.rs @@ -989,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()); + } }