reth_optimism_primitives/transaction/
tx_type.rs
1pub use op_alloy_consensus::OpTxType;
4
5#[cfg(test)]
6mod tests {
7 use super::*;
8 use alloy_consensus::constants::EIP7702_TX_TYPE_ID;
9 use op_alloy_consensus::DEPOSIT_TX_TYPE_ID;
10 use reth_codecs::{txtype::*, Compact};
11 use rstest::rstest;
12
13 #[rstest]
14 #[case(OpTxType::Legacy, COMPACT_IDENTIFIER_LEGACY, vec![])]
15 #[case(OpTxType::Eip2930, COMPACT_IDENTIFIER_EIP2930, vec![])]
16 #[case(OpTxType::Eip1559, COMPACT_IDENTIFIER_EIP1559, vec![])]
17 #[case(OpTxType::Eip7702, COMPACT_EXTENDED_IDENTIFIER_FLAG, vec![EIP7702_TX_TYPE_ID])]
18 #[case(OpTxType::Deposit, COMPACT_EXTENDED_IDENTIFIER_FLAG, vec![DEPOSIT_TX_TYPE_ID])]
19 fn test_txtype_to_compact(
20 #[case] tx_type: OpTxType,
21 #[case] expected_identifier: usize,
22 #[case] expected_buf: Vec<u8>,
23 ) {
24 let mut buf = vec![];
25 let identifier = tx_type.to_compact(&mut buf);
26
27 assert_eq!(
28 identifier, expected_identifier,
29 "Unexpected identifier for OpTxType {tx_type:?}",
30 );
31 assert_eq!(buf, expected_buf, "Unexpected buffer for OpTxType {tx_type:?}",);
32 }
33
34 #[rstest]
35 #[case(OpTxType::Legacy, COMPACT_IDENTIFIER_LEGACY, vec![])]
36 #[case(OpTxType::Eip2930, COMPACT_IDENTIFIER_EIP2930, vec![])]
37 #[case(OpTxType::Eip1559, COMPACT_IDENTIFIER_EIP1559, vec![])]
38 #[case(OpTxType::Eip7702, COMPACT_EXTENDED_IDENTIFIER_FLAG, vec![EIP7702_TX_TYPE_ID])]
39 #[case(OpTxType::Deposit, COMPACT_EXTENDED_IDENTIFIER_FLAG, vec![DEPOSIT_TX_TYPE_ID])]
40 fn test_txtype_from_compact(
41 #[case] expected_type: OpTxType,
42 #[case] identifier: usize,
43 #[case] buf: Vec<u8>,
44 ) {
45 let (actual_type, remaining_buf) = OpTxType::from_compact(&buf, identifier);
46
47 assert_eq!(actual_type, expected_type, "Unexpected TxType for identifier {identifier}");
48 assert!(remaining_buf.is_empty(), "Buffer not fully consumed for identifier {identifier}");
49 }
50}