diff --git a/bindings/nodejs/CHANGELOG.md b/bindings/nodejs/CHANGELOG.md index 4e7d379907..734c25af36 100644 --- a/bindings/nodejs/CHANGELOG.md +++ b/bindings/nodejs/CHANGELOG.md @@ -19,7 +19,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security --> -## 1.0.10 - 2023-mm-dd +## 1.0.10 - 2023-09-12 + +### Changed + +- `migrateDbChrysalisToStardust()` returns an error if no chrysalis data was found; ### Fixed diff --git a/bindings/nodejs/package.json b/bindings/nodejs/package.json index 17e1c54c2d..365ae7ba8c 100644 --- a/bindings/nodejs/package.json +++ b/bindings/nodejs/package.json @@ -1,6 +1,6 @@ { "name": "@iota/sdk", - "version": "1.0.9", + "version": "1.0.10", "description": "Node.js binding to the IOTA SDK library", "main": "out/index.js", "types": "out/index.d.ts", diff --git a/sdk/CHANGELOG.md b/sdk/CHANGELOG.md index bda9c242be..e6bd5c18d3 100644 --- a/sdk/CHANGELOG.md +++ b/sdk/CHANGELOG.md @@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security --> +## 1.0.4 - 2023-MM-DD + +### Changed + +- `migrate_db_chrysalis_to_stardust()` returns an error if no chrysalis data was found; + ## 1.0.3 - 2023-09-07 ### Added diff --git a/sdk/src/wallet/migration/chrysalis.rs b/sdk/src/wallet/migration/chrysalis.rs index 3a03fcd9a0..c4fc30e81b 100644 --- a/sdk/src/wallet/migration/chrysalis.rs +++ b/sdk/src/wallet/migration/chrysalis.rs @@ -71,6 +71,11 @@ pub async fn migrate_db_chrysalis_to_stardust( // `/db` will be appended to the chrysalis storage path, because that's how it was done in the chrysalis wallet let chrysalis_storage_path = &(*storage_path_string).join("db"); + if !chrysalis_storage_path.is_dir() { + return Err(crate::wallet::Error::Migration( + "no chrysalis data to migrate".to_string(), + )); + } let chrysalis_data = get_chrysalis_data(chrysalis_storage_path, password)?; // create new accounts base on previous data @@ -257,6 +262,11 @@ fn get_chrysalis_data(chrysalis_storage_path: &Path, password: Option) chrysalis_data.insert(key.to_vec(), value); } + if !chrysalis_data.contains_key(&b"iota-wallet-account-indexation".to_vec()) { + return Err(crate::wallet::Error::Migration( + "no chrysalis data to migrate".to_string(), + )); + } Ok(chrysalis_data) } diff --git a/sdk/tests/wallet/chrysalis_migration.rs b/sdk/tests/wallet/chrysalis_migration.rs index 0105eabcc2..a3d831fb32 100644 --- a/sdk/tests/wallet/chrysalis_migration.rs +++ b/sdk/tests/wallet/chrysalis_migration.rs @@ -348,6 +348,34 @@ async fn migrate_chrysalis_stronghold() -> Result<()> { tear_down(storage_path) } +#[tokio::test] +async fn migrate_empty_chrysalis_db() -> Result<()> { + iota_stronghold::engine::snapshot::try_set_encrypt_work_factor(0).unwrap(); + let storage_path = "migrate_empty_chrysalis_db"; + setup(storage_path)?; + + // Copy db so the original doesn't get modified + copy_folder("./tests/wallet/fixtures/check_existing_4_db_test", storage_path).unwrap(); + + assert!(matches!( + migrate_db_chrysalis_to_stardust("migrate_empty_chrysalis_db", None, None).await, + Err(iota_sdk::wallet::error::Error::Migration(msg)) if msg == "no chrysalis data to migrate" + )); + + // add empty /db folder + fs::create_dir("migrate_empty_chrysalis_db/db")?; + assert!(matches!( + migrate_db_chrysalis_to_stardust("migrate_empty_chrysalis_db", None, None).await, + Err(iota_sdk::wallet::error::Error::Migration(msg)) if msg == "no chrysalis data to migrate" + )); + + // stardust wallet data is still there + let wallet = Wallet::builder().with_storage_path(storage_path).finish().await?; + assert_eq!(wallet.get_accounts().await?.len(), 1); + + tear_down(storage_path) +} + fn copy_folder(src: impl AsRef, dest: impl AsRef) -> io::Result<()> { fs::create_dir_all(&dest)?; for entry in fs::read_dir(src)? {