1- use alloy_consensus:: {
2- transaction:: Recovered , Signed , TxEip1559 , TxEip2930 , TxEip4844 , TxEip4844Variant , TxEip7702 ,
3- TxEnvelope , TxLegacy , TxType ,
4- } ;
5- use alloy_primitives:: Bytes ;
6- use alloy_rpc_types_eth:: Transaction ;
7- use arbitrary:: Arbitrary ;
8-
91/// Returns an arbitrary instance of the passed type.
102#[ macro_export]
113macro_rules! random {
@@ -17,58 +9,3 @@ macro_rules! random {
179 <$typ>:: arbitrary( & mut u) . unwrap( )
1810 } } ;
1911}
20-
21- /// Helper instance to build an arbitrary transaction.
22- #[ derive( Debug ) ]
23- pub struct ArbitraryTxBuilder {
24- tx : Transaction ,
25- }
26-
27- impl Default for ArbitraryTxBuilder {
28- fn default ( ) -> Self {
29- let recovered = random ! ( Recovered <TxEnvelope >) ;
30- Self {
31- tx : Transaction {
32- inner : recovered,
33- block_hash : None ,
34- block_number : None ,
35- transaction_index : None ,
36- effective_gas_price : None ,
37- } ,
38- }
39- }
40- }
41-
42- impl ArbitraryTxBuilder {
43- /// Modifies the type of the random transaction.
44- pub fn with_ty ( mut self , ty : TxType ) -> Self {
45- match ty {
46- TxType :: Legacy => * self . tx . inner . inner_mut ( ) = random ! ( Signed <TxLegacy >) . into ( ) ,
47- TxType :: Eip2930 => * self . tx . inner . inner_mut ( ) = random ! ( Signed <TxEip2930 >) . into ( ) ,
48- TxType :: Eip1559 => * self . tx . inner . inner_mut ( ) = random ! ( Signed <TxEip1559 >) . into ( ) ,
49- TxType :: Eip4844 => * self . tx . inner . inner_mut ( ) = random ! ( Signed <TxEip4844 >) . into ( ) ,
50- TxType :: Eip7702 => * self . tx . inner . inner_mut ( ) = random ! ( Signed <TxEip7702 >) . into ( ) ,
51- }
52- self
53- }
54-
55- /// Modifies the input of the random transaction.
56- pub fn with_input ( mut self , input : Bytes ) -> Self {
57- match self . tx . inner . inner_mut ( ) {
58- TxEnvelope :: Legacy ( ref mut tx) => tx. tx_mut ( ) . input = input,
59- TxEnvelope :: Eip2930 ( ref mut tx) => tx. tx_mut ( ) . input = input,
60- TxEnvelope :: Eip1559 ( ref mut tx) => tx. tx_mut ( ) . input = input,
61- TxEnvelope :: Eip4844 ( ref mut tx) => match tx. tx_mut ( ) {
62- TxEip4844Variant :: TxEip4844 ( tx) => tx. input = input,
63- TxEip4844Variant :: TxEip4844WithSidecar ( tx) => tx. tx . input = input,
64- } ,
65- TxEnvelope :: Eip7702 ( ref mut tx) => tx. tx_mut ( ) . input = input,
66- }
67- self
68- }
69-
70- /// Returns the built transaction.
71- pub fn build ( self ) -> Transaction {
72- self . tx
73- }
74- }
0 commit comments