Skip to content

Commit

Permalink
chore: move optimism execution types test to optimism crate (#12026)
Browse files Browse the repository at this point in the history
  • Loading branch information
l1nxy authored Oct 26, 2024
1 parent a06c3af commit 019f347
Show file tree
Hide file tree
Showing 2 changed files with 423 additions and 47 deletions.
56 changes: 15 additions & 41 deletions crates/evm/execution-types/src/execution_outcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl ExecutionOutcome {
}

/// Transform block number to the index of block.
fn block_number_to_index(&self, block_number: BlockNumber) -> Option<usize> {
pub fn block_number_to_index(&self, block_number: BlockNumber) -> Option<usize> {
if self.first_block > block_number {
return None
}
Expand Down Expand Up @@ -366,12 +366,15 @@ impl From<(BlockExecutionOutput<Receipt>, BlockNumber)> for ExecutionOutcome {
#[cfg(test)]
mod tests {
use super::*;
use alloy_eips::eip7685::Requests;
use alloy_primitives::{bytes, Address, LogData, B256};
use reth_primitives::{Receipts, TxType};
use std::collections::HashMap;
#[cfg(not(feature = "optimism"))]
use alloy_primitives::bytes;
use alloy_primitives::{Address, B256};
use reth_primitives::Receipts;
#[cfg(not(feature = "optimism"))]
use reth_primitives::{LogData, TxType};

#[test]
#[cfg(not(feature = "optimism"))]
fn test_initialisation() {
// Create a new BundleState object with initial data
let bundle = BundleState::new(
Expand All @@ -387,10 +390,6 @@ mod tests {
cumulative_gas_used: 46913,
logs: vec![],
success: true,
#[cfg(feature = "optimism")]
deposit_nonce: Some(18),
#[cfg(feature = "optimism")]
deposit_receipt_version: Some(34),
})]],
};

Expand Down Expand Up @@ -444,6 +443,7 @@ mod tests {
}

#[test]
#[cfg(not(feature = "optimism"))]
fn test_block_number_to_index() {
// Create a Receipts object with a vector of receipt vectors
let receipts = Receipts {
Expand All @@ -452,10 +452,6 @@ mod tests {
cumulative_gas_used: 46913,
logs: vec![],
success: true,
#[cfg(feature = "optimism")]
deposit_nonce: Some(18),
#[cfg(feature = "optimism")]
deposit_receipt_version: Some(34),
})]],
};

Expand All @@ -482,6 +478,7 @@ mod tests {
}

#[test]
#[cfg(not(feature = "optimism"))]
fn test_get_logs() {
// Create a Receipts object with a vector of receipt vectors
let receipts = Receipts {
Expand All @@ -490,10 +487,6 @@ mod tests {
cumulative_gas_used: 46913,
logs: vec![Log::<LogData>::default()],
success: true,
#[cfg(feature = "optimism")]
deposit_nonce: Some(18),
#[cfg(feature = "optimism")]
deposit_receipt_version: Some(34),
})]],
};

Expand All @@ -517,6 +510,7 @@ mod tests {
}

#[test]
#[cfg(not(feature = "optimism"))]
fn test_receipts_by_block() {
// Create a Receipts object with a vector of receipt vectors
let receipts = Receipts {
Expand All @@ -525,10 +519,6 @@ mod tests {
cumulative_gas_used: 46913,
logs: vec![Log::<LogData>::default()],
success: true,
#[cfg(feature = "optimism")]
deposit_nonce: Some(18),
#[cfg(feature = "optimism")]
deposit_receipt_version: Some(34),
})]],
};

Expand All @@ -555,15 +545,12 @@ mod tests {
cumulative_gas_used: 46913,
logs: vec![Log::<LogData>::default()],
success: true,
#[cfg(feature = "optimism")]
deposit_nonce: Some(18),
#[cfg(feature = "optimism")]
deposit_receipt_version: Some(34),
})]
);
}

#[test]
#[cfg(not(feature = "optimism"))]
fn test_receipts_len() {
// Create a Receipts object with a vector of receipt vectors
let receipts = Receipts {
Expand All @@ -572,10 +559,6 @@ mod tests {
cumulative_gas_used: 46913,
logs: vec![Log::<LogData>::default()],
success: true,
#[cfg(feature = "optimism")]
deposit_nonce: Some(18),
#[cfg(feature = "optimism")]
deposit_receipt_version: Some(34),
})]],
};

Expand Down Expand Up @@ -616,17 +599,14 @@ mod tests {
}

#[test]
#[cfg(not(feature = "optimism"))]
fn test_revert_to() {
// Create a random receipt object
let receipt = Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![],
success: true,
#[cfg(feature = "optimism")]
deposit_nonce: Some(18),
#[cfg(feature = "optimism")]
deposit_receipt_version: Some(34),
};

// Create a Receipts object with a vector of receipt vectors
Expand Down Expand Up @@ -668,17 +648,14 @@ mod tests {
}

#[test]
#[cfg(not(feature = "optimism"))]
fn test_extend_execution_outcome() {
// Create a Receipt object with specific attributes.
let receipt = Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![],
success: true,
#[cfg(feature = "optimism")]
deposit_nonce: Some(18),
#[cfg(feature = "optimism")]
deposit_receipt_version: Some(34),
};

// Create a Receipts object containing the receipt.
Expand Down Expand Up @@ -715,17 +692,14 @@ mod tests {
}

#[test]
#[cfg(not(feature = "optimism"))]
fn test_split_at_execution_outcome() {
// Create a random receipt object
let receipt = Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![],
success: true,
#[cfg(feature = "optimism")]
deposit_nonce: Some(18),
#[cfg(feature = "optimism")]
deposit_receipt_version: Some(34),
};

// Create a Receipts object with a vector of receipt vectors
Expand Down
Loading

0 comments on commit 019f347

Please sign in to comment.