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

Fix/cleanup features #660

Merged
merged 2 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 10 additions & 7 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -621,17 +624,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"
Expand Down Expand Up @@ -661,7 +664,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"
Expand All @@ -671,7 +674,7 @@ required-features = [ "wallet" ]
[[example]]
name = "split_funds"
path = "examples/wallet/split_funds.rs"
required-features = [ "wallet" ]
required-features = [ "wallet", "storage" ]

[[example]]
name = "storage"
Expand All @@ -686,7 +689,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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
1 change: 0 additions & 1 deletion sdk/examples/wallet/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions sdk/src/wallet/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 1 addition & 10 deletions sdk/tests/wallet/backup_restore.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down
3 changes: 0 additions & 3 deletions sdk/tests/wallet/migrate_stronghold_snapshot_v2_to_v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions sdk/tests/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

mod account_recovery;
mod accounts;
#[cfg(all(feature = "stronghold", feature = "storage"))]
mod backup_restore;
mod balance;
mod bech32_hrp_validation;
Expand All @@ -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;
Expand All @@ -23,4 +25,5 @@ mod transactions;
#[allow(clippy::module_inception)]
mod wallet;
#[cfg(not(target_os = "windows"))]
#[cfg(feature = "rocksdb")]
mod wallet_storage;
10 changes: 7 additions & 3 deletions sdk/tests/wallet/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 6 additions & 4 deletions sdk/tests/wallet/wallet_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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();
Expand Down
Loading