Skip to content

Commit

Permalink
feat(primitives): supports test for from_compact (#5312)
Browse files Browse the repository at this point in the history
  • Loading branch information
DoTheBestToGetTheBest authored Nov 5, 2023
1 parent 1aca4b0 commit 2d315c2
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions crates/primitives/src/transaction/tx_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,34 @@ impl Compact for TxType {
)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_txtype_from_compact() {
let cases = vec![
(TxType::Legacy, 0, vec![]),
(TxType::EIP2930, 1, vec![]),
(TxType::EIP1559, 2, vec![]),
(TxType::EIP4844, 3, vec![EIP4844_TX_TYPE_ID]),
#[cfg(feature = "optimism")]
(TxType::DEPOSIT, 3, vec![DEPOSIT_TX_TYPE_ID]),
];

for (expected_type, identifier, buf) in cases {
let (actual_type, remaining_buf) = TxType::from_compact(&buf, identifier);
assert_eq!(
actual_type, expected_type,
"Unexpected TxType for identifier {}",
identifier
);
assert!(
remaining_buf.is_empty(),
"Buffer not fully consumed for identifier {}",
identifier
);
}
}
}

0 comments on commit 2d315c2

Please sign in to comment.