From 18d28f1419173d65212baa30ff1792c501b72a2b Mon Sep 17 00:00:00 2001 From: refcell Date: Tue, 5 Nov 2024 18:31:19 -0500 Subject: [PATCH] chore(derive): pipeline error test coverage (#784) --- crates/derive/src/errors/pipeline.rs | 45 ++++++++++++++++++++++++++++ crates/derive/src/errors/sources.rs | 34 ++++++++++++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/crates/derive/src/errors/pipeline.rs b/crates/derive/src/errors/pipeline.rs index 98722fabf..23096143a 100644 --- a/crates/derive/src/errors/pipeline.rs +++ b/crates/derive/src/errors/pipeline.rs @@ -235,6 +235,51 @@ impl From 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() { diff --git a/crates/derive/src/errors/sources.rs b/crates/derive/src/errors/sources.rs index 7f47b6746..75211763e 100644 --- a/crates/derive/src/errors/sources.rs +++ b/crates/derive/src/errors/sources.rs @@ -58,4 +58,36 @@ impl From 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(_))); + } +}