mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-23 14:54:45 +00:00
Add tests for excess bytes in SSZ
This commit is contained in:
@@ -106,6 +106,22 @@ mod round_trip {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fixed_len_excess_bytes() {
|
||||
let fixed = FixedLen { a: 1, b: 2, c: 3 };
|
||||
|
||||
let mut bytes = fixed.as_ssz_bytes();
|
||||
bytes.append(&mut vec![0]);
|
||||
|
||||
assert_eq!(
|
||||
FixedLen::from_ssz_bytes(&bytes),
|
||||
Err(DecodeError::InvalidByteLength {
|
||||
len: 15,
|
||||
expected: 14,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vec_of_fixed_len_struct() {
|
||||
let items: Vec<FixedLen> = vec![
|
||||
@@ -138,6 +154,22 @@ mod round_trip {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn variable_len_excess_bytes() {
|
||||
let variable = VariableLen {
|
||||
a: 1,
|
||||
b: vec![2],
|
||||
c: 3,
|
||||
};
|
||||
|
||||
let mut bytes = variable.as_ssz_bytes();
|
||||
bytes.append(&mut vec![0]);
|
||||
|
||||
// The error message triggered is not so helpful, it's caught by a side-effect. Just
|
||||
// checking there is _some_ error is fine.
|
||||
assert!(VariableLen::from_ssz_bytes(&bytes).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn first_offset_skips_byte() {
|
||||
let bytes = vec![
|
||||
|
||||
Reference in New Issue
Block a user