Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to alloy #16

Merged
merged 8 commits into from
Aug 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add packed encoding test
  • Loading branch information
michaelsproul committed Aug 14, 2024
commit 76f3511309d3743a20ca17da7751dc52de14a5f3
19 changes: 19 additions & 0 deletions tree_hash/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -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"
);
}
}
Loading