Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in migrate_db_chrysalis_to_stardust() if no chrysalis data exists #1215

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bindings/nodejs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 6 additions & 0 deletions sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions sdk/src/wallet/migration/chrysalis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,17 @@ 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() {
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
return Err(crate::wallet::Error::Migration(
"no chrysalis data to migrate".to_string(),
));
}
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
21 changes: 21 additions & 0 deletions sdk/tests/wallet/chrysalis_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,27 @@ 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";
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
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"
));
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved

// 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<Path>, dest: impl AsRef<Path>) -> io::Result<()> {
fs::create_dir_all(&dest)?;
for entry in fs::read_dir(src)? {
Expand Down
Loading