From 476a88b51eebbc4cbe64c10402fa9bce8c878fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Chabowski?= Date: Fri, 4 Oct 2024 18:12:59 +0200 Subject: [PATCH] Remove tests for data normalization --- .../v1/tests/update_da_record_data_tests.rs | 166 ------------------ 1 file changed, 166 deletions(-) diff --git a/crates/fuel-gas-price-algorithm/src/v1/tests/update_da_record_data_tests.rs b/crates/fuel-gas-price-algorithm/src/v1/tests/update_da_record_data_tests.rs index 1c1628be60a..123520b4e99 100644 --- a/crates/fuel-gas-price-algorithm/src/v1/tests/update_da_record_data_tests.rs +++ b/crates/fuel-gas-price-algorithm/src/v1/tests/update_da_record_data_tests.rs @@ -5,13 +5,6 @@ use crate::v1::{ }, Error, }; -use proptest::{ - prelude::Rng, - prop_compose, - proptest, -}; -use rand::SeedableRng; -use std::ops::Range; #[test] fn update_da_record_data__increases_block() { @@ -277,162 +270,3 @@ fn update_da_record_data__da_block_updates_projected_total_cost_with_known_and_g let expected = new_known_total_cost + guessed_part; assert_eq!(actual, expected as u128); } - -#[derive(Debug, Clone)] -pub struct RecordedBlock { - pub height: u32, - pub block_cost: u64, -} - -prop_compose! { - fn arb_vec_of_da_blocks()(last_da_block: u32, count in 1..123usize, rng_seed: u64) -> (Vec, (Range, u128)) { - let rng = &mut rand::rngs::StdRng::seed_from_u64(rng_seed); - let mut unrecorded_blocks = Vec::with_capacity(count); - let mut recorded_blocks = Vec::with_capacity(count); - for i in 0..count { - let height = last_da_block + 1 + i as u32; - let block_bytes = rng.gen_range(100..131_072); - let cost_per_byte = rng.gen_range(1..1000000); - let block_cost = block_bytes * cost_per_byte; - unrecorded_blocks.push(BlockBytes { - height, - block_bytes, - }); - recorded_blocks.push(RecordedBlock { - height, - block_cost, - }); - } - let recorded_heights = recorded_blocks - .iter() - .map(|block| block.height) - .collect::>(); - let min = recorded_heights.iter().min().unwrap(); - let max = recorded_heights.iter().max().unwrap(); - let recorded_range = *min..(max + 1); - let recorded_cost = recorded_blocks - .iter() - .map(|block| block.block_cost as u128) - .sum(); - - (unrecorded_blocks, (recorded_range, recorded_cost)) - } -} - -prop_compose! { - fn reward_greater_than_cost_with_da_blocks()(cost: u64, extra: u64, (unrecorded_blocks, (recorded_range, recorded_cost)) in arb_vec_of_da_blocks()) -> (u128, u128, Vec, (Range, u128)) { - let reward = cost as u128 + recorded_cost + extra as u128; - (cost as u128, reward, unrecorded_blocks, (recorded_range, recorded_cost)) - } -} - -proptest! { - // https://github.com/FuelLabs/fuel-core/issues/2264 - #[ignore] - #[test] - fn update_da_record_data__when_reward_is_greater_than_cost_will_zero_cost_and_subtract_from_reward( - (cost, reward, unrecorded_blocks, (recorded_range, recorded_cost)) in reward_greater_than_cost_with_da_blocks() - ) { - _update_da_record_data__when_reward_is_greater_than_cost_will_zero_cost_and_subtract_from_reward( - cost, - reward, - unrecorded_blocks, - recorded_range, - recorded_cost - ) - } -} - -fn _update_da_record_data__when_reward_is_greater_than_cost_will_zero_cost_and_subtract_from_reward( - known_total_cost: u128, - total_rewards: u128, - unrecorded_blocks: Vec, - recorded_range: Range, - recorded_cost: u128, -) { - // given - let da_cost_per_byte = 20; - let da_recorded_block_height = recorded_range.start - 1; - let l2_block_height = 15; - let mut updater = UpdaterBuilder::new() - .with_da_cost_per_byte(da_cost_per_byte) - .with_da_recorded_block_height(da_recorded_block_height) - .with_l2_block_height(l2_block_height) - .with_known_total_cost(known_total_cost) - .with_total_rewards(total_rewards) - .with_unrecorded_blocks(unrecorded_blocks) - .build(); - - // when - updater - .update_da_record_data(recorded_range, recorded_cost) - .unwrap(); - - // then - let expected = total_rewards - recorded_cost - known_total_cost; - let actual = updater.total_da_rewards_excess; - assert_eq!(actual, expected); - - let expected = 0; - let actual = updater.latest_known_total_da_cost_excess; - assert_eq!(actual, expected); -} - -prop_compose! { - fn cost_greater_than_reward_with_da_blocks()(reward: u64, extra: u64, (unrecorded_blocks, (recorded_range, recorded_cost)) in arb_vec_of_da_blocks()) -> (u128, u128, Vec, (Range, u128)) { - let cost = reward as u128 + recorded_cost + extra as u128; - (cost, reward as u128, unrecorded_blocks, (recorded_range, recorded_cost)) - } -} - -proptest! { - // https://github.com/FuelLabs/fuel-core/issues/2264 - #[ignore] - #[test] - fn update_da_record_data__when_cost_is_greater_than_reward_will_zero_reward_and_subtract_from_cost( - (cost, reward, unrecorded_blocks, (recorded_range, recorded_cost)) in cost_greater_than_reward_with_da_blocks() - ) { - _update_da_record_data__when_cost_is_greater_than_reward_will_zero_reward_and_subtract_from_cost( - cost, - reward, - unrecorded_blocks, - recorded_range, - recorded_cost - ) - } -} - -fn _update_da_record_data__when_cost_is_greater_than_reward_will_zero_reward_and_subtract_from_cost( - known_total_cost: u128, - total_rewards: u128, - unrecorded_blocks: Vec, - recorded_range: Range, - recorded_cost: u128, -) { - // given - let da_cost_per_byte = 20; - let da_recorded_block_height = recorded_range.start - 1; - let l2_block_height = 15; - let mut updater = UpdaterBuilder::new() - .with_da_cost_per_byte(da_cost_per_byte) - .with_da_recorded_block_height(da_recorded_block_height) - .with_l2_block_height(l2_block_height) - .with_known_total_cost(known_total_cost) - .with_total_rewards(total_rewards) - .with_unrecorded_blocks(unrecorded_blocks) - .build(); - - // when - updater - .update_da_record_data(recorded_range, recorded_cost) - .unwrap(); - - // then - let expected = 0; - let actual = updater.total_da_rewards_excess; - assert_eq!(actual, expected); - - let expected = known_total_cost + recorded_cost - total_rewards; - let actual = updater.latest_known_total_da_cost_excess; - assert_eq!(actual, expected); -}