Skip to content
32 changes: 29 additions & 3 deletions crates/cold/src/conformance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
//! a custom backend, call the test functions with your backend instance.

use crate::{
BlockData, ColdResult, ColdStorage, ColdStorageBackend, ColdStorageError, Filter,
HeaderSpecifier, ReceiptSpecifier, RpcLog, TransactionSpecifier,
BlockData, ColdResult, ColdStorage, ColdStorageBackend, ColdStorageError,
DynColdStorageBackend, Filter, HeaderSpecifier, ReceiptSpecifier, RpcLog, TransactionSpecifier,
};
use alloy::{
consensus::{
Expand All @@ -17,7 +17,7 @@ use alloy::{
},
};
use signet_storage_types::{Receipt, RecoveredTx, TransactionSigned};
use std::time::Duration;
use std::{sync::Arc, time::Duration};
use tokio_stream::StreamExt;
use tokio_util::sync::CancellationToken;

Expand All @@ -43,6 +43,32 @@ pub async fn conformance<B: ColdStorageBackend>(backend: B) -> ColdResult<()> {
Ok(())
}

/// Run the conformance suite against `backend` after erasing it
/// through [`DynColdStorageBackend`].
///
/// Exercises the same contract as [`conformance`] but routes every
/// call through `Arc<dyn DynColdStorageBackend>`, validating that
/// the erased dispatch path upholds the trait contract.
pub async fn conformance_erased<B: ColdStorageBackend>(backend: B) -> ColdResult<()> {
let erased: Arc<dyn DynColdStorageBackend> = Arc::new(backend);
let cancel = CancellationToken::new();
let handle = ColdStorage::new(erased, cancel.clone());
test_empty_storage(&handle).await?;
test_append_and_read_header(&handle).await?;
test_header_hash_lookup(&handle).await?;
test_transaction_lookups(&handle).await?;
test_receipt_lookups(&handle).await?;
test_truncation(&handle).await?;
test_batch_append(&handle).await?;
test_confirmation_metadata(&handle).await?;
test_cold_receipt_metadata(&handle).await?;
test_get_logs(&handle).await?;
test_stream_logs(&handle).await?;
test_drain_above(&handle).await?;
cancel.cancel();
Ok(())
}

/// Create test block data for conformance tests.
///
/// Creates a minimal valid block with the given block number.
Expand Down
Loading