Skip to content

Commit

Permalink
fix(alloy-eips): SimpleCoder::decode_one() should return Ok(None)
Browse files Browse the repository at this point in the history
  • Loading branch information
StackOverflowExcept1on committed Dec 22, 2024
1 parent 24ab11e commit 7baf239
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions crates/eips/src/eip4844/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,12 @@ impl SimpleCoder {
/// Decode an some bytes from an iterator of valid FEs.
///
/// Returns `Ok(Some(data))` if there is some data.
/// Returns `Ok(None)` if there is no data (length prefix is 0).
/// Returns `Ok(None)` if there is no data (empty iterator, length prefix is 0).
/// Returns `Err(())` if there is an error.
fn decode_one<'a>(mut fes: impl Iterator<Item = WholeFe<'a>>) -> Result<Option<Vec<u8>>, ()> {
let first = fes.next().ok_or(())?;
let Some(first) = fes.next() else {
return Ok(None);
};
let mut num_bytes = u64::from_be_bytes(first.as_ref()[1..9].try_into().unwrap()) as usize;

// if no more bytes is 0, we're done
Expand Down Expand Up @@ -434,6 +436,17 @@ mod tests {
assert_eq!(decoded, data);
}

#[test]
fn big_ingestion_strategy() {
let data = vec![1u8; 126_945];
let builder = SidecarBuilder::<SimpleCoder>::from_slice(&data);

let blobs = builder.take();
let decoded = SimpleCoder.decode_all(&blobs).unwrap().concat();

assert_eq!(decoded, data);
}

#[test]
fn it_ingests() {
// test ingesting a lot of data.
Expand Down

0 comments on commit 7baf239

Please sign in to comment.