Skip to content

Commit

Permalink
Rewrite reth_evm_optimism::l1::tests::sanity_l1_block_ecotone to use …
Browse files Browse the repository at this point in the history
…real data
  • Loading branch information
emhane committed Sep 4, 2024
1 parent 3146b99 commit 4a9220f
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions crates/optimism/evm/src/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ where

#[cfg(test)]
mod tests {
use reth_chainspec::OptimismHardforks;
use reth_optimism_chainspec::OP_MAINNET;
use reth_primitives::TransactionSigned;

use super::*;

#[test]
Expand All @@ -322,24 +326,39 @@ mod tests {

#[test]
fn sanity_l1_block_ecotone() {
use reth_primitives::{hex_literal::hex, Bytes, Header, TransactionSigned};
// rig

let bytes = Bytes::from_static(&hex!("7ef8f8a0b84fa363879a2159e341c50a32da3ea0d21765b7bd43db37f2e5e04e8848b1ee94deaddeaddeaddeaddeaddeaddeaddeaddead00019442000000000000000000000000000000000000158080830f424080b8a4440a5e20000f42400000000000000000000000040000000065c41f680000000000a03f6b00000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000535f4d983dea59eac60478a64ecfdcde8571e611404295350de7ed4ccb404296c1a84ab7a00000000000000000000000073b4168cc87f35cc239200a20eb841cded23493b"));
let l1_info_tx = TransactionSigned::decode_enveloped(&mut bytes.as_ref()).unwrap();
let mock_block = Block {
header: Header::default(),
body: vec![l1_info_tx],
ommers: Vec::default(),
withdrawals: None,
requests: None,
};
// OP mainnet ecotone block 118024092
// <https://optimistic.etherscan.io/block/118024092>
const TIMESTAMP: u64 = 1711603765;
assert!(OP_MAINNET.is_ecotone_active_at_timestamp(TIMESTAMP));

let l1_info: L1BlockInfo = extract_l1_info(&mock_block).unwrap();
assert_eq!(l1_info.l1_base_fee, U256::from(8));
assert_eq!(l1_info.l1_base_fee_scalar, U256::from(4));
assert_eq!(l1_info.l1_blob_base_fee, Some(U256::from(22_380_075_395u64)));
assert_eq!(l1_info.l1_blob_base_fee_scalar, Some(U256::from(0)));
assert_eq!(l1_info.l1_fee_overhead, None);
// First transaction in OP mainnet block 118024092
//
// https://optimistic.etherscan.io/getRawTx?tx=0x88501da5d5ca990347c2193be90a07037af1e3820bb40774c8154871c7669150
const TX: [u8; 251] = hex!("7ef8f8a0a539eb753df3b13b7e386e147d45822b67cb908c9ddc5618e3dbaa22ed00850b94deaddeaddeaddeaddeaddeaddeaddeaddead00019442000000000000000000000000000000000000158080830f424080b8a4440a5e2000000558000c5fc50000000000000000000000006605a89f00000000012a10d90000000000000000000000000000000000000000000000000000000af39ac3270000000000000000000000000000000000000000000000000000000d5ea528d24e582fa68786f080069bdbfe06a43f8e67bfd31b8e4d8a8837ba41da9a82a54a0000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f32985");

let tx = TransactionSigned::decode_enveloped(&mut TX.as_slice()).unwrap();
let block = Block { body: vec![tx], ..Default::default() };

// expected l1 block info
let expected_l1_base_fee = U256::from_be_bytes(hex!(
"0000000000000000000000000000000000000000000000000000000af39ac327" // 47036678951
));
let expected_l1_base_fee_scalar = U256::from(1368);
let expected_l1_blob_base_fee = U256::from_be_bytes(hex!(
"0000000000000000000000000000000000000000000000000000000d5ea528d2" // 57422457042
));
let expecte_l1_blob_base_fee_scalar = U256::from(810949);

// test

let l1_block_info: L1BlockInfo = extract_l1_info(&block).unwrap();

assert_eq!(l1_block_info.l1_base_fee, expected_l1_base_fee);
assert_eq!(l1_block_info.l1_base_fee_scalar, expected_l1_base_fee_scalar);
assert_eq!(l1_block_info.l1_blob_base_fee, Some(expected_l1_blob_base_fee));
assert_eq!(l1_block_info.l1_blob_base_fee_scalar, Some(expecte_l1_blob_base_fee_scalar));
}

#[test]
Expand Down

0 comments on commit 4a9220f

Please sign in to comment.