Skip to content

Commit

Permalink
Merge branch 'feature/support-new-tables-rocksdb' into fix_rocksdb
Browse files Browse the repository at this point in the history
  • Loading branch information
simrankedia committed Apr 22, 2024
2 parents 5b4f560 + 73d533c commit 967710b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

Description of the upcoming release here.

### Added

- [#1853](https://github.com/FuelLabs/fuel-core/pull/1853): Added a test case to verify the database's behavior when new columns are added to the RocksDB database.

## [Version 0.25.2]

### Fixed
Expand Down
3 changes: 3 additions & 0 deletions crates/database/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ fuel-core-types = { workspace = true }

[dev-dependencies]
fuel-core-trace = { path = "../trace" }

[features]
test-helpers = []
7 changes: 7 additions & 0 deletions crates/database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ pub enum Error {
Other(anyhow::Error),
}

#[cfg(feature = "test-helpers")]
impl PartialEq for Error {
fn eq(&self, other: &Self) -> bool {
self.to_string().eq(&other.to_string())
}
}

impl From<Error> for anyhow::Error {
fn from(error: Error) -> Self {
anyhow::Error::msg(error)
Expand Down
1 change: 1 addition & 0 deletions crates/fuel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ p2p = ["dep:fuel-core-p2p", "dep:fuel-core-sync"]
relayer = ["dep:fuel-core-relayer"]
rocksdb = ["dep:rocksdb", "dep:tempfile", "dep:num_cpus"]
test-helpers = [
"fuel-core-database/test-helpers",
"fuel-core-p2p?/test-helpers",
"fuel-core-storage/test-helpers",
"fuel-core-chain-config/test-helpers",
Expand Down
22 changes: 22 additions & 0 deletions crates/fuel-core/src/state/rocks_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,28 @@ mod tests {
)
}

#[test]
fn open_new_columns() {
let tmp_dir = TempDir::new().unwrap();

// Given
let old_columns =
vec![Column::Coins, Column::Messages, Column::UploadedBytecodes];
let database_with_old_columns =
RocksDb::<OnChain>::open(tmp_dir.path(), old_columns.clone(), None)
.expect("Failed to open database with old columns");
drop(database_with_old_columns);

// When
let mut new_columns = old_columns;
new_columns.push(Column::ContractsAssets);
let database_with_new_columns =
RocksDb::<OnChain>::open(tmp_dir.path(), new_columns, None).map(|_| ());

// Then
assert_eq!(Ok(()), database_with_new_columns);
}

#[test]
fn can_put_and_read() {
let key = vec![0xA, 0xB, 0xC];
Expand Down

0 comments on commit 967710b

Please sign in to comment.