Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sdk): Add MaybeArbitrary as super trait #12661

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/optimism/primitives/src/tx_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ use reth_primitives_traits::{InMemorySize, TxType};
#[into(u8)]
pub struct OpTxType(AlloyOpTxType);

impl<'a> reth_primitives::arbitrary::Arbitrary<'a> for OpTxType {
fn arbitrary(
u: &mut reth_primitives::arbitrary::Unstructured<'a>,
) -> reth_primitives::arbitrary::Result<Self> {
Ok(AlloyOpTxType::arbitrary(u)?.into())
}
}

impl TxType for OpTxType {
#[inline]
fn is_legacy(&self) -> bool {
Expand Down
3 changes: 2 additions & 1 deletion crates/primitives-traits/src/block/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use alloc::fmt;
use alloy_consensus::Transaction;
use reth_codecs::Compact;

use crate::{FullSignedTx, InMemorySize, MaybeSerde};
use crate::{FullSignedTx, InMemorySize, MaybeArbitrary, MaybeSerde};

/// Helper trait that unifies all behaviour required by transaction to support full node operations.
pub trait FullBlockBody: BlockBody<Transaction: FullSignedTx> + Compact {}
Expand All @@ -27,6 +27,7 @@ pub trait BlockBody:
+ alloy_rlp::Decodable
+ InMemorySize
+ MaybeSerde
+ MaybeArbitrary
{
/// Ordered list of signed transactions as committed in block.
// todo: requires trait for signed transaction
Expand Down
4 changes: 3 additions & 1 deletion crates/primitives-traits/src/block/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::fmt;
use alloy_primitives::Sealable;
use reth_codecs::Compact;

use crate::{InMemorySize, MaybeSerde};
use crate::{InMemorySize, MaybeArbitrary, MaybeSerde};

/// Helper trait that unifies all behaviour required by block header to support full node
/// operations.
Expand All @@ -29,6 +29,7 @@ pub trait BlockHeader:
+ Sealable
+ InMemorySize
+ MaybeSerde
+ MaybeArbitrary
{
}

Expand All @@ -47,5 +48,6 @@ impl<T> BlockHeader for T where
+ Sealable
+ InMemorySize
+ MaybeSerde
+ MaybeArbitrary
{
}
4 changes: 2 additions & 2 deletions crates/primitives-traits/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use alloc::fmt;

use reth_codecs::Compact;

use crate::{BlockHeader, FullBlockHeader, InMemorySize, MaybeSerde};
use crate::{BlockHeader, FullBlockHeader, InMemorySize, MaybeSerde, MaybeArbitrary};

/// Helper trait that unifies all behaviour required by block to support full node operations.
pub trait FullBlock: Block<Header: Compact> {}
Expand All @@ -20,7 +20,7 @@ impl<T> FullBlock for T where T: Block<Header: FullBlockHeader> {}
// senders
#[auto_impl::auto_impl(&, Arc)]
pub trait Block:
Send + Sync + Unpin + Clone + Default + fmt::Debug + PartialEq + Eq + InMemorySize + MaybeSerde
Send + Sync + Unpin + Clone + Default + fmt::Debug + PartialEq + Eq + InMemorySize + MaybeSerde + MaybeArbitrary
{
/// Header part of the block.
type Header: BlockHeader + 'static;
Expand Down
9 changes: 6 additions & 3 deletions crates/primitives-traits/src/header/sealed.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::InMemorySize;
use crate::{InMemorySize, MaybeArbitrary};
pub use alloy_consensus::Header;
use alloy_consensus::Sealed;
use alloy_eips::BlockNumHash;
Expand Down Expand Up @@ -156,9 +156,12 @@ impl<H> From<SealedHeader<H>> for Sealed<H> {
}

#[cfg(any(test, feature = "arbitrary"))]
impl<'a> arbitrary::Arbitrary<'a> for SealedHeader {
impl<'a, H> arbitrary::Arbitrary<'a> for SealedHeader<H>
where
H: MaybeArbitrary + Sealable,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
let header = Header::arbitrary(u)?;
let header = H::arbitrary(u)?;

Ok(Self::seal(header))
}
Expand Down
3 changes: 2 additions & 1 deletion crates/primitives-traits/src/receipt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Receipt abstraction

use crate::{InMemorySize, MaybeSerde};
use crate::{InMemorySize, MaybeSerde, MaybeArbitrary};
use alloc::vec::Vec;
use alloy_consensus::TxReceipt;
use alloy_primitives::B256;
Expand All @@ -26,6 +26,7 @@ pub trait Receipt:
+ alloy_rlp::Decodable
+ MaybeSerde
+ InMemorySize
+ MaybeArbitrary
{
/// Returns transaction type.
fn tx_type(&self) -> u8;
Expand Down
3 changes: 2 additions & 1 deletion crates/primitives-traits/src/tx_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::fmt;
use alloy_primitives::{U64, U8};
use reth_codecs::Compact;

use crate::InMemorySize;
use crate::{InMemorySize, MaybeArbitrary};

/// Helper trait that unifies all behaviour required by transaction type ID to support full node
/// operations.
Expand Down Expand Up @@ -32,6 +32,7 @@ pub trait TxType:
+ alloy_rlp::Encodable
+ alloy_rlp::Decodable
+ InMemorySize
+ MaybeArbitrary
{
/// Returns `true` if this is a legacy transaction.
fn is_legacy(&self) -> bool;
Expand Down