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: remove unused MIN_LENGTH_EIPXXXX_ENCODED #9211

Merged
merged 2 commits into from
Jul 1, 2024
Merged
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
118 changes: 2 additions & 116 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,6 @@ pub(crate) static PARALLEL_SENDER_RECOVERY_THRESHOLD: Lazy<usize> =
_ => 5,
});

/// Minimum length of a rlp-encoded legacy transaction.
pub const MIN_LENGTH_LEGACY_TX_ENCODED: usize = 10;
/// Minimum length of a rlp-encoded eip2930 transaction.
pub const MIN_LENGTH_EIP2930_TX_ENCODED: usize = 14;
/// Minimum length of a rlp-encoded eip1559 transaction.
pub const MIN_LENGTH_EIP1559_TX_ENCODED: usize = 15;
/// Minimum length of a rlp-encoded eip4844 transaction.
pub const MIN_LENGTH_EIP4844_TX_ENCODED: usize = 37;
/// Minimum length of a rlp-encoded deposit transaction.
#[cfg(feature = "optimism")]
pub const MIN_LENGTH_DEPOSIT_TX_ENCODED: usize = 65;

/// A raw transaction.
///
/// Transaction types were introduced in [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718).
Expand Down Expand Up @@ -1617,12 +1605,10 @@ mod tests {
hex, sign_message,
transaction::{
from_compact_zstd_unaware, signature::Signature, to_compact_ztd_unaware, TxEip1559,
TxKind, TxLegacy, MIN_LENGTH_EIP1559_TX_ENCODED, MIN_LENGTH_EIP2930_TX_ENCODED,
MIN_LENGTH_EIP4844_TX_ENCODED, MIN_LENGTH_LEGACY_TX_ENCODED,
PARALLEL_SENDER_RECOVERY_THRESHOLD,
TxKind, TxLegacy, PARALLEL_SENDER_RECOVERY_THRESHOLD,
},
Address, Bytes, Transaction, TransactionSigned, TransactionSignedEcRecovered,
TransactionSignedNoHash, TxEip2930, TxEip4844, B256, U256,
TransactionSignedNoHash, B256, U256,
};
use alloy_primitives::{address, b256, bytes};
use alloy_rlp::{Decodable, Encodable, Error as RlpError};
Expand Down Expand Up @@ -1963,106 +1949,6 @@ mod tests {
assert_eq!(sender, address!("7e9e359edf0dbacf96a9952fa63092d919b0842b"));
}

#[test]
fn min_length_encoded_legacy_transaction() {
let transaction = TxLegacy::default();
let signature = Signature::default();

let signed_tx = TransactionSigned::from_transaction_and_signature(
Transaction::Legacy(transaction),
signature,
);

let encoded = &alloy_rlp::encode(signed_tx);
assert_eq!(
if cfg!(feature = "optimism") {
hex!("c9808080808080808080")
} else {
hex!("c98080808080801b8080")
},
&encoded[..]
);
assert_eq!(MIN_LENGTH_LEGACY_TX_ENCODED, encoded.len());

TransactionSigned::decode(&mut &encoded[..]).unwrap();
}

#[test]
fn min_length_encoded_eip2930_transaction() {
let transaction = TxEip2930::default();
let signature = Signature::default();

let signed_tx = TransactionSigned::from_transaction_and_signature(
Transaction::Eip2930(transaction),
signature,
);

let encoded = &alloy_rlp::encode(signed_tx);
assert_eq!(hex!("8d01cb80808080808080c0808080"), encoded[..]);
assert_eq!(MIN_LENGTH_EIP2930_TX_ENCODED, encoded.len());

TransactionSigned::decode(&mut &encoded[..]).unwrap();
}

#[test]
fn min_length_encoded_eip1559_transaction() {
let transaction = TxEip1559::default();
let signature = Signature::default();

let signed_tx = TransactionSigned::from_transaction_and_signature(
Transaction::Eip1559(transaction),
signature,
);

let encoded = &alloy_rlp::encode(signed_tx);
assert_eq!(hex!("8e02cc8080808080808080c0808080"), encoded[..]);
assert_eq!(MIN_LENGTH_EIP1559_TX_ENCODED, encoded.len());

TransactionSigned::decode(&mut &encoded[..]).unwrap();
}

#[test]
fn min_length_encoded_eip4844_transaction() {
let transaction = TxEip4844::default();
let signature = Signature::default();

let signed_tx = TransactionSigned::from_transaction_and_signature(
Transaction::Eip4844(transaction),
signature,
);

let encoded = alloy_rlp::encode(signed_tx);
assert_eq!(
hex!("a403e280808080809400000000000000000000000000000000000000008080c080c0808080"),
encoded[..]
);
assert_eq!(MIN_LENGTH_EIP4844_TX_ENCODED, encoded.len());

TransactionSigned::decode(&mut &encoded[..]).unwrap();
}

#[cfg(feature = "optimism")]
#[test]
fn min_length_encoded_deposit_transaction() {
use super::MIN_LENGTH_DEPOSIT_TX_ENCODED;
use crate::TxDeposit;

let transaction = TxDeposit::default();
let signature = Signature::default();

let signed_tx = TransactionSigned::from_transaction_and_signature(
Transaction::Deposit(transaction),
signature,
);

let encoded = &alloy_rlp::encode(signed_tx);

assert_eq!(b"\xb8?~\xf8<\xa0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x94\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x80\x80\x80\x80\x80\x80", &encoded[..]);
assert_eq!(MIN_LENGTH_DEPOSIT_TX_ENCODED, encoded.len());

TransactionSigned::decode(&mut &encoded[..]).unwrap();
}

#[test]
fn transaction_signed_no_hash_zstd_codec() {
// will use same signature everywhere.
Expand Down
Loading