Skip to content

Commit

Permalink
chore(derive): pipeline error test coverage (#784)
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell authored Nov 5, 2024
1 parent d1930e2 commit 18d28f1
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
45 changes: 45 additions & 0 deletions crates/derive/src/errors/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,51 @@ impl From<DepositError> for PipelineEncodingError {
#[cfg(test)]
mod tests {
use super::*;
use core::error::Error;

#[test]
fn test_pipeline_error_kind_source() {
let err = PipelineErrorKind::Temporary(PipelineError::Eof);
assert!(err.source().is_some());

let err = PipelineErrorKind::Critical(PipelineError::Eof);
assert!(err.source().is_some());

let err = PipelineErrorKind::Reset(ResetError::BadParentHash(
Default::default(),
Default::default(),
));
assert!(err.source().is_some());
}

#[test]
fn test_pipeline_error_source() {
let err = PipelineError::AttributesBuilder(BuilderError::BlockMismatch(
Default::default(),
Default::default(),
));
assert!(err.source().is_some());

let encoding_err = PipelineEncodingError::EmptyBuffer;
let err: PipelineError = encoding_err.into();
assert!(err.source().is_some());

let err = PipelineError::Eof;
assert!(err.source().is_none());
}

#[test]
fn test_pipeline_encoding_error_source() {
let err = PipelineEncodingError::DepositError(DepositError::UnexpectedTopicsLen(0));
assert!(err.source().is_some());

let err = SpanBatchError::TooBigSpanBatchSize;
let err: PipelineEncodingError = err.into();
assert!(err.source().is_some());

let err = PipelineEncodingError::EmptyBuffer;
assert!(err.source().is_none());
}

#[test]
fn test_reset_error_kinds() {
Expand Down
34 changes: 33 additions & 1 deletion crates/derive/src/errors/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,36 @@ impl From<BlobDecodingError> for BlobProviderError {
}
}

impl core::error::Error for BlobProviderError {}
impl core::error::Error for BlobProviderError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::BlobDecoding(err) => Some(err),
_ => None,
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use core::error::Error;

#[test]
fn test_blob_decoding_error_source() {
let err: BlobProviderError = BlobDecodingError::InvalidFieldElement.into();
assert!(err.source().is_some());
}

#[test]
fn test_from_blob_provider_error() {
let err: PipelineErrorKind = BlobProviderError::SlotDerivation.into();
assert!(matches!(err, PipelineErrorKind::Critical(_)));

let err: PipelineErrorKind = BlobProviderError::SidecarLengthMismatch(1, 2).into();
assert!(matches!(err, PipelineErrorKind::Critical(_)));

let err: PipelineErrorKind =
BlobProviderError::BlobDecoding(BlobDecodingError::InvalidFieldElement).into();
assert!(matches!(err, PipelineErrorKind::Critical(_)));
}
}

0 comments on commit 18d28f1

Please sign in to comment.