Skip to content

Commit

Permalink
Test overflow fix via update_l2_block_data()
Browse files Browse the repository at this point in the history
  • Loading branch information
rafal-ch committed Sep 24, 2024
1 parent 056ba1e commit 3047c7e
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions crates/fuel-gas-price-algorithm/src/v1/tests/algorithm_v1_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,27 +150,37 @@ fn worst_case__same_block_gives_the_same_value_as_calculate() {

#[test]
fn da_change_should_not_panic() {
let updater = AlgorithmUpdaterV1 {
const HEIGHT: u32 = 0;

// The following values are chosen to make the `p.saturating_add(d)` result in
// i128::MIN, which would cause a panic if the calculation is not using `saturating_abs()`.
const LAST_PROFIT: i128 = i128::MIN / 2;
const TOTAL_DA_REWARDS_EXCESS: i128 = i128::MAX / 2;
const P: i64 = 1;
const D: i64 = 1;

let mut updater = AlgorithmUpdaterV1 {
new_scaled_exec_price: 0,
min_exec_gas_price: 0,
exec_gas_price_change_percent: 0,
l2_block_height: 0,
l2_block_height: HEIGHT,
l2_block_fullness_threshold_percent: ClampedPercentage::new(0),
new_scaled_da_gas_price: 0,
gas_price_factor: NonZeroU64::new(1).unwrap(),
min_da_gas_price: 0,
max_da_gas_price_change_percent: 0,
total_da_rewards_excess: 0,
total_da_rewards_excess: TOTAL_DA_REWARDS_EXCESS as u128,
da_recorded_block_height: 0,
latest_known_total_da_cost_excess: 0,
projected_total_da_cost: 0,
da_p_component: 0,
da_d_component: 0,
last_profit: 0,
da_p_component: P,
da_d_component: D,
last_profit: LAST_PROFIT,
second_to_last_profit: 0,
latest_da_cost_per_byte: 0,
unrecorded_blocks: vec![],
};

updater.da_change(i128::MIN / 2, i128::MIN / 2);
let _ =
updater.update_l2_block_data(HEIGHT + 1, 0, NonZeroU64::new(1).unwrap(), 0, 0);
}

0 comments on commit 3047c7e

Please sign in to comment.