Skip to content

Commit 914006e

Browse files
committed
Add Checksum serde test
1 parent 3664b39 commit 914006e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/std/src/checksum.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ impl From<Checksum> for Vec<u8> {
139139
mod tests {
140140
use super::*;
141141

142+
use crate::to_json_string;
143+
142144
#[test]
143145
fn generate_works() {
144146
let wasm = vec![0x68, 0x69, 0x6a];
@@ -218,4 +220,21 @@ mod tests {
218220
let _: &[u8; 32] = checksum.as_ref();
219221
let _: &[u8] = checksum.as_ref();
220222
}
223+
224+
#[test]
225+
fn serde_works() {
226+
// echo -n "hij" | sha256sum
227+
let checksum =
228+
Checksum::from_hex("722c8c993fd75a7627d69ed941344fe2a1423a3e75efd3e6778a142884227104")
229+
.unwrap();
230+
231+
let serialized = to_json_string(&checksum).unwrap();
232+
assert_eq!(
233+
serialized,
234+
"\"722c8c993fd75a7627d69ed941344fe2a1423a3e75efd3e6778a142884227104\""
235+
);
236+
237+
let deserialized: Checksum = serde_json::from_str(&serialized).unwrap();
238+
assert_eq!(deserialized, checksum);
239+
}
221240
}

0 commit comments

Comments
 (0)