Skip to content

Commit

Permalink
Add testcase for bool type (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
rongyi authored Aug 4, 2024
1 parent 8d5c6dd commit ac00e2e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/rlp/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ pub(crate) fn static_left_pad<const N: usize>(data: &[u8]) -> Result<[u8; N]> {

let mut v = [0; N];

// yes, data may empty, e.g. we decode a bool false value
if data.is_empty() {
return Ok(v);
}
Expand Down Expand Up @@ -247,6 +248,17 @@ mod tests {
}
}

#[test]
fn rlp_bool() {
let out = vec![0x80];
let val = bool::decode(&mut &out[..]);
assert_eq!(Ok(false), val);

let out = vec![0x01];
let val = bool::decode(&mut &out[..]);
assert_eq!(Ok(true), val);
}

#[test]
fn rlp_strings() {
check_decode::<Bytes, _>([
Expand Down
6 changes: 6 additions & 0 deletions crates/rlp/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ mod tests {
assert_eq!(encode(hex!("ABBA"))[..], hex!("82abba")[..]);
}

#[test]
fn rlp_bool() {
assert_eq!(encode(true), hex!("01"));
assert_eq!(encode(false), hex!("80"));
}

fn c<T, U: From<T>>(
it: impl IntoIterator<Item = (T, &'static [u8])>,
) -> impl Iterator<Item = (U, &'static [u8])> {
Expand Down

0 comments on commit ac00e2e

Please sign in to comment.