From 5be5a683a8bf5b87ef84981025c167f68aefdb62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Tue, 12 Sep 2023 16:19:42 +0200 Subject: [PATCH 1/7] error in migrate_db_chrysalis_to_stardust() if no chrysalis data exists --- bindings/nodejs/CHANGELOG.md | 6 +++++- sdk/CHANGELOG.md | 6 ++++++ sdk/src/wallet/migration/chrysalis.rs | 5 +++++ sdk/tests/wallet/chrysalis_migration.rs | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/bindings/nodejs/CHANGELOG.md b/bindings/nodejs/CHANGELOG.md index 4e7d379907..c5b2fef616 100644 --- a/bindings/nodejs/CHANGELOG.md +++ b/bindings/nodejs/CHANGELOG.md @@ -19,12 +19,16 @@ 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 ### Fixed - Type of `value` property in `CustomAddress`; +### Changed + +- `migrateDbChrysalisToStardust()` returns an error if no chrysalis data was found; + ## 1.0.9 - 2023-09-07 ### Added diff --git a/sdk/CHANGELOG.md b/sdk/CHANGELOG.md index bda9c242be..af4d2ca578 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.3 - 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..9ed7c97652 100644 --- a/sdk/src/wallet/migration/chrysalis.rs +++ b/sdk/src/wallet/migration/chrysalis.rs @@ -72,6 +72,11 @@ pub async fn migrate_db_chrysalis_to_stardust( let chrysalis_storage_path = &(*storage_path_string).join("db"); let chrysalis_data = get_chrysalis_data(chrysalis_storage_path, password)?; + if chrysalis_data.is_empty() { + return Err(crate::wallet::Error::Migration( + "no chrysalis data to migrate".to_string(), + )); + } // create new accounts base on previous data let (new_accounts, secret_manager_dto) = migrate_from_chrysalis_data(&chrysalis_data, &storage_path_string, false)?; diff --git a/sdk/tests/wallet/chrysalis_migration.rs b/sdk/tests/wallet/chrysalis_migration.rs index 0105eabcc2..0e2533ff0f 100644 --- a/sdk/tests/wallet/chrysalis_migration.rs +++ b/sdk/tests/wallet/chrysalis_migration.rs @@ -348,6 +348,20 @@ 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)?; + + 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" + )); + + 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)? { From 1cec8d0558972c08a3b493e609dfcdc667d57ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Tue, 12 Sep 2023 16:23:08 +0200 Subject: [PATCH 2/7] Improve --- sdk/src/wallet/migration/chrysalis.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/src/wallet/migration/chrysalis.rs b/sdk/src/wallet/migration/chrysalis.rs index 9ed7c97652..c45c7f2762 100644 --- a/sdk/src/wallet/migration/chrysalis.rs +++ b/sdk/src/wallet/migration/chrysalis.rs @@ -71,12 +71,12 @@ 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"); - let chrysalis_data = get_chrysalis_data(chrysalis_storage_path, password)?; - if chrysalis_data.is_empty() { + 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 let (new_accounts, secret_manager_dto) = migrate_from_chrysalis_data(&chrysalis_data, &storage_path_string, false)?; From fb1273ca69b18aed32b093c3631406bfee8d4bdc Mon Sep 17 00:00:00 2001 From: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> Date: Tue, 12 Sep 2023 16:28:56 +0200 Subject: [PATCH 3/7] Update sdk/CHANGELOG.md Co-authored-by: Thibault Martinez --- sdk/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/CHANGELOG.md b/sdk/CHANGELOG.md index af4d2ca578..e6bd5c18d3 100644 --- a/sdk/CHANGELOG.md +++ b/sdk/CHANGELOG.md @@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security --> -## 1.0.3 - 2023-MM-DD +## 1.0.4 - 2023-MM-DD ### Changed From dac7f61804587aef0d8d1112716f45a65d912e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Tue, 12 Sep 2023 16:29:34 +0200 Subject: [PATCH 4/7] Bump version --- bindings/nodejs/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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", From 4d0c4cb09463b4e77a0408ef7476ddcd3eded0b7 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 12 Sep 2023 20:14:39 +0200 Subject: [PATCH 5/7] ocd --- bindings/nodejs/CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings/nodejs/CHANGELOG.md b/bindings/nodejs/CHANGELOG.md index c5b2fef616..734c25af36 100644 --- a/bindings/nodejs/CHANGELOG.md +++ b/bindings/nodejs/CHANGELOG.md @@ -21,14 +21,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 1.0.10 - 2023-09-12 -### Fixed - -- Type of `value` property in `CustomAddress`; - ### Changed - `migrateDbChrysalisToStardust()` returns an error if no chrysalis data was found; +### Fixed + +- Type of `value` property in `CustomAddress`; + ## 1.0.9 - 2023-09-07 ### Added From d886d0c7712718f157eeac1f90a5b03657fe2c4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Tue, 12 Sep 2023 20:27:31 +0200 Subject: [PATCH 6/7] Add another check and update test --- sdk/src/wallet/migration/chrysalis.rs | 5 +++++ sdk/tests/wallet/chrysalis_migration.rs | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/sdk/src/wallet/migration/chrysalis.rs b/sdk/src/wallet/migration/chrysalis.rs index c45c7f2762..9116d73abd 100644 --- a/sdk/src/wallet/migration/chrysalis.rs +++ b/sdk/src/wallet/migration/chrysalis.rs @@ -77,6 +77,11 @@ pub async fn migrate_db_chrysalis_to_stardust( )); } let chrysalis_data = get_chrysalis_data(chrysalis_storage_path, password)?; + if chrysalis_data.is_empty() { + return Err(crate::wallet::Error::Migration( + "no chrysalis data to migrate".to_string(), + )); + } // create new accounts base on previous data let (new_accounts, secret_manager_dto) = migrate_from_chrysalis_data(&chrysalis_data, &storage_path_string, false)?; diff --git a/sdk/tests/wallet/chrysalis_migration.rs b/sdk/tests/wallet/chrysalis_migration.rs index 0e2533ff0f..231d9775a8 100644 --- a/sdk/tests/wallet/chrysalis_migration.rs +++ b/sdk/tests/wallet/chrysalis_migration.rs @@ -354,11 +354,18 @@ async fn migrate_empty_chrysalis_db() -> Result<()> { 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" )); + // 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) } From 23a44070bdd5fbbf5fa992f66c9e49845fe74de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Tue, 12 Sep 2023 20:44:45 +0200 Subject: [PATCH 7/7] Update check and test --- sdk/src/wallet/migration/chrysalis.rs | 10 +++++----- sdk/tests/wallet/chrysalis_migration.rs | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/sdk/src/wallet/migration/chrysalis.rs b/sdk/src/wallet/migration/chrysalis.rs index 9116d73abd..c4fc30e81b 100644 --- a/sdk/src/wallet/migration/chrysalis.rs +++ b/sdk/src/wallet/migration/chrysalis.rs @@ -77,11 +77,6 @@ pub async fn migrate_db_chrysalis_to_stardust( )); } let chrysalis_data = get_chrysalis_data(chrysalis_storage_path, password)?; - if chrysalis_data.is_empty() { - return Err(crate::wallet::Error::Migration( - "no chrysalis data to migrate".to_string(), - )); - } // create new accounts base on previous data let (new_accounts, secret_manager_dto) = migrate_from_chrysalis_data(&chrysalis_data, &storage_path_string, false)?; @@ -267,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 231d9775a8..a3d831fb32 100644 --- a/sdk/tests/wallet/chrysalis_migration.rs +++ b/sdk/tests/wallet/chrysalis_migration.rs @@ -362,6 +362,13 @@ async fn migrate_empty_chrysalis_db() -> Result<()> { 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);