Skip to content

Commit

Permalink
Farm coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed Aug 15, 2024
1 parent 37a207e commit 4763fd8
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions tree_hash/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloy_primitives::{U128, U256};
use ssz_derive::Encode;
use tree_hash::{Hash256, MerkleHasher, PackedEncoding, TreeHash, BYTES_PER_CHUNK};
use tree_hash_derive::TreeHash;
Expand Down Expand Up @@ -130,12 +131,30 @@ fn variable_union() {
/// Test that the packed encodings for different types are equal.
#[test]
fn packed_encoding_example() {
let canonical = 0xfff0eee0ddd0ccc0_u64.tree_hash_packed_encoding();
let val = 0xfff0eee0ddd0ccc0bbb0aaa099908880_u128;
let canonical = U256::from(val).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),
(0x8880_u16.tree_hash_packed_encoding(), 0),
(0x9990_u16.tree_hash_packed_encoding(), 2),
(0xaaa0_u16.tree_hash_packed_encoding(), 4),
(0xbbb0_u16.tree_hash_packed_encoding(), 6),
(0xccc0_u16.tree_hash_packed_encoding(), 8),
(0xddd0_u16.tree_hash_packed_encoding(), 10),
(0xeee0_u16.tree_hash_packed_encoding(), 12),
(0xfff0_u16.tree_hash_packed_encoding(), 14),
(U128::from(val).tree_hash_packed_encoding(), 0),
(U128::from(0).tree_hash_packed_encoding(), 16),
(
Hash256::from_slice(U256::from(val).as_le_slice()).tree_hash_packed_encoding(),
0,
),
(
Hash256::from_slice(U256::from(val).as_le_slice())
.tree_hash_root()
.to_vec()
.into(),
0,
),
];
for (i, (encoding, offset)) in encodings.into_iter().enumerate() {
assert_eq!(
Expand Down

0 comments on commit 4763fd8

Please sign in to comment.