Skip to content

Commit

Permalink
chore: add backward compatibility test for db storage
Browse files Browse the repository at this point in the history
fix: remove block production
  • Loading branch information
rymnc committed Dec 25, 2024
1 parent b6a29ae commit bb007d3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 28 deletions.
2 changes: 2 additions & 0 deletions version-compatibility/forkless-upgrade/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ version-36-fuel-core-bin = { version = "0.36.0", package = "fuel-core-bin", feat
] }
version-36-fuel-core-client = { version = "0.36.0", package = "fuel-core-client" }
version-36-fuel-core-services = { version = "0.36.0", package = "fuel-core-services" }
version-36-fuel-core-gas-price-service = { version = "0.36.0", package = "fuel-core-gas-price-service" }
version-36-fuel-core-storage = { version = "0.36.0", package = "fuel-core-storage" }
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use crate::tests_helper::{
};
use latest_fuel_core_gas_price_service::{
common::{
fuel_core_storage_adapter::storage::GasPriceMetadata,
updater_metadata::UpdaterMetadata,
fuel_core_storage_adapter::storage::GasPriceMetadata as NewGasPriceMetadata,
updater_metadata::UpdaterMetadata as NewUpdaterMetadata,
},
ports::GasPriceData,
ports::GasPriceData as NewGasPriceData,
v1::metadata::V1Metadata,
};
use latest_fuel_core_storage::{
transactional::AtomicView,
StorageAsRef,
transactional::AtomicView as NewAtomicView,
StorageAsRef as NewStorageAsRef,
};
use libp2p::{
identity::{
Expand All @@ -27,6 +27,18 @@ use libp2p::{
PeerId,
};
use std::ops::Deref;
use version_36_fuel_core_gas_price_service::fuel_gas_price_updater::{
fuel_core_storage_adapter::storage::GasPriceMetadata as OldGasPriceMetadata,
UpdaterMetadata as OldUpdaterMetadata,
V0Metadata,
};
use version_36_fuel_core_storage::{
transactional::{
AtomicView as OldAtomicView,
HistoricalView as OldHistoricalView,
},
StorageAsRef as OldStorageAsRef,
};

#[tokio::test]
async fn v1_gas_price_metadata_updates_successfully_from_v0() {
Expand All @@ -53,15 +65,29 @@ async fn v1_gas_price_metadata_updates_successfully_from_v0() {
"--starting-gas-price",
starting_gas_price.to_string().as_str(),
])
.await
.unwrap();
.await
.unwrap();

let db = &old_driver.node.shared.database;
let latest_height = db.gas_price().latest_height().unwrap();
let view = db.gas_price().latest_view().unwrap();
let v0_metadata = match OldStorageAsRef::storage::<OldGasPriceMetadata>(&view)
.get(&latest_height)
.unwrap()
.unwrap()
.deref()
.clone()
{
OldUpdaterMetadata::V0(v0) => v0,
};

let public_key = Keypair::from(genesis_keypair).public();
let genesis_peer_id = PeerId::from_public_key(&public_key);
let genesis_multiaddr = default_multiaddr(genesis_port, genesis_peer_id);
let temp_dir = old_driver.kill().await;

// Starting node that uses latest fuel core.
// It will connect to the genesis node and sync blocks.
// When
let latest_keypair = SecpKeypair::generate();
let hexed_secret = hex::encode(latest_keypair.secret().to_bytes());
let latest_node = LatestFuelCoreDriver::spawn_with_directory(
Expand All @@ -83,29 +109,26 @@ async fn v1_gas_price_metadata_updates_successfully_from_v0() {
"0",
],
)
.await
.unwrap();

// When
const BLOCKS_TO_PRODUCE: u32 = 10;
latest_node
.client
.produce_blocks(BLOCKS_TO_PRODUCE, None)
.await
.unwrap();
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
.await
.unwrap();

// Then
let db = &latest_node.node.shared.database;
let latest_height = db.gas_price().latest_height().unwrap();
let view = db.gas_price().latest_view().unwrap();
let metadata = view
.storage::<GasPriceMetadata>()
.get(&latest_height.into())
.unwrap()
.unwrap()
.deref()
.clone();
let v1_metadata = V1Metadata::try_from(
NewStorageAsRef::storage::<NewGasPriceMetadata>(&view)
.get(&latest_height.into())
.unwrap()
.unwrap()
.deref()
.clone(),
)
.unwrap();

assert!(matches!(metadata, UpdaterMetadata::V1(_)));
assert_eq!(v0_metadata.l2_block_height, v1_metadata.l2_block_height);
assert_eq!(
v0_metadata.new_exec_price,
v1_metadata.new_scaled_exec_price * v1_metadata.gas_price_factor.get()
);
}
2 changes: 1 addition & 1 deletion version-compatibility/forkless-upgrade/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ async fn test__genesis_block__hash() {
)
.unwrap()
)
}
}

0 comments on commit bb007d3

Please sign in to comment.