diff --git a/pallets/dynamic-evm-base-fee/src/mock.rs b/pallets/dynamic-evm-base-fee/src/mock.rs index b608979c3e..7a6a60f854 100644 --- a/pallets/dynamic-evm-base-fee/src/mock.rs +++ b/pallets/dynamic-evm-base-fee/src/mock.rs @@ -173,7 +173,7 @@ pub fn get_ideal_bfpg() -> U256 { ) } -/// Max step limit described how much `base fee per gas` can move in any direction during one block. +/// Max step limit describes how much `base fee per gas` can move in any direction during one block. pub fn get_max_step_limit() -> U256 { let bfpg: u128 = BaseFeePerGas::::get().unique_saturated_into(); let max_allowed_step: u128 = ::StepLimitRatio::get() * bfpg; diff --git a/pallets/dynamic-evm-base-fee/src/tests.rs b/pallets/dynamic-evm-base-fee/src/tests.rs index 754b1a3bf0..76dc929235 100644 --- a/pallets/dynamic-evm-base-fee/src/tests.rs +++ b/pallets/dynamic-evm-base-fee/src/tests.rs @@ -146,8 +146,8 @@ fn unit_adjustment_factor_no_change() { fn bfpg_bounds_are_respected() { ExtBuilder::build().execute_with(|| { // Lower bound - let lower_bfpg = ::MinBaseFeePerGas::get(); - BaseFeePerGas::::set(lower_bfpg); + let min_bfpg = ::MinBaseFeePerGas::get(); + BaseFeePerGas::::set(min_bfpg); // This should bring the ideal bfpg value to zero set_adjustment_factor(FixedU128::zero()); @@ -156,7 +156,7 @@ fn bfpg_bounds_are_respected() { DynamicEvmBaseFee::on_finalize(1); assert_eq!( BaseFeePerGas::::get(), - lower_bfpg, + min_bfpg, "bfpg must not go below lower threshold." ); @@ -181,29 +181,49 @@ fn bfpg_bounds_are_respected() { fn step_limit_ratio_is_respected() { ExtBuilder::build().execute_with(|| { // Lower bound, high adjustment factor - let lower_bfpg = ::MinBaseFeePerGas::get(); - BaseFeePerGas::::set(lower_bfpg); + let min_bfpg = ::MinBaseFeePerGas::get(); + BaseFeePerGas::::set(min_bfpg); set_adjustment_factor(FixedU128::max_value()); let step_limit = get_max_step_limit(); DynamicEvmBaseFee::on_finalize(1); assert_eq!( BaseFeePerGas::::get(), - lower_bfpg + step_limit, + min_bfpg + step_limit, "Step limit ratio in ascending direction was not respected." ); // Upper bound, low adjustment factor - let higher_bfpg = ::MaxBaseFeePerGas::get(); - BaseFeePerGas::::set(higher_bfpg); + let max_bfpg = ::MaxBaseFeePerGas::get(); + BaseFeePerGas::::set(max_bfpg); set_adjustment_factor(FixedU128::zero()); let step_limit = get_max_step_limit(); DynamicEvmBaseFee::on_finalize(2); assert_eq!( BaseFeePerGas::::get(), - higher_bfpg - step_limit, + max_bfpg - step_limit, "Step limit ratio in descending direction was not respected." ); }); } + +#[test] +fn bfpg_full_spectrum_change_works() { + ExtBuilder::build().execute_with(|| { + // Set bfpg to lowest possible, and adjustment factor to highest possible + let min_bfpg = ::MinBaseFeePerGas::get(); + BaseFeePerGas::::set(min_bfpg); + set_adjustment_factor(FixedU128::max_value()); + + // Run for limited amount of iterations until upper bound is reached + let target_bfpg = ::MaxBaseFeePerGas::get(); + let mut counter = 1; + let iter_limit = 500_000; // safety limit to avoid endless loop + while counter <= iter_limit && BaseFeePerGas::::get() < target_bfpg { + DynamicEvmBaseFee::on_finalize(counter); + counter += 1; + } + assert_eq!(BaseFeePerGas::::get(), target_bfpg); + }); +}