Skip to content

Commit

Permalink
chore(derive): import hygiene (#744)
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell authored Oct 29, 2024
1 parent 155eea7 commit b77cbf3
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 27 deletions.
4 changes: 0 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions crates/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,12 @@ serde = { workspace = true, optional = true, features = ["derive"] }

# `test-utils` feature dependencies
spin = { workspace = true, optional = true }
anyhow = { workspace = true, optional = true }
alloy-rpc-client = { workspace = true, optional = true }
alloy-node-bindings = { workspace = true, optional = true }
alloy-transport-http = { workspace = true, optional = true }
tracing-subscriber = { workspace = true, optional = true, features = ["fmt"] }

[dev-dependencies]
spin.workspace = true
anyhow.workspace = true
proptest.workspace = true
serde_json.workspace = true
alloy-rpc-client.workspace = true
alloy-node-bindings.workspace = true
alloy-transport-http.workspace = true
tokio = { workspace = true, features = ["full"] }
tracing-subscriber = { workspace = true, features = ["fmt"] }
alloy-primitives = { workspace = true, features = ["rlp", "k256", "map", "arbitrary"] }
Expand All @@ -70,10 +62,5 @@ serde = [
]
test-utils = [
"dep:spin",
"dep:anyhow",
"dep:alloy-transport-http",
"dep:alloy-node-bindings",
"dep:tracing-subscriber",
"dep:alloy-rpc-client",
"alloy-transport-http/reqwest"
]
2 changes: 1 addition & 1 deletion crates/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
html_favicon_url = "https://raw.githubusercontent.com/anton-rs/kona/main/assets/favicon.ico"
)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(any(test, feature = "test-utils")), warn(unused_crate_dependencies))]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(not(test), no_std)]

extern crate alloc;
Expand Down
8 changes: 7 additions & 1 deletion crates/derive/src/test_utils/attributes_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ use async_trait::async_trait;
use op_alloy_protocol::{BlockInfo, L2BlockInfo};
use op_alloy_rpc_types_engine::OpPayloadAttributes;

/// An error returned by the [`TestAttributesBuilder`].
#[derive(derive_more::Display, Debug, PartialEq, Eq)]
pub enum TestAttributesBuilderError {}

impl core::error::Error for TestAttributesBuilderError {}

/// A mock implementation of the [`AttributesBuilder`] for testing.
#[derive(Debug, Default)]
pub struct TestAttributesBuilder {
/// The attributes to return.
pub attributes: Vec<anyhow::Result<OpPayloadAttributes>>,
pub attributes: Vec<Result<OpPayloadAttributes, TestAttributesBuilderError>>,
}

#[async_trait]
Expand Down
5 changes: 3 additions & 2 deletions crates/derive/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ pub use batch_provider::TestNextBatchProvider;

mod attributes_queue;
pub use attributes_queue::{
new_test_attributes_provider, TestAttributesBuilder, TestAttributesProvider,
new_test_attributes_provider, TestAttributesBuilder, TestAttributesBuilderError,
TestAttributesProvider,
};

mod batch_stream;
Expand All @@ -40,7 +41,7 @@ mod tracing;
pub use tracing::{CollectingLayer, TraceStorage};

mod sys_config_fetcher;
pub use sys_config_fetcher::TestSystemConfigL2Fetcher;
pub use sys_config_fetcher::{TestSystemConfigL2Fetcher, TestSystemConfigL2FetcherError};

mod frames;
pub use frames::{FrameQueueAsserter, FrameQueueBuilder};
Expand Down
21 changes: 15 additions & 6 deletions crates/derive/src/test_utils/sys_config_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use crate::traits::L2ChainProvider;
use alloc::{boxed::Box, sync::Arc};
use alloy_primitives::map::HashMap;
use anyhow::Result;
use async_trait::async_trait;
use op_alloy_consensus::OpBlock;
use op_alloy_genesis::{RollupConfig, SystemConfig};
Expand All @@ -28,26 +27,36 @@ impl TestSystemConfigL2Fetcher {
}
}

/// An error returned by the [TestSystemConfigL2Fetcher].
#[derive(derive_more::Display, Debug, PartialEq, Eq)]
pub enum TestSystemConfigL2FetcherError {
/// The system config was not found.
#[display("system config not found: {_0}")]
NotFound(u64),
}

impl core::error::Error for TestSystemConfigL2FetcherError {}

#[async_trait]
impl L2ChainProvider for TestSystemConfigL2Fetcher {
type Error = anyhow::Error;
type Error = TestSystemConfigL2FetcherError;

async fn system_config_by_number(
&mut self,
number: u64,
_: Arc<RollupConfig>,
) -> Result<SystemConfig> {
) -> Result<SystemConfig, Self::Error> {
self.system_configs
.get(&number)
.cloned()
.ok_or_else(|| anyhow::anyhow!("system config not found: {number}"))
.ok_or_else(|| TestSystemConfigL2FetcherError::NotFound(number))
}

async fn l2_block_info_by_number(&mut self, _: u64) -> Result<L2BlockInfo> {
async fn l2_block_info_by_number(&mut self, _: u64) -> Result<L2BlockInfo, Self::Error> {
unimplemented!()
}

async fn block_by_number(&mut self, _: u64) -> Result<OpBlock> {
async fn block_by_number(&mut self, _: u64) -> Result<OpBlock, Self::Error> {
unimplemented!()
}
}

0 comments on commit b77cbf3

Please sign in to comment.