Skip to content

Commit

Permalink
Fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchTurner committed Jan 11, 2025
1 parent 5361d5b commit d636390
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
24 changes: 16 additions & 8 deletions crates/services/gas_price_service/src/v1/uninitialized_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use crate::{
GasPriceSettings,
GasPriceSettingsProvider,
},
gas_price_algorithm::SharedGasPriceAlgo,
gas_price_algorithm::{
GasPriceAlgorithm,
SharedGasPriceAlgo,
},
l2_block_source::FuelL2BlockSource,
updater_metadata::UpdaterMetadata,
utils::{
Expand Down Expand Up @@ -128,20 +131,21 @@ where
.latest_height()
.unwrap_or(genesis_block_height)
.into();

let gas_price_metadata_height = gas_metadata_height
.map(|x| x.into())
.unwrap_or(latest_block_height);

let (algo_updater, shared_algo) =
initialize_algorithm(&config, gas_price_metadata_height, &gas_price_db)?;
let latest_gas_price = on_chain_db
.latest_view()?
.get_block(&latest_block_height.into())?
.and_then(|block| {
let (_, gas_price) = mint_values(&block).ok()?;
Some(gas_price)
})
.unwrap_or(0);
let gas_price_metadata_height = gas_metadata_height
.map(|x| x.into())
.unwrap_or(latest_block_height);

let (algo_updater, shared_algo) =
initialize_algorithm(&config, gas_price_metadata_height, &gas_price_db)?;
.unwrap_or(algo_updater.algorithm().next_gas_price());

let latest_gas_price = LatestGasPrice::new(latest_block_height, latest_gas_price);

Expand Down Expand Up @@ -227,6 +231,10 @@ where
state_watcher,
)?;
}
self.latest_gas_price.set(
latest_block_height,
self.algo_updater.algorithm().next_gas_price(),
);

let service = GasPriceServiceV1::new(
l2_block_source,
Expand Down
24 changes: 20 additions & 4 deletions tests/tests/gas_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,12 @@ async fn estimate_gas_price__is_greater_than_actual_price_at_desired_height() {
let latest = client.latest_gas_price().await.unwrap();
let real = latest.gas_price;
let estimated = u64::from(estimate.gas_price);
assert!(estimated >= real);
assert!(
estimated >= real,
"estimated: {}, real: {}",
estimated,
real
);
}

#[tokio::test(flavor = "multi_thread")]
Expand Down Expand Up @@ -532,6 +537,10 @@ async fn startup__can_override_gas_price_values_by_changing_config() {

#[test]
fn produce_block__l1_committed_block_affects_gas_price() {
let _ = tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.try_init();

let rt = tokio::runtime::Runtime::new().unwrap();
// set up chain with single unrecorded block
let mut args = vec![
Expand Down Expand Up @@ -607,16 +616,23 @@ fn produce_block__l1_committed_block_affects_gas_price() {
// Won't accept DA costs until l2_height is > 1
driver.client.produce_blocks(1, None).await.unwrap();
// Wait for DaBlockCosts to be accepted
tokio::time::sleep(Duration::from_millis(2)).await;
tokio::time::sleep(Duration::from_millis(200)).await;
// Produce new block to update gas price
driver.client.produce_blocks(1, None).await.unwrap();
tokio::time::sleep(Duration::from_millis(20)).await;
tokio::time::sleep(Duration::from_millis(10)).await;
driver.client.produce_blocks(1, None).await.unwrap();
tokio::time::sleep(Duration::from_millis(10)).await;
driver.client.estimate_gas_price(0).await.unwrap().gas_price
})
.into();

// then
assert!(first_gas_price < new_gas_price);
assert!(
first_gas_price < new_gas_price,
"first: {}, new: {}",
first_gas_price,
new_gas_price
);
rt.shutdown_timeout(tokio::time::Duration::from_millis(100));
}

Expand Down

0 comments on commit d636390

Please sign in to comment.