diff --git a/Cargo.lock b/Cargo.lock index bc83e0f28c..d4b6c54f72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10073,6 +10073,7 @@ dependencies = [ "reth-primitives-traits", "reth-storage-api", "revm-context", + "serde_json", "thiserror 2.0.16", ] diff --git a/crates/rpc/rpc-convert/Cargo.toml b/crates/rpc/rpc-convert/Cargo.toml index df95e0a5eb..af43e9c54a 100644 --- a/crates/rpc/rpc-convert/Cargo.toml +++ b/crates/rpc/rpc-convert/Cargo.toml @@ -45,6 +45,9 @@ thiserror.workspace = true auto_impl.workspace = true dyn-clone.workspace = true +[dev-dependencies] +serde_json.workspace = true + [features] default = [] op = [ diff --git a/crates/rpc/rpc-convert/src/transaction.rs b/crates/rpc/rpc-convert/src/transaction.rs index d7c607ca77..91b7770802 100644 --- a/crates/rpc/rpc-convert/src/transaction.rs +++ b/crates/rpc/rpc-convert/src/transaction.rs @@ -1124,35 +1124,59 @@ mod transaction_response_tests { } #[cfg(feature = "op")] - #[test] - fn test_optimism_transaction_conversion() { - use op_alloy_consensus::OpTxEnvelope; - use op_alloy_network::Optimism; - use reth_optimism_primitives::OpTransactionSigned; + mod op { + use super::*; + use crate::transaction::TryIntoTxEnv; + use revm_context::{BlockEnv, CfgEnv}; - let signed_tx = Signed::new_unchecked( - TxLegacy::default(), - Signature::new(U256::ONE, U256::ONE, false), - B256::ZERO, - ); - let envelope = OpTxEnvelope::Legacy(signed_tx); + #[test] + fn test_optimism_transaction_conversion() { + use op_alloy_consensus::OpTxEnvelope; + use op_alloy_network::Optimism; + use reth_optimism_primitives::OpTransactionSigned; - let inner_tx = Transaction { - inner: Recovered::new_unchecked(envelope, Address::ZERO), - block_hash: None, - block_number: None, - transaction_index: None, - effective_gas_price: None, - }; + let signed_tx = Signed::new_unchecked( + TxLegacy::default(), + Signature::new(U256::ONE, U256::ONE, false), + B256::ZERO, + ); + let envelope = OpTxEnvelope::Legacy(signed_tx); - let tx_response = op_alloy_rpc_types::Transaction { - inner: inner_tx, - deposit_nonce: None, - deposit_receipt_version: None, - }; + let inner_tx = Transaction { + inner: Recovered::new_unchecked(envelope, Address::ZERO), + block_hash: None, + block_number: None, + transaction_index: None, + effective_gas_price: None, + }; - let result = >::from_transaction_response(tx_response); + let tx_response = op_alloy_rpc_types::Transaction { + inner: inner_tx, + deposit_nonce: None, + deposit_receipt_version: None, + }; - assert!(result.is_ok()); + let result = >::from_transaction_response(tx_response); + + assert!(result.is_ok()); + } + + #[test] + fn test_op_into_tx_env() { + use op_alloy_rpc_types::OpTransactionRequest; + use op_revm::{transaction::OpTxTr, OpSpecId}; + use revm_context::Transaction; + + let s = r#"{"from":"0x0000000000000000000000000000000000000000","to":"0x6d362b9c3ab68c0b7c79e8a714f1d7f3af63655f","input":"0x1626ba7ec8ee0d506e864589b799a645ddb88b08f5d39e8049f9f702b3b61fa15e55fc73000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000550000002d6db27c52e3c11c1cf24072004ac75cba49b25bf45f513902e469755e1f3bf2ca8324ad16930b0a965c012a24bb1101f876ebebac047bd3b6bf610205a27171eaaeffe4b5e5589936f4e542d637b627311b0000000000000000000000","data":"0x1626ba7ec8ee0d506e864589b799a645ddb88b08f5d39e8049f9f702b3b61fa15e55fc73000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000550000002d6db27c52e3c11c1cf24072004ac75cba49b25bf45f513902e469755e1f3bf2ca8324ad16930b0a965c012a24bb1101f876ebebac047bd3b6bf610205a27171eaaeffe4b5e5589936f4e542d637b627311b0000000000000000000000","chainId":"0x7a69"}"#; + + let req: OpTransactionRequest = serde_json::from_str(s).unwrap(); + + let cfg = CfgEnv::::default(); + let block_env = BlockEnv::default(); + let tx_env = req.try_into_tx_env(&cfg, &block_env).unwrap(); + assert_eq!(tx_env.gas_limit(), block_env.gas_limit); + assert_eq!(tx_env.gas_price(), 0); + assert!(tx_env.enveloped_tx().unwrap().is_empty()); + } } }