Skip to content

Commit

Permalink
test: fix decode tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samlaf committed Jan 2, 2025
1 parent 7dd7a13 commit c69886f
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions crates/eigenda/src/eigenda_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,48 @@ impl EigenDABlobData {

#[cfg(test)]
mod tests {
use crate::BLOB_ENCODING_VERSION_0;

use super::*;
use alloc::vec;
use alloy_primitives::Bytes;
use kona_derive::errors::BlobDecodingError;

fn generate_blob_data(content: &[u8]) -> EigenDABlobData {
let mut blob = vec![0; 32];
blob[1] = BLOB_ENCODING_VERSION_0;
blob[2..6].copy_from_slice(&(content.len() as u32).to_be_bytes());
blob.extend_from_slice(&helpers::convert_by_padding_empty_byte(content));
EigenDABlobData {
blob: Bytes::from(blob),
}
}

#[test]
fn test_decode_success() {
let data = EigenDABlobData {
blob: Bytes::from(vec![1, 2, 3, 4]),
};
let content = vec![1, 2, 3, 4];
let data = generate_blob_data(&content);
let result = data.decode();
assert!(result.is_ok());
assert_eq!(result.unwrap(), Bytes::from(vec![1, 2, 3, 4]));
assert_eq!(result.unwrap(), Bytes::from(content));
}

#[test]
fn test_decode_empty_blob() {
let data = EigenDABlobData {
blob: Bytes::from(vec![]),
};
fn test_decode_success_empty() {
let content = vec![];
let data = generate_blob_data(&content);
let result = data.decode();
assert!(result.is_ok());
assert_eq!(result.unwrap(), Bytes::from(vec![]));
assert_eq!(result.unwrap(), Bytes::from(content));
}

#[test]
fn test_decode_invalid_blob() {
// TODO: implement this once decode actually does something
fn test_decode_error_invalid_length() {
let data = EigenDABlobData {
blob: Bytes::from(vec![0; 31]), // one byte short of having a full header
};
let result = data.decode();
assert!(result.is_err());
assert_eq!(result.unwrap_err(), BlobDecodingError::InvalidLength);
}
}

0 comments on commit c69886f

Please sign in to comment.