Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add tests for base l1 blockinfo #12609

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions crates/optimism/rpc/src/eth/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,12 @@ impl OpReceiptBuilder {

#[cfg(test)]
mod test {
use super::*;
use alloy_primitives::hex;
use op_alloy_network::eip2718::Decodable2718;
use reth_optimism_chainspec::OP_MAINNET;
use reth_optimism_chainspec::{BASE_MAINNET, OP_MAINNET};
use reth_primitives::{Block, BlockBody};

use super::*;

/// OP Mainnet transaction at index 0 in block 124665056.
///
/// <https://optimistic.etherscan.io/tx/0x312e290cf36df704a2217b015d6455396830b0ce678b860ebfcc30f41403d7b1>
Expand Down Expand Up @@ -342,4 +341,46 @@ mod test {
"incorrect l1 blob base fee scalar"
);
}

// <https://github.com/paradigmxyz/reth/issues/12177>
#[test]
fn base_receipt_gas_fields() {
// https://basescan.org/tx/0x510fd4c47d78ba9f97c91b0f2ace954d5384c169c9545a77a373cf3ef8254e6e
let system = hex!("7ef8f8a0389e292420bcbf9330741f72074e39562a09ff5a00fd22e4e9eee7e34b81bca494deaddeaddeaddeaddeaddeaddeaddeaddead00019442000000000000000000000000000000000000158080830f424080b8a4440a5e20000008dd00101c120000000000000004000000006721035b00000000014189960000000000000000000000000000000000000000000000000000000349b4dcdc000000000000000000000000000000000000000000000000000000004ef9325cc5991ce750960f636ca2ffbb6e209bb3ba91412f21dd78c14ff154d1930f1f9a0000000000000000000000005050f69a9786f081509234f1a7f4684b5e5b76c9");
let tx_0 = TransactionSigned::decode_2718(&mut &system[..]).unwrap();

let block = Block {
body: BlockBody { transactions: vec![tx_0], ..Default::default() },
..Default::default()
};
let l1_block_info =
reth_optimism_evm::extract_l1_info(&block.body).expect("should extract l1 info");

// https://basescan.org/tx/0xf9420cbaf66a2dda75a015488d37262cbfd4abd0aad7bb2be8a63e14b1fa7a94
let tx = hex!("02f86c8221058034839a4ae283021528942f16386bb37709016023232523ff6d9daf444be380841249c58bc080a001b927eda2af9b00b52a57be0885e0303c39dd2831732e14051c2336470fd468a0681bf120baf562915841a48601c2b54a6742511e535cf8f71c95115af7ff63bd");
let tx_1 = TransactionSigned::decode_2718(&mut &tx[..]).unwrap();

let receipt_meta = OpReceiptFieldsBuilder::new(1730216981)
.l1_block_info(&BASE_MAINNET, &tx_1, l1_block_info)
.expect("should parse revm l1 info")
.build();

let L1BlockInfo {
l1_gas_price,
l1_gas_used,
l1_fee,
l1_fee_scalar,
l1_base_fee_scalar,
l1_blob_base_fee,
l1_blob_base_fee_scalar,
} = receipt_meta.l1_block_info;

assert_eq!(l1_gas_price, Some(14121491676), "incorrect l1 base fee (former gas price)");
assert_eq!(l1_gas_used, Some(1600), "incorrect l1 gas used");
assert_eq!(l1_fee, Some(191150293412), "incorrect l1 fee");
assert!(l1_fee_scalar.is_none(), "incorrect l1 fee scalar");
assert_eq!(l1_base_fee_scalar, Some(2269), "incorrect l1 base fee scalar");
assert_eq!(l1_blob_base_fee, Some(1324954204), "incorrect l1 blob base fee");
assert_eq!(l1_blob_base_fee_scalar, Some(1055762), "incorrect l1 blob base fee scalar");
}
}
Loading