diff --git a/.changes/db-migration.md b/.changes/db-migration.md new file mode 100644 index 0000000000..9d324dc0d8 --- /dev/null +++ b/.changes/db-migration.md @@ -0,0 +1,5 @@ +--- +"wallet-nodejs-binding": patch +--- + +Fixed migration mismatch from `iota-rs` version. \ No newline at end of file diff --git a/bindings/nodejs/CHANGELOG.md b/bindings/nodejs/CHANGELOG.md index c9f9b361c8..a14b72f45b 100644 --- a/bindings/nodejs/CHANGELOG.md +++ b/bindings/nodejs/CHANGELOG.md @@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security --> +## 1.0.7 - 2023-08-29 + +### Fixed + +- Migration mismatch from `iota-rs` version; + ## 1.0.6 - 2023-08-25 ### Fixed diff --git a/bindings/nodejs/package.json b/bindings/nodejs/package.json index c9f0b13161..34c546be14 100644 --- a/bindings/nodejs/package.json +++ b/bindings/nodejs/package.json @@ -1,6 +1,6 @@ { "name": "@iota/sdk", - "version": "1.0.6", + "version": "1.0.7", "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 01846b4751..1b80ee77f0 100644 --- a/sdk/CHANGELOG.md +++ b/sdk/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Ledger Nano events properly created when preparing transactions using a `SecretManager`; - `Account::prepare_output()` when `ReturnStrategy::Gift` is used with an existing NFT output; - `Wallet::restore_backup()` when no secret manager data is stored inside; +- Migration mismatch from `iota-rs` version; ## 1.0.2 - 2023-07-28 diff --git a/sdk/src/wallet/migration/migrate_1.rs b/sdk/src/wallet/migration/migrate_1.rs index 920f713472..8523b952ea 100644 --- a/sdk/src/wallet/migration/migrate_1.rs +++ b/sdk/src/wallet/migration/migrate_1.rs @@ -140,11 +140,11 @@ fn migrate_account(account: &mut serde_json::Value) -> Result<()> { } fn migrate_client_options(client_options: &mut serde_json::Value) -> Result<()> { - let protocol_parameters = &mut client_options["protocolParameters"]; + if let Some(protocol_parameters) = &mut client_options.get_mut("protocolParameters") { + ConvertHrp::check(&mut protocol_parameters["bech32_hrp"])?; - ConvertHrp::check(&mut protocol_parameters["bech32_hrp"])?; - - rename_keys(&mut protocol_parameters["rent_structure"]); + rename_keys(&mut protocol_parameters["rent_structure"]); + } Ok(()) } diff --git a/sdk/src/wallet/migration/migrate_3.rs b/sdk/src/wallet/migration/migrate_3.rs index af824c19ed..900d6e643e 100644 --- a/sdk/src/wallet/migration/migrate_3.rs +++ b/sdk/src/wallet/migration/migrate_3.rs @@ -37,12 +37,7 @@ impl Migration for Migrate { if let Some(mut wallet) = storage.get::(WALLET_INDEXATION_KEY).await? { if let Some(client_options) = wallet.get_mut("client_options") { - let params = client_options["protocolParameters"].as_object_mut().unwrap(); - if let Some(version) = params.remove("protocol_version") { - params.insert("version".to_owned(), version); - } - ConvertNetworkName::check(&mut client_options["protocolParameters"]["network_name"])?; - ConvertTokenSupply::check(&mut client_options["protocolParameters"]["token_supply"])?; + migrate_client_options(client_options)?; } rename_keys(&mut wallet); @@ -69,12 +64,7 @@ impl Migration for Migrate { } if let Some(mut client_options) = storage.get::(CLIENT_OPTIONS_KEY).await? { - let params = client_options["protocolParameters"].as_object_mut().unwrap(); - if let Some(version) = params.remove("protocol_version") { - params.insert("version".to_owned(), version); - } - ConvertNetworkName::check(&mut client_options["protocolParameters"]["network_name"])?; - ConvertTokenSupply::check(&mut client_options["protocolParameters"]["token_supply"])?; + migrate_client_options(&mut client_options)?; rename_keys(&mut client_options); storage.set(CLIENT_OPTIONS_KEY, &client_options).await?; @@ -83,6 +73,20 @@ impl Migration for Migrate { } } +fn migrate_client_options(client_options: &mut serde_json::Value) -> Result<()> { + if let Some(params) = client_options + .get_mut("protocolParameters") + .map(|p| p.as_object_mut().unwrap()) + { + if let Some(version) = params.remove("protocol_version") { + params.insert("version".to_owned(), version); + } + ConvertNetworkName::check(&mut params["network_name"])?; + ConvertTokenSupply::check(&mut params["token_supply"])?; + } + Ok(()) +} + fn migrate_account(account: &mut serde_json::Value) -> Result<()> { for output_data in account["outputs"] .as_object_mut() diff --git a/sdk/tests/wallet/fixtures/check_existing_5_db_test/000008.sst b/sdk/tests/wallet/fixtures/check_existing_5_db_test/000008.sst new file mode 100644 index 0000000000..61e759b8d7 Binary files /dev/null and b/sdk/tests/wallet/fixtures/check_existing_5_db_test/000008.sst differ diff --git a/sdk/tests/wallet/fixtures/check_existing_5_db_test/CURRENT b/sdk/tests/wallet/fixtures/check_existing_5_db_test/CURRENT new file mode 100644 index 0000000000..00d8c47479 --- /dev/null +++ b/sdk/tests/wallet/fixtures/check_existing_5_db_test/CURRENT @@ -0,0 +1 @@ +MANIFEST-000130 diff --git a/sdk/tests/wallet/fixtures/check_existing_5_db_test/IDENTITY b/sdk/tests/wallet/fixtures/check_existing_5_db_test/IDENTITY new file mode 100644 index 0000000000..e743f8f724 --- /dev/null +++ b/sdk/tests/wallet/fixtures/check_existing_5_db_test/IDENTITY @@ -0,0 +1 @@ +005b9a4a-311b-4093-8947-6d1a92f14e53 \ No newline at end of file diff --git a/sdk/tests/wallet/fixtures/check_existing_5_db_test/MANIFEST-000130 b/sdk/tests/wallet/fixtures/check_existing_5_db_test/MANIFEST-000130 new file mode 100644 index 0000000000..188779be97 Binary files /dev/null and b/sdk/tests/wallet/fixtures/check_existing_5_db_test/MANIFEST-000130 differ diff --git a/sdk/tests/wallet/fixtures/check_existing_5_db_test/walletstronghold b/sdk/tests/wallet/fixtures/check_existing_5_db_test/walletstronghold new file mode 100644 index 0000000000..9881773c83 Binary files /dev/null and b/sdk/tests/wallet/fixtures/check_existing_5_db_test/walletstronghold differ diff --git a/sdk/tests/wallet/wallet_storage.rs b/sdk/tests/wallet/wallet_storage.rs index 289182933a..b491345913 100644 --- a/sdk/tests/wallet/wallet_storage.rs +++ b/sdk/tests/wallet/wallet_storage.rs @@ -316,6 +316,41 @@ async fn check_existing_db_4() -> Result<()> { tear_down(storage_path) } +// Db created with iota-sdk commit 37edd0706ee003a0d17c7da19ba974b17b365cfe (@iota/wallet@2.0.2-alpha.32) +#[cfg(feature = "stronghold")] +#[tokio::test] +async fn check_existing_db_5() -> Result<()> { + let storage_path = "check_existing_5_db_test"; + setup(storage_path)?; + // Copy db so the original doesn't get modified + copy_folder("./tests/wallet/fixtures/check_existing_5_db_test", storage_path).unwrap(); + + let wallet = Wallet::builder().with_storage_path(storage_path).finish().await?; + + // Commented because it wasn't created with encrypt_work_factor 0 + // wallet.set_stronghold_password("STRONGHOLD_PASSWORD".to_owned()).await?; + + assert_eq!(wallet.get_accounts().await?.len(), 1); + + let client_options = wallet.client_options().await; + assert_eq!(client_options.node_manager_builder.nodes.len(), 1); + + let account = wallet.get_account("Alice").await?; + + let addresses = account.addresses().await?; + // One public address + assert_eq!(addresses.len(), 1); + // Wallet was created with mnemonic: "endorse answer radar about source reunion marriage tag sausage weekend frost + // daring base attack because joke dream slender leisure group reason prepare broken river" + assert_eq!( + addresses[0].address().to_string(), + "rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy" + ); + assert!(!addresses[0].internal()); + + 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)? {