Skip to main content

multiversx_sc_codec/impl_for_types/
impl_bytes.rs

1#[cfg(test)]
2mod tests {
3    use crate::test_util::{
4        check_dep_encode, check_dep_encode_decode, check_top_encode, check_top_encode_decode,
5    };
6
7    #[test]
8    fn test_dep_encode() {
9        let bytes = check_dep_encode(&&[1u8, 2u8, 3u8][..]);
10        assert_eq!(bytes.as_slice(), &[0, 0, 0, 3, 1u8, 2u8, 3u8]);
11    }
12
13    #[test]
14    fn test_top_encode_empty() {
15        let empty_byte_slice: &[u8] = &[];
16        let bytes = check_top_encode(&empty_byte_slice);
17        assert_eq!(bytes.as_slice(), empty_byte_slice);
18    }
19
20    #[test]
21    fn test_dep_encode_empty() {
22        let empty_byte_slice: &[u8] = &[];
23        let bytes = check_dep_encode(&empty_byte_slice);
24        assert_eq!(bytes.as_slice(), &[0, 0, 0, 0])
25    }
26
27    #[test]
28    fn test_top_encode_non_empty() {
29        let bytes = check_top_encode(&&[1u8, 2u8, 3u8][..]);
30        assert_eq!(bytes.as_slice(), &[1u8, 2u8, 3u8]);
31    }
32
33    #[test]
34    fn test_top_vec_u8_decode() {
35        // Vec<u8> round-trips as byte buffer
36        check_top_encode_decode(alloc::vec![1u8, 2, 3], &[1, 2, 3]);
37    }
38
39    #[test]
40    fn test_dep_vec_u8_decode() {
41        check_dep_encode_decode(alloc::vec![1u8, 2, 3], &[0, 0, 0, 3, 1, 2, 3]);
42    }
43}