|
1 | 1 | #[cfg(test)] |
2 | 2 | mod tests { |
3 | | - use borsh::{BorshSerialize, BorshDeserialize}; |
| 3 | + use borsh::{BorshDeserialize, BorshSerialize}; |
4 | 4 |
|
5 | | - #[derive(BorshSerialize, BorshDeserialize, Debug, PartialEq)] |
6 | | - struct TestSerializable { |
7 | | - a: u32, |
8 | | - b: String, |
9 | | - c: Vec<u8>, |
10 | | - } |
| 5 | + #[derive(BorshSerialize, BorshDeserialize, Debug, PartialEq)] |
| 6 | + struct TestSerializable { |
| 7 | + a: u32, |
| 8 | + b: String, |
| 9 | + c: Vec<u8>, |
| 10 | + } |
11 | 11 |
|
12 | | - #[test] |
13 | | - fn test_serializable_to_vec() { |
14 | | - let inst = TestSerializable { |
15 | | - a: 42, |
16 | | - b: "Hello, world!".to_string(), |
17 | | - c: vec![1, 2, 3, 4, 5], |
18 | | - }; |
| 12 | + #[test] |
| 13 | + fn test_serializable_to_vec() { |
| 14 | + let inst = TestSerializable { |
| 15 | + a: 42, |
| 16 | + b: "Hello, world!".to_string(), |
| 17 | + c: vec![1, 2, 3, 4, 5], |
| 18 | + }; |
19 | 19 |
|
20 | | - // Expected serialized output |
21 | | - let expected_serialized: Vec<u8> = vec![ |
22 | | - 42, 0, 0, 0, // a: u32 (little-endian) |
23 | | - 13, 0, 0, 0, // Length of the string b (13) |
24 | | - 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33, // "Hello, world!" as bytes |
25 | | - 5, 0, 0, 0, // Length of the vector c (5) |
26 | | - 1, 2, 3, 4, 5 // c: Vec<u8> |
27 | | - ]; |
| 20 | + // Expected serialized output |
| 21 | + let expected_serialized: Vec<u8> = vec![ |
| 22 | + 42, 0, 0, 0, // a: u32 (little-endian) |
| 23 | + 13, 0, 0, 0, // Length of the string b (13) |
| 24 | + 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, |
| 25 | + 33, // "Hello, world!" as bytes |
| 26 | + 5, 0, 0, 0, // Length of the vector c (5) |
| 27 | + 1, 2, 3, 4, 5, // c: Vec<u8> |
| 28 | + ]; |
28 | 29 |
|
29 | | - // Serialize the instance |
30 | | - let serialized = borsh::to_vec(&inst).expect("Serialization failed"); |
| 30 | + // Serialize the instance |
| 31 | + let serialized = borsh::to_vec(&inst).expect("Serialization failed"); |
31 | 32 |
|
32 | | - // Assert that the serialized output matches the expected value |
33 | | - assert_eq!(serialized, expected_serialized, "Serialized bytes differ from the expected value"); |
| 33 | + // Assert that the serialized output matches the expected value |
| 34 | + assert_eq!( |
| 35 | + serialized, expected_serialized, |
| 36 | + "Serialized bytes differ from the expected value" |
| 37 | + ); |
34 | 38 |
|
35 | | - // Deserialize the serialized data back to a new instance |
36 | | - let deserialized_inst: TestSerializable = borsh::BorshDeserialize::try_from_slice(&serialized) |
37 | | - .expect("Deserialization failed"); |
| 39 | + // Deserialize the serialized data back to a new instance |
| 40 | + let deserialized_inst: TestSerializable = |
| 41 | + borsh::BorshDeserialize::try_from_slice(&serialized) |
| 42 | + .expect("Deserialization failed"); |
38 | 43 |
|
39 | | - // Assert that the deserialized instance matches the original instance |
40 | | - assert_eq!(deserialized_inst, inst, "Deserialized instance differs from the original"); |
41 | | - } |
| 44 | + // Assert that the deserialized instance matches the original instance |
| 45 | + assert_eq!( |
| 46 | + deserialized_inst, inst, |
| 47 | + "Deserialized instance differs from the original" |
| 48 | + ); |
| 49 | + } |
42 | 50 | } |
0 commit comments