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(sidecar): add basefee overflow test #746

Closed
wants to merge 3 commits into from
Closed
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
24 changes: 22 additions & 2 deletions bolt-sidecar/src/common/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use crate::{primitives::AccountState, state::ValidationError};
/// Calculates the max_basefee `slot_diff` blocks in the future given a current basefee (in wei).
/// Returns None if an overflow would occur.
/// Cfr. https://github.com/flashbots/ethers-provider-flashbots-bundle/blob/7ddaf2c9d7662bef400151e0bfc89f5b13e72b4c/src/index.ts#L308
///
/// # Overflows
/// For 10 gwei, the max slot diff is 499.
///
/// NOTE: this increase is correct also for the EIP-4844 blob base fee:
/// See https://eips.ethereum.org/EIPS/eip-4844#base-fee-per-blob-gas-update-rule
Expand Down Expand Up @@ -87,14 +90,31 @@ pub fn validate_transaction(

#[cfg(test)]
mod tests {
use alloy::consensus::constants::GWEI_TO_WEI;

use super::*;

#[test]
fn test_calculate_max_basefee() {
let current = 10_000_000_000; // 10 gwei
let current = GWEI_TO_WEI as u128 * 10; // 10 gwei
let slot_diff = 9; // 9 full blocks in the future

let result = calculate_max_basefee(current, slot_diff);
assert_eq!(result, Some(28865075793))
assert_eq!(result, Some(28865075793));

let slot_diff = 84;

let result = calculate_max_basefee(current, slot_diff);

assert!(result.is_some());

// Max slot diff is 499
let slot_diff = 500;

let result = calculate_max_basefee(current, slot_diff);

println!("result: {:?}", result);

assert!(result.is_none());
}
}