Skip to content

Commit

Permalink
Add packed encoding test
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed Aug 14, 2024
1 parent eac7f63 commit 76f3511
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tree_hash/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,22 @@ fn variable_union() {
mix_in_selector(u8_hash_concat(2, 1), 1)
);
}

/// Test that the packed encodings for different types are equal.
#[test]
fn packed_encoding_example() {
let canonical = 0xfff0eee0ddd0ccc0_u64.tree_hash_packed_encoding();
let encodings = [
(0xccc0_u16.tree_hash_packed_encoding(), 0),
(0xddd0_u16.tree_hash_packed_encoding(), 2),
(0xeee0_u16.tree_hash_packed_encoding(), 4),
(0xfff0_u16.tree_hash_packed_encoding(), 6),
];
for (i, (encoding, offset)) in encodings.into_iter().enumerate() {
assert_eq!(
&encoding[..],
&canonical[offset..offset + encoding.len()],
"encoding {i} is wrong"
);
}
}

0 comments on commit 76f3511

Please sign in to comment.