Skip to content

Commit

Permalink
Add test for revm::optimism::L1BlockInfo::calculate_tx_l1_cost_fjord (
Browse files Browse the repository at this point in the history
bluealloy#1743)

* Add test for revm::optimism::L1BlockInfo::calculate_tx_l1_cost_fjord

* Fix lint
  • Loading branch information
emhane authored Sep 3, 2024
1 parent 73366e7 commit fa5650e
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion crates/revm/src/optimism/l1block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -410,4 +410,35 @@ 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
// <https://optimistic.etherscan.io/block/124665056>
let l1_block_info = L1BlockInfo {
l1_base_fee: U256::from(1055991687),
l1_base_fee_scalar: U256::from(5227),
l1_blob_base_fee_scalar: Some(U256::from(1014213)),
l1_blob_base_fee: Some(U256::from(1)),
..Default::default() // 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)
}
}

0 comments on commit fa5650e

Please sign in to comment.