Skip to content

Commit

Permalink
Add Checksum serde test
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Nov 15, 2023
1 parent 98ccfd2 commit 5167ba5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/std/src/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ impl From<Checksum> for Vec<u8> {
mod tests {
use super::*;

use crate::to_json_string;

#[test]
fn generate_works() {
let wasm = vec![0x68, 0x69, 0x6a];
Expand Down Expand Up @@ -218,4 +220,21 @@ mod tests {
let _: &[u8; 32] = checksum.as_ref();
let _: &[u8] = checksum.as_ref();
}

#[test]
fn serde_works() {
// echo -n "hij" | sha256sum
let checksum =
Checksum::from_hex("722c8c993fd75a7627d69ed941344fe2a1423a3e75efd3e6778a142884227104")
.unwrap();

let serialized = to_json_string(&checksum).unwrap();
assert_eq!(
serialized,
"\"722c8c993fd75a7627d69ed941344fe2a1423a3e75efd3e6778a142884227104\""
);

let deserialized: Checksum = serde_json::from_str(&serialized).unwrap();
assert_eq!(deserialized, checksum);
}
}

0 comments on commit 5167ba5

Please sign in to comment.