Skip to content

Commit 7b9cdfb

Browse files
committed
feat: refactor test and remove unsued error enum
1 parent 8d156cc commit 7b9cdfb

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

src/error.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,14 @@ pub enum ScannerError {
3535

3636
#[error("Operation timed out")]
3737
Timeout,
38-
39-
#[error("RPC call failed after exhausting all retry attempts: {0}")]
40-
RetryFailure(Arc<RpcError<TransportErrorKind>>),
41-
42-
#[error("No RPC providers support pubsub")]
43-
PubSubNotSupported,
4438
}
4539

4640
impl From<RobustProviderError> for ScannerError {
4741
fn from(error: RobustProviderError) -> ScannerError {
4842
match error {
4943
RobustProviderError::Timeout => ScannerError::Timeout,
50-
RobustProviderError::RetryFailure(err) => ScannerError::RetryFailure(err),
44+
RobustProviderError::RpcError(err) => ScannerError::RpcError(err),
5145
RobustProviderError::BlockNotFound(block) => ScannerError::BlockNotFound(block),
52-
RobustProviderError::PubSubNotSupported => ScannerError::PubSubNotSupported,
5346
}
5447
}
5548
}

src/robust_provider.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@ pub enum Error {
1818
#[error("Operation timed out")]
1919
Timeout,
2020
#[error("RPC call failed after exhausting all retry attempts: {0}")]
21-
RetryFailure(Arc<RpcError<TransportErrorKind>>),
21+
RpcError(Arc<RpcError<TransportErrorKind>>),
2222
#[error("Block not found, Block Id: {0}")]
2323
BlockNotFound(BlockId),
24-
#[error("No RPC providers support pubsub")]
25-
PubSubNotSupported,
2624
}
2725

2826
impl From<RpcError<TransportErrorKind>> for Error {
2927
fn from(err: RpcError<TransportErrorKind>) -> Self {
30-
Error::RetryFailure(Arc::new(err))
28+
Error::RpcError(Arc::new(err))
3129
}
3230
}
3331

@@ -195,8 +193,11 @@ impl<N: Network> RobustProvider<N> {
195193
/// after exhausting retries or if the call times out.
196194
pub async fn subscribe_blocks(&self) -> Result<Subscription<N::HeaderResponse>, Error> {
197195
info!("eth_subscribe called");
198-
// We need this otherwise error is not clear
199-
self.root().client().expect_pubsub_frontend();
196+
197+
self.root().client().pubsub_frontend().ok_or_else(|| {
198+
Error::from(RpcError::Transport(TransportErrorKind::PubsubUnavailable))
199+
})?;
200+
200201
let result = self
201202
.retry_with_total_timeout(
202203
move |provider| async move { provider.subscribe_blocks().await },
@@ -366,7 +367,7 @@ mod tests {
366367
})
367368
.await;
368369

369-
assert!(matches!(result, Err(Error::RetryFailure(_))));
370+
assert!(matches!(result, Err(Error::RpcError(_))));
370371
assert_eq!(call_count.load(Ordering::SeqCst), 3);
371372
}
372373

@@ -389,14 +390,15 @@ mod tests {
389390
async fn test_http_provider_skipped_when_pubsub_required() {
390391
let provider = test_provider(100, 3, 10);
391392

392-
let result: Result<(), Error> = provider
393-
.retry_with_total_timeout(
394-
|_| async { Ok(()) },
395-
true, // require pubsub
396-
)
397-
.await;
393+
let result = provider.subscribe_blocks().await;
394+
395+
let Err(Error::RpcError(err)) = result else {
396+
panic!("Expected Error::RpcError, got: {result:?}");
397+
};
398398

399-
// Should get PubSubNotSupported error
400-
assert!(matches!(result, Err(Error::PubSubNotSupported)));
399+
assert!(
400+
matches!(err.as_ref(), RpcError::Transport(TransportErrorKind::PubsubUnavailable)),
401+
"Expected PubsubUnavailable error, got: {err:?}",
402+
);
401403
}
402404
}

0 commit comments

Comments
 (0)