From 7855f88c6cb6de0b18ab3f1ecf7cf75bceddef86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Mon, 28 Aug 2023 12:01:18 +0200 Subject: [PATCH 1/6] Add db from 37edd0706ee003a0d17c7da19ba974b17b365cfe --- .../check_existing_5_db_test/000008.sst | Bin 0 -> 1874 bytes .../fixtures/check_existing_5_db_test/CURRENT | 1 + .../check_existing_5_db_test/IDENTITY | 1 + .../check_existing_5_db_test/MANIFEST-000130 | Bin 0 -> 190 bytes .../check_existing_5_db_test/walletstronghold | Bin 0 -> 477 bytes sdk/tests/wallet/wallet_storage.rs | 35 ++++++++++++++++++ 6 files changed, 37 insertions(+) create mode 100644 sdk/tests/wallet/fixtures/check_existing_5_db_test/000008.sst create mode 100644 sdk/tests/wallet/fixtures/check_existing_5_db_test/CURRENT create mode 100644 sdk/tests/wallet/fixtures/check_existing_5_db_test/IDENTITY create mode 100644 sdk/tests/wallet/fixtures/check_existing_5_db_test/MANIFEST-000130 create mode 100644 sdk/tests/wallet/fixtures/check_existing_5_db_test/walletstronghold 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 0000000000000000000000000000000000000000..61e759b8d79b1b8c3dce3e46da88119f9499a2d7 GIT binary patch literal 1874 zcmaJ>O>7%Q6n^74v6Cil6Q^lOfhJ1?s$_5M*!fq4(n3X~Dx@S3XcU?8?%1AqcV{~@ z8`}xKKr59)1+9v>Q6z*a!~yXm0ph}y6G9*kJr)Ux1BW)H<>$g%Cr!nLl~&q)Z{C~t zeeZkkpU&F}I8JP;X^|?HR#t_%G`-2B;=&^Y2;A<;!ehThxX?6RqmILLnp&0!Je|&v z_F=e_gKdL*Hme&mnUrA(?yWR@X3XTrvePMpI-DwF#+Y}w#f+5U2Sxmvw{6LkV(3}h zHfRF=n87pBRoU~tPBkQTRVJFJeD%X`4 zJ>@e`KObm6(8JI#df=n&X3B7cRb}=N91HTW1EEDr>M3ezq^1wv#2}k{<&{UEckNx6 zvxGYccgc3M*?;hQyGuPNhM)wNz?`) z>k0b}vUA+1Xzi<+(NXGiQ!}MKrcG7huFIr}-!&ntqsBUN$)rmsAo2>_>%dsH-0-Yt zJz8{_ZOmvHup_W@bRnc-Go)hMP|QNcv*Rhlqn^Oe45B(82pPE72u&F-_s;f#Ugld^ zTW%O(uT-#472#mQiHVeP4cae4hRuMjvr$Pn(41GHjW$FXC+O)L{USP`*5UnT6YwGUMsL9JG$i&??kNZ^#~%10{@33ZU?eJci!qC# zLd|e)Z4>9$VPzO6$ za;IT(8wR2=5(LCAEti}~PB_4RXV{PGB<9wVsmrus8 z5EOklEvklGW7Bn`h&>-ky$%PvEjM%}NPX93I?OBU3Uu}mfeS#Jd+QqFhsmx2!sc>iB6=C-B8eyouNX=U5ZnX- z3PqVVbMR&qJuVKL#1jO!OPQGhmkRZ41ak|sG* z?cIsJN(*}y=srj=OPQtd7S>V#U(akAU|wAS literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..188779be97a2bb05b09e6a105fb8f154ccb89fac GIT binary patch literal 190 zcmWIhx#Ncn10$nUPHI_dPD+xVQ)NkNd1i5{bAE0?Vo_pAeo=+2o>mzHBU2R@D+_Bn z1IHyk`IN+x#H7UHRNdm_jMUsj-Lll8;>`R!Mn(oO5GzhiE=nzl&rQrrOiwLhWQGVc zva+(?y0vjR8yh17I|B!MXkK<+et8}<2P;ILfkz-s**k96JcY_dT^C<`4@ux;JSfBQ cik*RxlYzO3k%g7bYQHrn&?$95elw5{01iho)Bpeg literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..9881773c8358d50388496a26a2d731c716335482 GIT binary patch literal 477 zcmV<30V4iTK~hvn0s!r@KAcDAaCC9mOqal1+?C(MIDBL*s*0!E594QSbtUk4swo`LIyFt)xs)Y8X?)oI>f$RlSLa!DO8Z?=9x1w22?70Xe+sX_O zB*^bYG$`I2I;=5!XDl}U@5SaZ>c}_%Ox=h~zqA`rNa+s~JM^1OFKwiEnz#klSG2ER z6>uyVe23yJaZ-h&Znjyu-%z3Uu>ujDh%!c1v7f z^ZTu@SG6O8;FRb;VSjIxB+?95ACpGbKN6bBEx4rF&_Bcrbg6wjDeyb}l`fbyWnrii TbTa|B`vb~z8l8bJO+1)OMQ!Pv literal 0 HcmV?d00001 diff --git a/sdk/tests/wallet/wallet_storage.rs b/sdk/tests/wallet/wallet_storage.rs index 289182933a..5024f2875b 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(), 2); + + 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)? { From 08a787598c3d60ecae2ecc4a5a25b93650be1f5e Mon Sep 17 00:00:00 2001 From: Alexandcoats Date: Mon, 28 Aug 2023 09:50:04 -0400 Subject: [PATCH 2/6] Properly handle possibly null protocol params (#1090) --- sdk/src/wallet/migration/migrate_1.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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(()) } From 04d7c840221d9e09752dc2ed7b92288f9d551667 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Mon, 28 Aug 2023 11:24:19 -0400 Subject: [PATCH 3/6] Fix migration 3 --- sdk/src/wallet/migration/migrate_3.rs | 28 +++++++++++++++------------ sdk/tests/wallet/wallet_storage.rs | 3 ++- 2 files changed, 18 insertions(+), 13 deletions(-) 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/wallet_storage.rs b/sdk/tests/wallet/wallet_storage.rs index 5024f2875b..f5de14d054 100644 --- a/sdk/tests/wallet/wallet_storage.rs +++ b/sdk/tests/wallet/wallet_storage.rs @@ -330,7 +330,8 @@ async fn check_existing_db_5() -> Result<()> { // 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(), 2); + // TODO: Supposed to be 2 or was that a mistake? + 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); From f3a028ad2dcefa110cdfaa95ac9d74f25caf4741 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Mon, 28 Aug 2023 11:41:04 -0400 Subject: [PATCH 4/6] changelog --- sdk/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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 From 11e0c8a984ae1a70cd8cc15a3ddd271b83fe239a Mon Sep 17 00:00:00 2001 From: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> Date: Tue, 29 Aug 2023 09:19:28 +0200 Subject: [PATCH 5/6] Update sdk/tests/wallet/wallet_storage.rs --- sdk/tests/wallet/wallet_storage.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/tests/wallet/wallet_storage.rs b/sdk/tests/wallet/wallet_storage.rs index f5de14d054..b491345913 100644 --- a/sdk/tests/wallet/wallet_storage.rs +++ b/sdk/tests/wallet/wallet_storage.rs @@ -330,7 +330,6 @@ async fn check_existing_db_5() -> Result<()> { // Commented because it wasn't created with encrypt_work_factor 0 // wallet.set_stronghold_password("STRONGHOLD_PASSWORD".to_owned()).await?; - // TODO: Supposed to be 2 or was that a mistake? assert_eq!(wallet.get_accounts().await?.len(), 1); let client_options = wallet.client_options().await; From 8a0989afbb9e5866af79c1b0bd6a5fe7b6cb9466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Tue, 29 Aug 2023 09:23:08 +0200 Subject: [PATCH 6/6] Nodejs bindings changelog and version bump --- .changes/db-migration.md | 5 +++++ bindings/nodejs/CHANGELOG.md | 6 ++++++ bindings/nodejs/package.json | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changes/db-migration.md 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",