Skip to content

Commit

Permalink
chore: add backward compatibility test for db storage
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc committed Dec 25, 2024
1 parent b6a29ae commit 1ded825
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 18 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,8 +65,22 @@ 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);
Expand Down Expand Up @@ -83,8 +109,8 @@ async fn v1_gas_price_metadata_updates_successfully_from_v0() {
"0",
],
)
.await
.unwrap();
.await
.unwrap();

// When
const BLOCKS_TO_PRODUCE: u32 = 10;
Expand All @@ -99,13 +125,19 @@ async fn v1_gas_price_metadata_updates_successfully_from_v0() {
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 1ded825

Please sign in to comment.