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