Skip to content

Commit

Permalink
Update check and test
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M committed Sep 12, 2023
1 parent d886d0c commit 23a4407
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 5 additions & 5 deletions sdk/src/wallet/migration/chrysalis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -267,6 +262,11 @@ fn get_chrysalis_data(chrysalis_storage_path: &Path, password: Option<Password>)

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)
}

Expand Down
7 changes: 7 additions & 0 deletions sdk/tests/wallet/chrysalis_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 23a4407

Please sign in to comment.