Skip to content

Commit

Permalink
Merge pull request #380 from Chia-Network/minor-test-refactor
Browse files Browse the repository at this point in the history
minor refactoring of a test in `de_br.rs`
  • Loading branch information
arvidn authored Feb 12, 2024
2 parents 07e9213 + 46ce8d4 commit 6284d54
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/serde/de_br.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,21 @@ pub fn node_from_bytes_backrefs(allocator: &mut Allocator, b: &[u8]) -> io::Resu
#[cfg(test)]
use hex::FromHex;

#[cfg(test)]
use crate::serde::object_cache::{treehash, ObjectCache};

#[cfg(test)]
fn deserialize_check(serialization_as_hex: &str, expected_hash_as_hex: &str) {
let buf = Vec::from_hex(serialization_as_hex).unwrap();
let mut allocator = Allocator::new();
let node = node_from_bytes_backrefs(&mut allocator, &buf).unwrap();

let mut oc = ObjectCache::new(&allocator, treehash);
let calculated_hash = oc.get_or_calculate(&node).unwrap();
let ch: &[u8] = calculated_hash;
let expected_hash: Vec<u8> = Vec::from_hex(expected_hash_as_hex).unwrap();
assert_eq!(expected_hash, ch);
}

#[test]
fn test_deserialize_with_backrefs() {
fn deserialize_check(serialization_as_hex: &str, expected_hash_as_hex: &str) {
use crate::serde::object_cache::{treehash, ObjectCache};
let buf = Vec::from_hex(serialization_as_hex).unwrap();
let mut allocator = Allocator::new();
let node = node_from_bytes_backrefs(&mut allocator, &buf).unwrap();

let mut oc = ObjectCache::new(&allocator, treehash);
let calculated_hash = oc.get_or_calculate(&node).unwrap();
let ch: &[u8] = calculated_hash;
let expected_hash: Vec<u8> = Vec::from_hex(expected_hash_as_hex).unwrap();
assert_eq!(expected_hash, ch);
}

// ("foobar" "foobar")
deserialize_check(
"ff86666f6f626172ff86666f6f62617280",
Expand Down

0 comments on commit 6284d54

Please sign in to comment.