Skip to content

Commit

Permalink
fix(protocol): std leaking into tests (#241)
Browse files Browse the repository at this point in the history
### Description

Fixes the `maili-protocol` crate to not have `std` leaking into tests.

Closes #224
  • Loading branch information
refcell authored Feb 11, 2025
1 parent 64066b7 commit e61aa2e
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions crates/protocol/src/batch/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl Batch {
mod tests {
use super::*;
use crate::{SpanBatchElement, SpanBatchError, SpanBatchTransactions};
use alloc::{vec, vec::Vec};
use alloy_consensus::{Signed, TxEip2930, TxEnvelope};
use alloy_primitives::{address, hex, Bytes, PrimitiveSignature as Signature, TxKind};

Expand Down
1 change: 1 addition & 0 deletions crates/protocol/src/batch/inclusion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl BatchWithInclusionBlock {
mod tests {
use super::*;
use crate::test_utils::TestBatchValidator;
use alloc::vec;

#[tokio::test]
async fn test_single_batch_with_inclusion_block() {
Expand Down
1 change: 1 addition & 0 deletions crates/protocol/src/batch/single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ impl SingleBatch {
#[cfg(test)]
mod tests {
use super::*;
use alloc::vec;
use alloy_consensus::{SignableTransaction, TxEip1559, TxEip7702, TxEnvelope};
use alloy_eips::eip2718::{Decodable2718, Encodable2718};
use alloy_primitives::{Address, PrimitiveSignature, Sealed, TxKind, U256};
Expand Down
1 change: 1 addition & 0 deletions crates/protocol/src/batch/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ impl SpanBatchTransactions {
#[cfg(test)]
mod tests {
use super::*;
use alloc::vec;
use alloy_consensus::{Signed, TxEip1559, TxEip2930, TxEip7702};
use alloy_primitives::{address, PrimitiveSignature as Signature, TxKind};

Expand Down
2 changes: 1 addition & 1 deletion crates/protocol/src/batch/tx_data/eip7702.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl SpanBatchEip7702TransactionData {
mod test {
use super::*;
use crate::SpanBatchTransactionData;
use alloc::vec::Vec;
use alloc::{vec, vec::Vec};
use alloy_rlp::{Decodable, Encodable};
use revm::primitives::Authorization;

Expand Down
5 changes: 3 additions & 2 deletions crates/protocol/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use op_alloy_consensus::OpBlock;

/// Block Header Info
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq, Default)]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct BlockInfo {
Expand Down Expand Up @@ -78,7 +78,7 @@ pub struct L2BlockInfo {
pub seq_num: u64,
}

#[cfg(any(test, feature = "arbitrary"))]
#[cfg(feature = "arbitrary")]
impl arbitrary::Arbitrary<'_> for L2BlockInfo {
fn arbitrary(g: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> {
Ok(Self {
Expand Down Expand Up @@ -173,6 +173,7 @@ impl L2BlockInfo {
#[cfg(test)]
mod tests {
use super::*;
use alloc::string::ToString;
use alloy_consensus::{Header, TxEnvelope};
use alloy_primitives::b256;

Expand Down
1 change: 1 addition & 0 deletions crates/protocol/src/info/bedrock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl L1BlockInfoBedrock {
#[cfg(test)]
mod tests {
use super::*;
use alloc::vec;

#[test]
fn test_decode_calldata_bedrock_invalid_length() {
Expand Down
1 change: 1 addition & 0 deletions crates/protocol/src/info/ecotone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ impl L1BlockInfoEcotone {
#[cfg(test)]
mod tests {
use super::*;
use alloc::vec;

#[test]
fn test_decode_calldata_ecotone_invalid_length() {
Expand Down
1 change: 1 addition & 0 deletions crates/protocol/src/info/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ impl L1BlockInfoInterop {
#[cfg(test)]
mod tests {
use super::*;
use alloc::vec;

#[test]
fn test_decode_calldata_interop_invalid_length() {
Expand Down
1 change: 1 addition & 0 deletions crates/protocol/src/info/isthmus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ impl L1BlockInfoIsthmus {
#[cfg(test)]
mod tests {
use super::*;
use alloc::vec;

#[test]
fn test_decode_calldata_isthmus_invalid_length() {
Expand Down
2 changes: 1 addition & 1 deletion crates/protocol/src/info/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ mod test {
use crate::test_utils::{
RAW_BEDROCK_INFO_TX, RAW_ECOTONE_INFO_TX, RAW_INTEROP_INFO_TX, RAW_ISTHMUS_INFO_TX,
};
use alloc::string::ToString;
use alloc::{string::ToString, vec::Vec};
use alloy_primitives::{address, b256};

#[test]
Expand Down
1 change: 1 addition & 0 deletions crates/protocol/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl Iterator for FrameIter<'_> {
#[cfg(test)]
mod tests {
use super::*;
use alloc::{vec, vec::Vec};

#[test]
fn test_iterate_none() {
Expand Down
2 changes: 1 addition & 1 deletion crates/protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

Expand Down
4 changes: 2 additions & 2 deletions crates/protocol/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ pub fn read_tx_data(r: &mut &[u8]) -> Result<(Vec<u8>, TxType), SpanBatchError>
mod tests {
use super::*;
use crate::test_utils::{RAW_BEDROCK_INFO_TX, RAW_ECOTONE_INFO_TX, RAW_ISTHMUS_INFO_TX};
use alloc::vec;
use alloy_eips::eip1898::BlockNumHash;
use alloy_primitives::{address, hex, uint, U256};
use maili_genesis::ChainGenesis;
Expand Down Expand Up @@ -223,7 +224,6 @@ mod tests {

#[test]
fn test_to_system_config_non_deposit() {
use alloy_primitives::U256;
let block = OpBlock {
header: alloy_consensus::Header { number: 1, ..Default::default() },
body: alloy_consensus::BlockBody {
Expand All @@ -235,7 +235,7 @@ mod tests {
gas_price: 1,
gas_limit: 1,
to: alloy_primitives::TxKind::Create,
value: alloy_primitives::U256::ZERO,
value: U256::ZERO,
input: alloy_primitives::Bytes::new(),
},
alloy_primitives::PrimitiveSignature::new(U256::ZERO, U256::ZERO, false),
Expand Down

0 comments on commit e61aa2e

Please sign in to comment.