From e384f78c1c1b2d9a49006d4052d29b3d832cd3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Thu, 22 Jun 2023 11:25:39 +0200 Subject: [PATCH 1/2] Fix/cleanup features --- sdk/Cargo.toml | 12 ++++++------ sdk/examples/wallet/logger.rs | 1 - sdk/src/wallet/account/mod.rs | 1 + sdk/tests/wallet/backup_restore.rs | 11 +---------- .../wallet/migrate_stronghold_snapshot_v2_to_v3.rs | 3 --- sdk/tests/wallet/mod.rs | 3 +++ sdk/tests/wallet/wallet.rs | 10 +++++++--- sdk/tests/wallet/wallet_storage.rs | 10 ++++++---- 8 files changed, 24 insertions(+), 27 deletions(-) diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index d940e73ae2..aaed3b36dc 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -621,17 +621,17 @@ required-features = [ "wallet", "stronghold" ] [[example]] name = "check_unlock_conditions" path = "examples/wallet/17_check_unlock_conditions.rs" -required-features = [ "wallet" ] +required-features = [ "wallet", "storage" ] [[example]] name = "accounts" path = "examples/wallet/accounts.rs" -required-features = [ "wallet" ] +required-features = [ "wallet", "storage" ] [[example]] name = "background_syncing" path = "examples/wallet/background_syncing.rs" -required-features = [ "wallet" ] +required-features = [ "wallet", "storage" ] [[example]] name = "events" @@ -661,7 +661,7 @@ required-features = [ "wallet", "stronghold" ] [[example]] name = "recover_accounts" path = "examples/wallet/recover_accounts.rs" -required-features = [ "wallet" ] +required-features = [ "wallet", "storage" ] [[example]] name = "spammer" @@ -671,7 +671,7 @@ required-features = [ "wallet" ] [[example]] name = "split_funds" path = "examples/wallet/split_funds.rs" -required-features = [ "wallet" ] +required-features = [ "wallet", "storage" ] [[example]] name = "storage" @@ -686,7 +686,7 @@ required-features = [ "wallet", "stronghold" ] [[example]] name = "wallet" path = "examples/wallet/wallet.rs" -required-features = [ "wallet" ] +required-features = [ "wallet", "storage" ] [[example]] name = "migrate_stronghold_snapshot_v2_to_v3" diff --git a/sdk/examples/wallet/logger.rs b/sdk/examples/wallet/logger.rs index 986ff883fd..bf1154e610 100644 --- a/sdk/examples/wallet/logger.rs +++ b/sdk/examples/wallet/logger.rs @@ -42,7 +42,6 @@ async fn main() -> Result<()> { MnemonicSecretManager::try_from_mnemonic(var("NON_SECURE_USE_OF_DEVELOPMENT_MNEMONIC_1").unwrap())?; let wallet = Wallet::builder() .with_secret_manager(SecretManager::Mnemonic(secret_manager)) - .with_storage_path(&var("WALLET_DB_PATH").unwrap()) .with_client_options(client_options) .with_coin_type(SHIMMER_COIN_TYPE) .finish() diff --git a/sdk/src/wallet/account/mod.rs b/sdk/src/wallet/account/mod.rs index 7ac89e254f..3557e0fb58 100644 --- a/sdk/src/wallet/account/mod.rs +++ b/sdk/src/wallet/account/mod.rs @@ -567,6 +567,7 @@ impl AccountDetails { /// index: 0, coin_type: 4218, alias: "Alice", public_addresses: contains a single public account address /// (rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy), all other fields are set to their Rust /// defaults. + #[cfg(feature = "storage")] pub(crate) fn mock() -> Self { Self { index: 0, diff --git a/sdk/tests/wallet/backup_restore.rs b/sdk/tests/wallet/backup_restore.rs index 8c7b4c0af0..832145040b 100644 --- a/sdk/tests/wallet/backup_restore.rs +++ b/sdk/tests/wallet/backup_restore.rs @@ -1,25 +1,21 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -#[cfg(all(feature = "stronghold", feature = "storage"))] use std::path::PathBuf; -#[cfg(all(feature = "stronghold", feature = "storage"))] -use iota_sdk::wallet::{ClientOptions, Result, Wallet}; -#[cfg(all(feature = "stronghold", feature = "storage"))] use iota_sdk::{ client::{ constants::{IOTA_COIN_TYPE, SHIMMER_COIN_TYPE}, node_manager::node::{Node, NodeDto}, secret::{mnemonic::MnemonicSecretManager, stronghold::StrongholdSecretManager, SecretManager}, }, + wallet::{ClientOptions, Result, Wallet}, Url, }; use crate::wallet::common::{setup, tear_down, NODE_LOCAL, NODE_OTHER}; #[tokio::test] -#[cfg(all(feature = "stronghold", feature = "storage"))] // Backup and restore with Stronghold async fn backup_and_restore() -> Result<()> { iota_stronghold::engine::snapshot::try_set_encrypt_work_factor(0).unwrap(); @@ -114,7 +110,6 @@ async fn backup_and_restore() -> Result<()> { } #[tokio::test] -#[cfg(all(feature = "stronghold", feature = "storage"))] // Backup and restore with Stronghold and MnemonicSecretManager async fn backup_and_restore_mnemonic_secret_manager() -> Result<()> { iota_stronghold::engine::snapshot::try_set_encrypt_work_factor(0).unwrap(); @@ -197,7 +192,6 @@ async fn backup_and_restore_mnemonic_secret_manager() -> Result<()> { } #[tokio::test] -#[cfg(all(feature = "stronghold", feature = "storage"))] // Backup and restore with Stronghold async fn backup_and_restore_different_coin_type() -> Result<()> { iota_stronghold::engine::snapshot::try_set_encrypt_work_factor(0).unwrap(); @@ -282,7 +276,6 @@ async fn backup_and_restore_different_coin_type() -> Result<()> { } #[tokio::test] -#[cfg(all(feature = "stronghold", feature = "storage"))] // Backup and restore with Stronghold async fn backup_and_restore_same_coin_type() -> Result<()> { iota_stronghold::engine::snapshot::try_set_encrypt_work_factor(0).unwrap(); @@ -365,7 +358,6 @@ async fn backup_and_restore_same_coin_type() -> Result<()> { } #[tokio::test] -#[cfg(all(feature = "stronghold", feature = "storage"))] // Backup and restore with Stronghold async fn backup_and_restore_different_coin_type_dont_ignore() -> Result<()> { iota_stronghold::engine::snapshot::try_set_encrypt_work_factor(0).unwrap(); @@ -454,7 +446,6 @@ async fn backup_and_restore_different_coin_type_dont_ignore() -> Result<()> { } #[tokio::test] -#[cfg(all(feature = "stronghold", feature = "storage"))] async fn backup_and_restore_bech32_hrp_mismatch() -> Result<()> { iota_stronghold::engine::snapshot::try_set_encrypt_work_factor(0).unwrap(); diff --git a/sdk/tests/wallet/migrate_stronghold_snapshot_v2_to_v3.rs b/sdk/tests/wallet/migrate_stronghold_snapshot_v2_to_v3.rs index 415ca8333f..794e9f8247 100644 --- a/sdk/tests/wallet/migrate_stronghold_snapshot_v2_to_v3.rs +++ b/sdk/tests/wallet/migrate_stronghold_snapshot_v2_to_v3.rs @@ -20,7 +20,6 @@ use crate::wallet::common::{setup, tear_down, NODE_LOCAL}; const PBKDF_SALT: &str = "wallet.rs"; const PBKDF_ITER: u32 = 100; -#[cfg(feature = "stronghold")] #[tokio::test] async fn stronghold_snapshot_v2_v3_migration() { iota_stronghold::engine::snapshot::try_set_encrypt_work_factor(0).unwrap(); @@ -117,7 +116,6 @@ async fn stronghold_snapshot_v2_v3_migration() { tear_down(storage_path).unwrap(); } -#[cfg(feature = "stronghold")] #[tokio::test] async fn stronghold_snapshot_v2_v3_migration_same_path() { iota_stronghold::engine::snapshot::try_set_encrypt_work_factor(0).unwrap(); @@ -155,7 +153,6 @@ async fn stronghold_snapshot_v2_v3_migration_same_path() { std::fs::remove_file("./tests/wallet/fixtures/v2-copy.stronghold").unwrap(); } -#[cfg(feature = "stronghold")] #[tokio::test] async fn stronghold_snapshot_v2_v3_migration_with_backup() { iota_stronghold::engine::snapshot::try_set_encrypt_work_factor(0).unwrap(); diff --git a/sdk/tests/wallet/mod.rs b/sdk/tests/wallet/mod.rs index ec2d24cd81..64cf36b942 100644 --- a/sdk/tests/wallet/mod.rs +++ b/sdk/tests/wallet/mod.rs @@ -3,6 +3,7 @@ mod account_recovery; mod accounts; +#[cfg(all(feature = "stronghold", feature = "storage"))] mod backup_restore; mod balance; mod bech32_hrp_validation; @@ -15,6 +16,7 @@ mod error; mod events; #[cfg(feature = "message_interface")] mod message_interface; +#[cfg(feature = "stronghold")] mod migrate_stronghold_snapshot_v2_to_v3; mod native_tokens; mod output_preparation; @@ -23,4 +25,5 @@ mod transactions; #[allow(clippy::module_inception)] mod wallet; #[cfg(not(target_os = "windows"))] +#[cfg(feature = "rocksdb")] mod wallet_storage; diff --git a/sdk/tests/wallet/wallet.rs b/sdk/tests/wallet/wallet.rs index 68597435f0..48b74fb9fd 100644 --- a/sdk/tests/wallet/wallet.rs +++ b/sdk/tests/wallet/wallet.rs @@ -5,19 +5,23 @@ use iota_sdk::client::secret::stronghold::StrongholdSecretManager; #[cfg(feature = "storage")] use iota_sdk::{ + client::constants::SHIMMER_COIN_TYPE, client::node_manager::node::{Node, NodeDto}, + wallet::Error, Url, }; use iota_sdk::{ client::{ - constants::{IOTA_COIN_TYPE, SHIMMER_COIN_TYPE}, + constants::IOTA_COIN_TYPE, secret::{mnemonic::MnemonicSecretManager, SecretManager}, }, types::block::address::{Bech32Address, ToBech32Ext}, - wallet::{ClientOptions, Error, Result, Wallet}, + wallet::{ClientOptions, Result, Wallet}, }; -use crate::wallet::common::{make_wallet, setup, tear_down, DEFAULT_MNEMONIC, NODE_LOCAL, NODE_OTHER}; +#[cfg(feature = "storage")] +use crate::wallet::common::NODE_OTHER; +use crate::wallet::common::{make_wallet, setup, tear_down, DEFAULT_MNEMONIC, NODE_LOCAL}; #[cfg(feature = "storage")] #[tokio::test] diff --git a/sdk/tests/wallet/wallet_storage.rs b/sdk/tests/wallet/wallet_storage.rs index 1072640555..970890bd1c 100644 --- a/sdk/tests/wallet/wallet_storage.rs +++ b/sdk/tests/wallet/wallet_storage.rs @@ -3,12 +3,14 @@ use std::{fs, io, path::Path}; -use iota_sdk::{client::stronghold::StrongholdAdapter, wallet::Result, Wallet}; +#[cfg(feature = "stronghold")] +use iota_sdk::client::stronghold::StrongholdAdapter; +use iota_sdk::{wallet::Result, Wallet}; use crate::wallet::common::{setup, tear_down}; // Db created with wallet.rs commit 8dd389ddeed0d95bb493c38f376b41a6a9127148 -#[cfg(all(feature = "stronghold", feature = "rocksdb"))] +#[cfg(feature = "stronghold")] #[tokio::test] async fn check_existing_db() -> Result<()> { iota_stronghold::engine::snapshot::try_set_encrypt_work_factor(0).unwrap(); @@ -86,7 +88,7 @@ async fn check_existing_db() -> Result<()> { } // Db created with wallet.rs commit 2dd9974c1bc05c2b0b7d6f0ee100deb2da60d071 -#[cfg(all(feature = "ledger_nano", feature = "rocksdb"))] +#[cfg(feature = "ledger_nano")] #[tokio::test] async fn check_existing_db_1() -> Result<()> { let storage_path = "check_existing_1_db_test"; @@ -135,7 +137,7 @@ async fn check_existing_db_1() -> Result<()> { } // Db created with wallet.rs commit b5132eb545cd0a2043640677bca335efee4029b8 -#[cfg(all(feature = "stronghold", feature = "rocksdb"))] +#[cfg(feature = "stronghold")] #[tokio::test] async fn check_existing_db_2() -> Result<()> { iota_stronghold::engine::snapshot::try_set_encrypt_work_factor(0).unwrap(); From 7ea8baa82b2cdb946176a8809f33738787010e6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Thu, 22 Jun 2023 11:33:15 +0200 Subject: [PATCH 2/2] fix more --- sdk/Cargo.toml | 5 ++++- .../sign_and_verify_ed25519/verify_ed25519_signature.rs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index aaed3b36dc..1bfb783960 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -103,7 +103,7 @@ wallet = [ "client" ] [[example]] name = "sign_and_verify_ed25519" path = "examples/how_tos/sign_and_verify_ed25519/sign_ed25519.rs" -required-features = [ "stronghold" ] +required-features = [ "wallet", "stronghold" ] [[example]] name = "verify_ed25519_signature" @@ -114,6 +114,7 @@ path = "examples/how_tos/sign_and_verify_ed25519/verify_ed25519_signature.rs" [[example]] name = "create_mnemonic" path = "examples/how_tos/accounts_and_addresses/create_mnemonic.rs" +required-features = [ "client" ] [[example]] name = "create_account" @@ -228,10 +229,12 @@ required-features = [ "rocksdb", "stronghold" ] [[example]] name = "output_unlock_conditions" path = "examples/how_tos/outputs/unlock_conditions.rs" +required-features = [ "client" ] [[example]] name = "output_features" path = "examples/how_tos/outputs/features.rs" +required-features = [ "client" ] # Block examples diff --git a/sdk/examples/how_tos/sign_and_verify_ed25519/verify_ed25519_signature.rs b/sdk/examples/how_tos/sign_and_verify_ed25519/verify_ed25519_signature.rs index 644adddbc8..00e0f2a9b4 100644 --- a/sdk/examples/how_tos/sign_and_verify_ed25519/verify_ed25519_signature.rs +++ b/sdk/examples/how_tos/sign_and_verify_ed25519/verify_ed25519_signature.rs @@ -7,13 +7,13 @@ //! cargo run --release --all-features --example verify_ed25519_signature //! ``` -use iota_sdk::{crypto::signatures::ed25519, wallet::Result}; +use iota_sdk::{crypto::signatures::ed25519, types::block::Error}; const FOUNDRY_METADATA: &str = r#"{"standard":"IRC30","name":"NativeToken","description":"A native token","symbol":"NT","decimals":6,"logoUrl":"https://my.website/nativeToken.png"}"#; const PUBLIC_KEY: &str = "0x67b7fc3f78763c9394fc4fcdb52cf3a973b6e064bdc3defb40a6cb2c880e6f5c"; const ED25519_SIGNATURE: &str = "0x5437ee671f182507103c6ae2f6649083475019f2cc372e674be164577dd123edd7a76291ba88732bbe1fae39688b50a3678bce05c9ef32c9494b3968f4f07a01"; -fn main() -> Result<()> { +fn main() -> Result<(), Error> { let ed25519_public_key = ed25519::PublicKey::try_from_bytes(prefix_hex::decode(PUBLIC_KEY).unwrap())?; let ed25519_signature = ed25519::Signature::from_bytes(prefix_hex::decode(ED25519_SIGNATURE).unwrap());