Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions crates/codec/src/decoding/v7/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ pub fn decode_v7(blob: &[u8]) -> Result<Batch, DecodingError> {
};

// decode the payload.
decode_v7_payload(buf)
decode_v7_payload(version, buf)
}

/// Decode the blob data into a [`Batch`].
pub(crate) fn decode_v7_payload(blob: &[u8]) -> Result<Batch, DecodingError> {
pub(crate) fn decode_v7_payload(version: u8, blob: &[u8]) -> Result<Batch, DecodingError> {
let buf = &mut (&*blob);

// check buf len.
Expand Down Expand Up @@ -103,7 +103,7 @@ pub(crate) fn decode_v7_payload(blob: &[u8]) -> Result<Batch, DecodingError> {
skipped_l1_message_bitmap: None,
};

Ok(Batch::new(7, None, payload))
Ok(Batch::new(version, None, payload))
}

#[cfg(test)]
Expand Down Expand Up @@ -292,6 +292,26 @@ mod tests {

assert_eq!(last_block, &expected_block);



Ok(())
}

#[test]
fn test_should_decode_v8_mock() -> eyre::Result<()> {
let blob = read_to_bytes("./testdata/blob_v7_uncompressed.bin")?;
let mut blob = blob.to_vec();
// Manually patch the version byte to 8 to simulate a v8 blob.
// BlobSliceIter skips the first byte (index 0) of every 32-byte chunk.
// So the first data byte (version) is at index 1.
blob[1] = 8;

let batch = decode_v7(&blob)?;
assert_eq!(batch.version, 8);

let blocks = batch.data.l2_blocks();
assert_eq!(blocks.len(), 4);

Ok(())
}
}
Loading