Add input and accesslist to mock tx (#4904)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
DoTheBestToGetTheBest
2023-10-05 03:18:00 -07:00
committed by GitHub
parent 066998dc80
commit 0a36bb6045

View File

@ -13,7 +13,7 @@ use rand::{
}; };
use reth_primitives::{ use reth_primitives::{
constants::{eip4844::DATA_GAS_PER_BLOB, MIN_PROTOCOL_BASE_FEE}, constants::{eip4844::DATA_GAS_PER_BLOB, MIN_PROTOCOL_BASE_FEE},
hex, AccessList, Address, FromRecoveredPooledTransaction, FromRecoveredTransaction, hex, AccessList, Address, Bytes, FromRecoveredPooledTransaction, FromRecoveredTransaction,
IntoRecoveredTransaction, PooledTransactionsElementEcRecovered, Signature, Transaction, IntoRecoveredTransaction, PooledTransactionsElementEcRecovered, Signature, Transaction,
TransactionKind, TransactionSigned, TransactionSignedEcRecovered, TxEip1559, TxEip2930, TransactionKind, TransactionSigned, TransactionSignedEcRecovered, TxEip1559, TxEip2930,
TxEip4844, TxHash, TxLegacy, TxType, TxValue, B256, EIP1559_TX_TYPE_ID, EIP4844_TX_TYPE_ID, TxEip4844, TxHash, TxLegacy, TxType, TxValue, B256, EIP1559_TX_TYPE_ID, EIP4844_TX_TYPE_ID,
@ -91,6 +91,7 @@ pub enum MockTransaction {
gas_limit: u64, gas_limit: u64,
to: TransactionKind, to: TransactionKind,
value: U256, value: U256,
input: Bytes,
}, },
Eip1559 { Eip1559 {
hash: B256, hash: B256,
@ -101,6 +102,8 @@ pub enum MockTransaction {
gas_limit: u64, gas_limit: u64,
to: TransactionKind, to: TransactionKind,
value: U256, value: U256,
accesslist: AccessList,
input: Bytes,
}, },
Eip4844 { Eip4844 {
hash: B256, hash: B256,
@ -112,6 +115,8 @@ pub enum MockTransaction {
gas_limit: u64, gas_limit: u64,
to: TransactionKind, to: TransactionKind,
value: U256, value: U256,
accesslist: AccessList,
input: Bytes,
}, },
} }
@ -123,7 +128,8 @@ impl MockTransaction {
hash => B256; hash => B256;
sender => Address; sender => Address;
gas_limit => u64; gas_limit => u64;
value => U256 value => U256;
input => Bytes
} }
/// Returns a new legacy transaction with random address and hash and empty values /// Returns a new legacy transaction with random address and hash and empty values
@ -136,6 +142,7 @@ impl MockTransaction {
gas_limit: 0, gas_limit: 0,
to: TransactionKind::Call(Address::random()), to: TransactionKind::Call(Address::random()),
value: Default::default(), value: Default::default(),
input: Default::default(),
} }
} }
@ -150,6 +157,8 @@ impl MockTransaction {
gas_limit: 0, gas_limit: 0,
to: TransactionKind::Call(Address::random()), to: TransactionKind::Call(Address::random()),
value: Default::default(), value: Default::default(),
input: Bytes::new(),
accesslist: Default::default(),
} }
} }
@ -165,6 +174,8 @@ impl MockTransaction {
gas_limit: 0, gas_limit: 0,
to: TransactionKind::Call(Address::random()), to: TransactionKind::Call(Address::random()),
value: Default::default(), value: Default::default(),
input: Bytes::new(),
accesslist: Default::default(),
} }
} }
@ -231,6 +242,19 @@ impl MockTransaction {
} }
} }
pub fn set_accesslist(&mut self, list: AccessList) -> &mut Self {
match self {
MockTransaction::Legacy { .. } => {}
MockTransaction::Eip1559 { accesslist, .. } => {
*accesslist = list;
}
MockTransaction::Eip4844 { accesslist, .. } => {
*accesslist = list;
}
}
self
}
pub fn set_gas_price(&mut self, val: u128) -> &mut Self { pub fn set_gas_price(&mut self, val: u128) -> &mut Self {
match self { match self {
MockTransaction::Legacy { gas_price, .. } => { MockTransaction::Legacy { gas_price, .. } => {
@ -421,7 +445,11 @@ impl PoolTransaction for MockTransaction {
} }
fn access_list(&self) -> Option<&AccessList> { fn access_list(&self) -> Option<&AccessList> {
None match self {
MockTransaction::Legacy { .. } => None,
MockTransaction::Eip1559 { accesslist: accessslist, .. } => Some(accessslist),
MockTransaction::Eip4844 { accesslist: accessslist, .. } => Some(accessslist),
}
} }
fn max_priority_fee_per_gas(&self) -> Option<u128> { fn max_priority_fee_per_gas(&self) -> Option<u128> {
@ -475,7 +503,11 @@ impl PoolTransaction for MockTransaction {
} }
fn input(&self) -> &[u8] { fn input(&self) -> &[u8] {
&[] match self {
MockTransaction::Legacy { .. } => &[],
MockTransaction::Eip1559 { input, .. } => input,
MockTransaction::Eip4844 { input, .. } => input,
}
} }
fn size(&self) -> usize { fn size(&self) -> usize {
@ -512,7 +544,7 @@ impl FromRecoveredTransaction for MockTransaction {
gas_limit, gas_limit,
to, to,
value, value,
input: _, input,
}) => MockTransaction::Legacy { }) => MockTransaction::Legacy {
hash, hash,
sender, sender,
@ -521,6 +553,7 @@ impl FromRecoveredTransaction for MockTransaction {
gas_limit, gas_limit,
to, to,
value: value.into(), value: value.into(),
input,
}, },
Transaction::Eip1559(TxEip1559 { Transaction::Eip1559(TxEip1559 {
chain_id: _, chain_id: _,
@ -530,8 +563,8 @@ impl FromRecoveredTransaction for MockTransaction {
max_priority_fee_per_gas, max_priority_fee_per_gas,
to, to,
value, value,
input: _, input,
access_list: _, access_list,
}) => MockTransaction::Eip1559 { }) => MockTransaction::Eip1559 {
hash, hash,
sender, sender,
@ -541,6 +574,8 @@ impl FromRecoveredTransaction for MockTransaction {
gas_limit, gas_limit,
to, to,
value: value.into(), value: value.into(),
input,
accesslist: access_list,
}, },
Transaction::Eip4844(TxEip4844 { Transaction::Eip4844(TxEip4844 {
chain_id: _, chain_id: _,
@ -550,8 +585,8 @@ impl FromRecoveredTransaction for MockTransaction {
max_priority_fee_per_gas, max_priority_fee_per_gas,
to, to,
value, value,
input: _, input,
access_list: _, access_list,
blob_versioned_hashes: _, blob_versioned_hashes: _,
max_fee_per_blob_gas, max_fee_per_blob_gas,
}) => MockTransaction::Eip4844 { }) => MockTransaction::Eip4844 {
@ -564,6 +599,8 @@ impl FromRecoveredTransaction for MockTransaction {
gas_limit, gas_limit,
to, to,
value: value.into(), value: value.into(),
input,
accesslist: access_list,
}, },
Transaction::Eip2930 { .. } => { Transaction::Eip2930 { .. } => {
unimplemented!() unimplemented!()
@ -635,6 +672,7 @@ impl proptest::arbitrary::Arbitrary for MockTransaction {
gas_limit: *gas_limit, gas_limit: *gas_limit,
to: *to, to: *to,
value: (*value).into(), value: (*value).into(),
input: (*input).clone(),
}, },
Transaction::Eip1559(TxEip1559 { Transaction::Eip1559(TxEip1559 {
nonce, nonce,
@ -644,6 +682,7 @@ impl proptest::arbitrary::Arbitrary for MockTransaction {
to, to,
value, value,
input, input,
access_list,
.. ..
}) => MockTransaction::Eip1559 { }) => MockTransaction::Eip1559 {
sender, sender,
@ -654,6 +693,8 @@ impl proptest::arbitrary::Arbitrary for MockTransaction {
gas_limit: *gas_limit, gas_limit: *gas_limit,
to: *to, to: *to,
value: (*value).into(), value: (*value).into(),
input: (*input).clone(),
accesslist: (*access_list).clone(),
}, },
Transaction::Eip4844(TxEip4844 { Transaction::Eip4844(TxEip4844 {
nonce, nonce,
@ -664,6 +705,7 @@ impl proptest::arbitrary::Arbitrary for MockTransaction {
value, value,
input, input,
max_fee_per_blob_gas, max_fee_per_blob_gas,
access_list,
.. ..
}) => MockTransaction::Eip4844 { }) => MockTransaction::Eip4844 {
sender, sender,
@ -675,6 +717,8 @@ impl proptest::arbitrary::Arbitrary for MockTransaction {
gas_limit: *gas_limit, gas_limit: *gas_limit,
to: *to, to: *to,
value: (*value).into(), value: (*value).into(),
input: (*input).clone(),
accesslist: (*access_list).clone(),
}, },
}) })
.boxed() .boxed()