From d64f6bb6dd25af078535b070d4be7f07e92daee1 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Mon, 2 Sep 2024 21:14:03 +0200 Subject: [PATCH] Add test for revm::optimism::L1BlockInfo::calculate_tx_l1_cost_fjord --- crates/revm/src/optimism/l1block.rs | 32 ++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/crates/revm/src/optimism/l1block.rs b/crates/revm/src/optimism/l1block.rs index 86e32850fa..138afa2784 100644 --- a/crates/revm/src/optimism/l1block.rs +++ b/crates/revm/src/optimism/l1block.rs @@ -244,7 +244,7 @@ impl L1BlockInfo { #[cfg(test)] mod tests { use super::*; - use crate::primitives::bytes; + use crate::primitives::{bytes, hex}; #[test] fn test_data_gas_non_zero_bytes() { @@ -410,4 +410,34 @@ mod tests { let gas_cost = l1_block_info.calculate_tx_l1_cost(&input, SpecId::FJORD); assert_eq!(gas_cost, U256::ZERO); } + + #[test] + fn calculate_tx_l1_cost_fjord() { + // rig + + // L1 block info for OP mainnet fjord block 124665056 + // + let mut l1_block_info = L1BlockInfo::default(); + l1_block_info.l1_base_fee = U256::from(1055991687); + l1_block_info.l1_base_fee_scalar = U256::from(5227); + l1_block_info.l1_blob_base_fee_scalar = Some(U256::from(1014213)); + l1_block_info.l1_blob_base_fee = Some(U256::from(1)); + // l1 fee overhead (l1 gas used) deprecated since Fjord + + // first tx in OP mainnet Fjord block 124665056 + // https://optimistic.etherscan.io/tx/0x1059e8004daff32caa1f1b1ef97fe3a07a8cf40508f5b835b66d9420d87c4a4a + const TX: &[u8] = &hex!("02f904940a8303fba78401d6d2798401db2b6d830493e0943e6f4f7866654c18f536170780344aa8772950b680b904246a761202000000000000000000000000087000a300de7200382b55d40045000000e5d60e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000022482ad56cb0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000dc6ff44d5d932cbd77b52e5612ba0529dc6226f1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044095ea7b300000000000000000000000021c4928109acb0659a88ae5329b5374a3024694c0000000000000000000000000000000000000000000000049b9ca9a6943400000000000000000000000000000000000000000000000000000000000000000000000000000000000021c4928109acb0659a88ae5329b5374a3024694c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000024b6b55f250000000000000000000000000000000000000000000000049b9ca9a694340000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000415ec214a3950bea839a7e6fbb0ba1540ac2076acd50820e2d5ef83d0902cdffb24a47aff7de5190290769c4f0a9c6fabf63012986a0d590b1b571547a8c7050ea1b00000000000000000000000000000000000000000000000000000000000000c080a06db770e6e25a617fe9652f0958bd9bd6e49281a53036906386ed39ec48eadf63a07f47cf51a4a40b4494cf26efc686709a9b03939e20ee27e59682f5faa536667e"); + + // L1 fee for tx, from OP mainnet block scanner + // https://optimistic.etherscan.io/tx/0x1059e8004daff32caa1f1b1ef97fe3a07a8cf40508f5b835b66d9420d87c4a4a + let expected_l1_fee = U256::from_be_bytes(hex!( + "00000000000000000000000000000000000000000000000000000005bf1ab43d" + )); + + // test + + let l1_fee = l1_block_info.calculate_tx_l1_cost_fjord(TX); + + assert_eq!(l1_fee, expected_l1_fee) + } }