Skip to content

Commit

Permalink
fix vec of type with buf (paradigmxyz#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshieDo committed Jan 5, 2023
1 parent e069248 commit 528c19f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/storage/codecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ where
let mut element = T::default();

let len = buf.get_u16();
(element, buf) = T::from_compact(buf, len as usize);

(element, _) = T::from_compact(&buf[..(len as usize)], len as usize);
buf.advance(len as usize);

list.push(element);
}
Expand Down Expand Up @@ -161,7 +163,9 @@ where
}

let len = buf.get_u16();
let (element, buf) = T::from_compact(buf, len as usize);

let (element, _) = T::from_compact(&buf[..(len as usize)], len as usize);
buf.advance(len as usize);

(Some(element), buf)
}
Expand Down
13 changes: 13 additions & 0 deletions crates/storage/db/src/tables/models/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ impl_fixed_arbitrary!(BlockNumHash, 40);

#[cfg(test)]
mod test {
use crate::table::{Compress, Decompress};

use super::*;
use rand::{thread_rng, Rng};

Expand Down Expand Up @@ -155,4 +157,15 @@ mod test {
let key = BlockNumHash::arbitrary(&mut Unstructured::new(&bytes)).unwrap();
assert_eq!(bytes, Encode::encode(key));
}

#[test]
fn test_ommer() {
let mut ommer = StoredBlockOmmers::default();
ommer.ommers.push(Header::default());
ommer.ommers.push(Header::default());
assert!(
ommer.clone() ==
StoredBlockOmmers::decompress::<Vec<_>>(ommer.compress().into()).unwrap()
);
}
}

0 comments on commit 528c19f

Please sign in to comment.