From a9dab288bf2a0d433c1663a9e5aff1e759beafab Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Sat, 21 Dec 2024 14:13:48 +0700 Subject: [PATCH 1/5] test: add test revm-optimism --- Cargo.lock | 1 + crates/optimism/Cargo.toml | 1 + .../optimism/src/transaction/abstraction.rs | 85 +++++++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index a8a72552de..e90ef4160d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3128,6 +3128,7 @@ dependencies = [ "revm-database", "revm-inspector", "revm-precompile", + "revm-primitives", "rstest 0.23.0", "serde", ] diff --git a/crates/optimism/Cargo.toml b/crates/optimism/Cargo.toml index 6c9db89c8c..f292737af6 100644 --- a/crates/optimism/Cargo.toml +++ b/crates/optimism/Cargo.toml @@ -38,6 +38,7 @@ serde = { version = "1.0", default-features = false, features = [ [dev-dependencies] +primitives.workspace = true database.workspace = true anyhow = "1.0.89" indicatif = "0.17" diff --git a/crates/optimism/src/transaction/abstraction.rs b/crates/optimism/src/transaction/abstraction.rs index c39a3a22a7..674f4f7d6b 100644 --- a/crates/optimism/src/transaction/abstraction.rs +++ b/crates/optimism/src/transaction/abstraction.rs @@ -181,3 +181,88 @@ impl OpTxTrait for OpTransaction { } } } + +#[cfg(test)] +mod tests { + use super::*; + use revm::primitives::{Address, U256, B256}; + + // Helper macro for testing panic messages + macro_rules! assert_panic { + ($expected:expr, $($eval:tt)+) => { + let result = std::panic::catch_unwind(|| { + $($eval)+ + }); + assert!(result.is_err()); + if let Err(err) = result { + if let Some(message) = err.downcast_ref::<&str>() { + assert_eq!(*message, $expected); + } else { + panic!("Panic occurred but with unexpected message type"); + } + } + }; + } + + #[test] + fn test_deposit_transaction_type_conversion() { + let deposit_tx = OpTransactionType::Deposit; + let tx_type: TransactionType = deposit_tx.into(); + assert_eq!(tx_type, TransactionType::Custom); + + // Also test base transaction conversion + let base_tx = OpTransactionType::Base(TransactionType::Legacy); + let tx_type: TransactionType = base_tx.into(); + assert_eq!(tx_type, TransactionType::Legacy); + } + + #[test] + fn test_deposit_transaction_fields() { + let deposit = TxDeposit { + from: Address::ZERO, + to: revm::primitives::TxKind::Call(Address::ZERO), + value: U256::ZERO, + gas_limit: 0, + is_system_transaction: false, + mint: Some(0u128), + source_hash: B256::default(), + input: Default::default(), + }; + + let op_tx: OpTransaction = OpTransaction::Deposit(deposit); + + // Verify transaction type + assert_eq!(op_tx.tx_type(), OpTransactionType::Deposit); + + // Verify common fields access + assert_eq!(op_tx.common_fields().gas_limit(), 0); + assert_eq!(op_tx.kind(), revm::primitives::TxKind::Call(Address::ZERO)); + + // Verify gas related calculations + assert_eq!(op_tx.effective_gas_price(U256::from(100)), U256::from(100)); + assert_eq!(op_tx.max_fee(), 0); + } + + #[test] + fn test_deposit_transaction_type_access_panics() { + let deposit = TxDeposit { + from: Address::ZERO, + to: revm::primitives::TxKind::Call(Address::ZERO), + value: U256::ZERO, + gas_limit: 0, + is_system_transaction: false, + mint: Some(0u128), + source_hash: B256::default(), + input: Default::default(), + }; + + let op_tx: OpTransaction = OpTransaction::Deposit(deposit); + + // Test each transaction type access method + assert_panic!("Not a legacy transaction", op_tx.legacy()); + assert_panic!("Not eip2930 transaction", op_tx.eip2930()); + assert_panic!("Not a eip1559 transaction", op_tx.eip1559()); + assert_panic!("Not a eip4844 transaction", op_tx.eip4844()); + assert_panic!("Not a eip7702 transaction", op_tx.eip7702()); + } +} \ No newline at end of file From fdf000a11f2c3da77bb600e38f9c78e209022d9d Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Sat, 21 Dec 2024 14:16:42 +0700 Subject: [PATCH 2/5] bet --- Cargo.lock | 1 - crates/optimism/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e90ef4160d..a8a72552de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3128,7 +3128,6 @@ dependencies = [ "revm-database", "revm-inspector", "revm-precompile", - "revm-primitives", "rstest 0.23.0", "serde", ] diff --git a/crates/optimism/Cargo.toml b/crates/optimism/Cargo.toml index f292737af6..6c9db89c8c 100644 --- a/crates/optimism/Cargo.toml +++ b/crates/optimism/Cargo.toml @@ -38,7 +38,6 @@ serde = { version = "1.0", default-features = false, features = [ [dev-dependencies] -primitives.workspace = true database.workspace = true anyhow = "1.0.89" indicatif = "0.17" From 5ec07296b5e492c3ddda823c56bfee81c6a404ec Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Sat, 21 Dec 2024 14:30:00 +0700 Subject: [PATCH 3/5] bet --- crates/optimism/src/transaction/abstraction.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/optimism/src/transaction/abstraction.rs b/crates/optimism/src/transaction/abstraction.rs index 674f4f7d6b..a7a0fb5966 100644 --- a/crates/optimism/src/transaction/abstraction.rs +++ b/crates/optimism/src/transaction/abstraction.rs @@ -183,14 +183,17 @@ impl OpTxTrait for OpTransaction { } #[cfg(test)] +#[cfg(feature = "std")] mod tests { use super::*; use revm::primitives::{Address, U256, B256}; + use std::panic; + // Helper macro for testing panic messages macro_rules! assert_panic { ($expected:expr, $($eval:tt)+) => { - let result = std::panic::catch_unwind(|| { + let result = panic::catch_unwind(|| { $($eval)+ }); assert!(result.is_err()); From 57c0521d378d1545547d40379ece9e4f602988c7 Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Sat, 21 Dec 2024 14:34:35 +0700 Subject: [PATCH 4/5] bet --- crates/optimism/src/transaction/abstraction.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/crates/optimism/src/transaction/abstraction.rs b/crates/optimism/src/transaction/abstraction.rs index a7a0fb5966..796e1fa9e2 100644 --- a/crates/optimism/src/transaction/abstraction.rs +++ b/crates/optimism/src/transaction/abstraction.rs @@ -186,10 +186,9 @@ impl OpTxTrait for OpTransaction { #[cfg(feature = "std")] mod tests { use super::*; - use revm::primitives::{Address, U256, B256}; + use revm::primitives::{Address, B256, U256}; use std::panic; - // Helper macro for testing panic messages macro_rules! assert_panic { ($expected:expr, $($eval:tt)+) => { @@ -231,16 +230,12 @@ mod tests { source_hash: B256::default(), input: Default::default(), }; - let op_tx: OpTransaction = OpTransaction::Deposit(deposit); - // Verify transaction type assert_eq!(op_tx.tx_type(), OpTransactionType::Deposit); - // Verify common fields access assert_eq!(op_tx.common_fields().gas_limit(), 0); assert_eq!(op_tx.kind(), revm::primitives::TxKind::Call(Address::ZERO)); - // Verify gas related calculations assert_eq!(op_tx.effective_gas_price(U256::from(100)), U256::from(100)); assert_eq!(op_tx.max_fee(), 0); @@ -258,9 +253,7 @@ mod tests { source_hash: B256::default(), input: Default::default(), }; - let op_tx: OpTransaction = OpTransaction::Deposit(deposit); - // Test each transaction type access method assert_panic!("Not a legacy transaction", op_tx.legacy()); assert_panic!("Not eip2930 transaction", op_tx.eip2930()); @@ -268,4 +261,4 @@ mod tests { assert_panic!("Not a eip4844 transaction", op_tx.eip4844()); assert_panic!("Not a eip7702 transaction", op_tx.eip7702()); } -} \ No newline at end of file +} From fe6cb1dce6df8ceeaadfe7c1903e7425e2aebf12 Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Mon, 23 Dec 2024 21:12:19 +0700 Subject: [PATCH 5/5] bet --- .../optimism/src/transaction/abstraction.rs | 40 ------------------- 1 file changed, 40 deletions(-) diff --git a/crates/optimism/src/transaction/abstraction.rs b/crates/optimism/src/transaction/abstraction.rs index 796e1fa9e2..27fd621b0c 100644 --- a/crates/optimism/src/transaction/abstraction.rs +++ b/crates/optimism/src/transaction/abstraction.rs @@ -183,28 +183,9 @@ impl OpTxTrait for OpTransaction { } #[cfg(test)] -#[cfg(feature = "std")] mod tests { use super::*; use revm::primitives::{Address, B256, U256}; - use std::panic; - - // Helper macro for testing panic messages - macro_rules! assert_panic { - ($expected:expr, $($eval:tt)+) => { - let result = panic::catch_unwind(|| { - $($eval)+ - }); - assert!(result.is_err()); - if let Err(err) = result { - if let Some(message) = err.downcast_ref::<&str>() { - assert_eq!(*message, $expected); - } else { - panic!("Panic occurred but with unexpected message type"); - } - } - }; - } #[test] fn test_deposit_transaction_type_conversion() { @@ -240,25 +221,4 @@ mod tests { assert_eq!(op_tx.effective_gas_price(U256::from(100)), U256::from(100)); assert_eq!(op_tx.max_fee(), 0); } - - #[test] - fn test_deposit_transaction_type_access_panics() { - let deposit = TxDeposit { - from: Address::ZERO, - to: revm::primitives::TxKind::Call(Address::ZERO), - value: U256::ZERO, - gas_limit: 0, - is_system_transaction: false, - mint: Some(0u128), - source_hash: B256::default(), - input: Default::default(), - }; - let op_tx: OpTransaction = OpTransaction::Deposit(deposit); - // Test each transaction type access method - assert_panic!("Not a legacy transaction", op_tx.legacy()); - assert_panic!("Not eip2930 transaction", op_tx.eip2930()); - assert_panic!("Not a eip1559 transaction", op_tx.eip1559()); - assert_panic!("Not a eip4844 transaction", op_tx.eip4844()); - assert_panic!("Not a eip7702 transaction", op_tx.eip7702()); - } }