Skip to content

Commit 363b941

Browse files
author
Seulgi Kim
committed
Add test cases for rlp about hash
1 parent e50775a commit 363b941

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

util/rlp/src/impls.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,4 +378,43 @@ mod tests {
378378
let encoded = h.rlp_bytes().to_vec();
379379
assert_eq!(&[0x80 + 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], encoded.as_slice());
380380
}
381+
382+
#[test]
383+
fn vec_and_hash() {
384+
let vec: Vec<u8> = {
385+
let mut vec = Vec::with_capacity(32);
386+
for i in 0..32 {
387+
vec.push(i);
388+
}
389+
vec
390+
};
391+
let hash: H256 = {
392+
let mut hash = H256::zero();
393+
for i in 0..32 {
394+
hash[i] = i as u8;
395+
}
396+
hash
397+
};
398+
assert_eq!(vec.rlp_bytes(), hash.rlp_bytes());
399+
}
400+
401+
#[test]
402+
fn slice_and_hash() {
403+
let array: [u8; 32] = {
404+
let mut array = [0 as u8; 32];
405+
for i in 0..32 {
406+
array[i] = i as u8;
407+
}
408+
array
409+
};
410+
let slice: &[u8] = &array;
411+
let hash: H256 = {
412+
let mut hash = H256::zero();
413+
for i in 0..32 {
414+
hash[i] = i as u8;
415+
}
416+
hash
417+
};
418+
assert_eq!(slice.rlp_bytes(), hash.rlp_bytes());
419+
}
381420
}

0 commit comments

Comments
 (0)