diff --git a/bindings/core/src/method_handler/client.rs b/bindings/core/src/method_handler/client.rs index 04bd1e2371..4241e1c3b0 100644 --- a/bindings/core/src/method_handler/client.rs +++ b/bindings/core/src/method_handler/client.rs @@ -210,6 +210,8 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM params.rent_structure().byte_factor_data(), ), token_supply: params.token_supply().to_string(), + genesis_unix_timestamp: params.genesis_unix_timestamp(), + slot_duration_in_seconds: params.slot_duration_in_seconds(), }; Response::ProtocolParameters(protocol_response) } diff --git a/sdk/examples/wallet/offline_signing/2_sign_transaction.rs b/sdk/examples/wallet/offline_signing/2_sign_transaction.rs index 8c598c615b..b1a67e7fc1 100644 --- a/sdk/examples/wallet/offline_signing/2_sign_transaction.rs +++ b/sdk/examples/wallet/offline_signing/2_sign_transaction.rs @@ -56,6 +56,8 @@ async fn main() -> Result<()> { .with_byte_factor_key(1) .with_byte_factor_data(10), 1813620509061365, + 1582328545, + 10, ) .unwrap(); diff --git a/sdk/src/client/builder.rs b/sdk/src/client/builder.rs index 51ee7b0bf0..fc6d5995d6 100644 --- a/sdk/src/client/builder.rs +++ b/sdk/src/client/builder.rs @@ -75,6 +75,8 @@ impl From for NetworkInfoDto { info.protocol_parameters.rent_structure().byte_factor_data(), ), token_supply: info.protocol_parameters.token_supply().to_string(), + genesis_unix_timestamp: info.protocol_parameters.genesis_unix_timestamp(), + slot_duration_in_seconds: info.protocol_parameters.slot_duration_in_seconds(), }, local_pow: info.local_pow, fallback_to_local_pow: info.fallback_to_local_pow, diff --git a/sdk/src/client/node_manager/syncing.rs b/sdk/src/client/node_manager/syncing.rs index e6b453d342..6e2f7c7dcd 100644 --- a/sdk/src/client/node_manager/syncing.rs +++ b/sdk/src/client/node_manager/syncing.rs @@ -104,7 +104,8 @@ impl ClientInner { if let Some((info, _node_url)) = nodes.first() { let mut network_info = self.network_info.write().await; - network_info.latest_milestone_timestamp = info.status.latest_milestone.timestamp; + // TODO change to one of the new timestamps, which ones ? + // network_info.latest_milestone_timestamp = info.status.latest_milestone.timestamp; network_info.protocol_parameters = ProtocolParameters::try_from(info.protocol.clone())?; } diff --git a/sdk/src/types/api/core/response.rs b/sdk/src/types/api/core/response.rs index 995d3cd7a5..76c6de5586 100644 --- a/sdk/src/types/api/core/response.rs +++ b/sdk/src/types/api/core/response.rs @@ -9,7 +9,8 @@ use crate::types::block::{ OutputWithMetadata, }, protocol::dto::ProtocolParametersDto, - BlockDto, + slot::SlotIndex, + BlockDto, BlockId, IssuerId, }; /// Response of GET /api/core/v3/info. @@ -23,12 +24,12 @@ use crate::types::block::{ pub struct InfoResponse { pub name: String, pub version: String, + pub issuer_id: IssuerId, pub status: StatusResponse, + pub metrics: MetricsResponse, pub supported_protocol_versions: Vec, pub protocol: ProtocolParametersDto, - pub pending_protocol_parameters: Vec, pub base_token: BaseTokenResponse, - pub metrics: MetricsResponse, pub features: Vec, } @@ -42,57 +43,33 @@ pub struct InfoResponse { )] pub struct StatusResponse { pub is_healthy: bool, - pub latest_milestone: LatestMilestoneResponse, - pub confirmed_milestone: ConfirmedMilestoneResponse, - pub pruning_index: u32, -} - -/// Returned in [`StatusResponse`]. -/// Information about the latest milestone. -#[derive(Clone, Debug, Eq, PartialEq)] -#[cfg_attr( - feature = "serde", - derive(serde::Serialize, serde::Deserialize), - serde(rename_all = "camelCase") -)] -pub struct LatestMilestoneResponse { - pub index: u32, - #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))] - pub timestamp: Option, - #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))] - pub milestone_id: Option, -} - -/// Returned in [`StatusResponse`]. -/// Information about the confirmed milestone. -#[derive(Clone, Debug, Eq, PartialEq)] -#[cfg_attr( - feature = "serde", - derive(serde::Serialize, serde::Deserialize), - serde(rename_all = "camelCase") -)] -pub struct ConfirmedMilestoneResponse { - pub index: u32, - #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))] - pub timestamp: Option, - #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))] - pub milestone_id: Option, + pub last_accepted_block_id: BlockId, + pub last_confirmed_block_id: BlockId, + pub finalized_slot: SlotIndex, + #[cfg_attr(feature = "serde", serde(rename = "ATT"))] + pub att: u64, + #[cfg_attr(feature = "serde", serde(rename = "RATT"))] + pub ratt: u64, + #[cfg_attr(feature = "serde", serde(rename = "CTT"))] + pub ctt: u64, + #[cfg_attr(feature = "serde", serde(rename = "RCTT"))] + pub rctt: u64, + pub latest_committed_slot: SlotIndex, + pub pruning_slot: SlotIndex, } /// Returned in [`InfoResponse`]. -/// Pending protocol parameters. -#[derive(Clone, Debug, Eq, PartialEq)] +/// Metric information about the node. +#[derive(Clone, Debug, PartialEq)] #[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(rename_all = "camelCase") )] -pub struct PendingProtocolParameter { - #[cfg_attr(feature = "serde", serde(rename = "type"))] - pub kind: u8, - pub target_milestone_index: u32, - pub protocol_version: u8, - pub params: String, +pub struct MetricsResponse { + pub blocks_per_second: f64, + pub confirmed_blocks_per_second: f64, + pub confirmed_rate: f64, } /// Returned in [`InfoResponse`]. @@ -109,24 +86,10 @@ pub struct BaseTokenResponse { pub unit: String, #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))] pub subunit: Option, - pub decimals: u8, + pub decimals: u32, pub use_metric_prefix: bool, } -/// Returned in [`InfoResponse`]. -/// Metric information about the node. -#[derive(Clone, Debug, PartialEq)] -#[cfg_attr( - feature = "serde", - derive(serde::Serialize, serde::Deserialize), - serde(rename_all = "camelCase") -)] -pub struct MetricsResponse { - pub blocks_per_second: f64, - pub referenced_blocks_per_second: f64, - pub referenced_rate: f64, -} - /// Response of GET /api/core/v3/tips. /// Returns non-lazy tips. #[derive(Clone, Debug, Eq, PartialEq)] @@ -326,18 +289,6 @@ pub struct PeerResponse { pub gossip: Option, } -/// Response of GET /api/plugins/debug/whiteflag. -/// Returns the computed merkle tree hash for the given white flag traversal. -#[derive(Clone, Debug, Eq, PartialEq)] -#[cfg_attr( - feature = "serde", - derive(serde::Serialize, serde::Deserialize), - serde(rename_all = "camelCase") -)] -pub struct WhiteFlagResponse { - pub merkle_tree_hash: String, -} - /// Response of GET /api/routes. /// Returns the available API route groups of the node. #[derive(Clone, Debug, Eq, PartialEq)] diff --git a/sdk/src/types/block/issuer_id.rs b/sdk/src/types/block/issuer_id.rs new file mode 100644 index 0000000000..c715eb3b96 --- /dev/null +++ b/sdk/src/types/block/issuer_id.rs @@ -0,0 +1,11 @@ +// Copyright 2020-2021 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +impl_id!( + pub IssuerId, + 32, + "Identifier of a block issuer." +); + +#[cfg(feature = "serde")] +string_serde_impl!(IssuerId); diff --git a/sdk/src/types/block/mod.rs b/sdk/src/types/block/mod.rs index 8489480978..487655c827 100644 --- a/sdk/src/types/block/mod.rs +++ b/sdk/src/types/block/mod.rs @@ -8,6 +8,7 @@ mod r#macro; mod block_id; mod convert; mod error; +mod issuer_id; /// A module that provides types and syntactic validations of addresses. pub mod address; @@ -47,6 +48,7 @@ pub use self::{ block_id::BlockId, convert::ConvertTo, error::Error, + issuer_id::IssuerId, }; pub(crate) const PROTOCOL_VERSION: u8 = 2; diff --git a/sdk/src/types/block/protocol.rs b/sdk/src/types/block/protocol.rs index 7ed1e123c8..b8945bd740 100644 --- a/sdk/src/types/block/protocol.rs +++ b/sdk/src/types/block/protocol.rs @@ -36,6 +36,12 @@ pub struct ProtocolParameters { // TokenSupply defines the current token supply on the network. #[cfg_attr(feature = "serde", serde(alias = "tokenSupply"))] token_supply: u64, + // Genesis timestamp at which the slots start to count. + #[cfg_attr(feature = "serde", serde(alias = "genesisUnixTimestamp"))] + genesis_unix_timestamp: u32, + // Duration of each slot in seconds. + #[cfg_attr(feature = "serde", serde(alias = "slotDurationInSeconds"))] + slot_duration_in_seconds: u8, } // This implementation is required to make [`ProtocolParameters`] a [`Packable`] visitor. @@ -50,12 +56,14 @@ impl Default for ProtocolParameters { // PANIC: These values are known to be correct. Self::new( PROTOCOL_VERSION, - String::from("shimmer"), + String::from("iota-core-testnet"), "smr", 1500, 15, RentStructure::default(), 1_813_620_509_061_365, + 1582328545, + 10, ) .unwrap() } @@ -63,6 +71,7 @@ impl Default for ProtocolParameters { impl ProtocolParameters { /// Creates a new [`ProtocolParameters`]. + #[allow(clippy::too_many_arguments)] pub fn new( protocol_version: u8, network_name: String, @@ -71,6 +80,8 @@ impl ProtocolParameters { below_max_depth: u8, rent_structure: RentStructure, token_supply: u64, + genesis_unix_timestamp: u32, + slot_duration_in_seconds: u8, ) -> Result { Ok(Self { protocol_version, @@ -80,6 +91,8 @@ impl ProtocolParameters { below_max_depth, rent_structure, token_supply, + genesis_unix_timestamp, + slot_duration_in_seconds, }) } @@ -122,6 +135,14 @@ impl ProtocolParameters { pub fn token_supply(&self) -> u64 { self.token_supply } + + pub fn genesis_unix_timestamp(&self) -> u32 { + self.genesis_unix_timestamp + } + + pub fn slot_duration_in_seconds(&self) -> u8 { + self.slot_duration_in_seconds + } } /// Returns a [`ProtocolParameters`] for testing purposes. @@ -136,6 +157,8 @@ pub fn protocol_parameters() -> ProtocolParameters { 15, crate::types::block::output::RentStructure::new(500, 10, 1), 1_813_620_509_061_365, + 1582328545, + 10, ) .unwrap() } @@ -161,6 +184,8 @@ pub mod dto { pub below_max_depth: u8, pub rent_structure: RentStructure, pub token_supply: String, + pub genesis_unix_timestamp: u32, + pub slot_duration_in_seconds: u8, } impl TryFrom for ProtocolParameters { @@ -178,6 +203,8 @@ pub mod dto { .token_supply .parse() .map_err(|_| Error::InvalidField("token_supply"))?, + value.genesis_unix_timestamp, + value.slot_duration_in_seconds, ) } } diff --git a/sdk/src/wallet/account/mod.rs b/sdk/src/wallet/account/mod.rs index 3557e0fb58..ecd10d2687 100644 --- a/sdk/src/wallet/account/mod.rs +++ b/sdk/src/wallet/account/mod.rs @@ -490,6 +490,8 @@ fn serialize() { 15, crate::types::block::output::RentStructure::new(500, 10, 1), 1_813_620_509_061_365, + 1582328545, + 10, ) .unwrap(); diff --git a/sdk/src/wallet/account/operations/participation/mod.rs b/sdk/src/wallet/account/operations/participation/mod.rs index 1027ea5a03..0e4ac8f9b9 100644 --- a/sdk/src/wallet/account/operations/participation/mod.rs +++ b/sdk/src/wallet/account/operations/participation/mod.rs @@ -273,7 +273,9 @@ where participations: &mut Participations, ) -> crate::wallet::Result<()> { log::debug!("[remove_ended_participation_events]"); - let latest_milestone_index = self.client().get_info().await?.node_info.status.latest_milestone.index; + // TODO change to one of the new timestamps, which ones ? + let latest_milestone_index = 0; + // let latest_milestone_index = self.client().get_info().await?.node_info.status.latest_milestone.index; let account_index = self.details().await.index; let events = self diff --git a/sdk/tests/client/client_builder.rs b/sdk/tests/client/client_builder.rs index 5288663f33..9cdfcebd37 100644 --- a/sdk/tests/client/client_builder.rs +++ b/sdk/tests/client/client_builder.rs @@ -51,7 +51,9 @@ async fn client_builder() { "vByteFactorKey":10, "vByteFactorData":1 }, - "tokenSupply":1813620509061365 + "tokenSupply":1813620509061365, + "genesisUnixTimestamp":1582328545, + "slotDurationInSeconds":10 }, "localPow":true, "fallbackToLocalPow":true, @@ -105,7 +107,9 @@ async fn client_builder() { "vByteFactorKey":10, "vByteFactorData":1 }, - "tokenSupply":1813620509061365 + "tokenSupply":1813620509061365, + "genesisUnixTimestamp":1582328545, + "slotDurationInSeconds":10 }, "localPow":true, "fallbackToLocalPow":true, diff --git a/sdk/tests/wallet/fixtures/check_existing_1_db_test/000071.sst b/sdk/tests/wallet/fixtures/check_existing_1_db_test/000071.sst deleted file mode 100644 index 69ed084cb8..0000000000 Binary files a/sdk/tests/wallet/fixtures/check_existing_1_db_test/000071.sst and /dev/null differ diff --git a/sdk/tests/wallet/fixtures/check_existing_1_db_test/000074.sst b/sdk/tests/wallet/fixtures/check_existing_1_db_test/000074.sst deleted file mode 100644 index e0ac5f9142..0000000000 Binary files a/sdk/tests/wallet/fixtures/check_existing_1_db_test/000074.sst and /dev/null differ diff --git a/sdk/tests/wallet/fixtures/check_existing_1_db_test/000079.sst b/sdk/tests/wallet/fixtures/check_existing_1_db_test/000079.sst deleted file mode 100644 index 15d32e7f91..0000000000 Binary files a/sdk/tests/wallet/fixtures/check_existing_1_db_test/000079.sst and /dev/null differ diff --git a/sdk/tests/wallet/fixtures/check_existing_1_db_test/CURRENT b/sdk/tests/wallet/fixtures/check_existing_1_db_test/CURRENT deleted file mode 100644 index 635f1ad119..0000000000 --- a/sdk/tests/wallet/fixtures/check_existing_1_db_test/CURRENT +++ /dev/null @@ -1 +0,0 @@ -MANIFEST-000081 diff --git a/sdk/tests/wallet/fixtures/check_existing_1_db_test/IDENTITY b/sdk/tests/wallet/fixtures/check_existing_1_db_test/IDENTITY deleted file mode 100644 index d738fe0907..0000000000 --- a/sdk/tests/wallet/fixtures/check_existing_1_db_test/IDENTITY +++ /dev/null @@ -1 +0,0 @@ -3ebbd3ee-87c9-49db-ba0d-460f89bae548 \ No newline at end of file diff --git a/sdk/tests/wallet/fixtures/check_existing_1_db_test/MANIFEST-000081 b/sdk/tests/wallet/fixtures/check_existing_1_db_test/MANIFEST-000081 deleted file mode 100644 index 4732749d0e..0000000000 Binary files a/sdk/tests/wallet/fixtures/check_existing_1_db_test/MANIFEST-000081 and /dev/null differ diff --git a/sdk/tests/wallet/fixtures/check_existing_2_db_test/000086.sst b/sdk/tests/wallet/fixtures/check_existing_2_db_test/000086.sst deleted file mode 100644 index 514522892d..0000000000 Binary files a/sdk/tests/wallet/fixtures/check_existing_2_db_test/000086.sst and /dev/null differ diff --git a/sdk/tests/wallet/fixtures/check_existing_2_db_test/000089.sst b/sdk/tests/wallet/fixtures/check_existing_2_db_test/000089.sst deleted file mode 100644 index 1930fcddd4..0000000000 Binary files a/sdk/tests/wallet/fixtures/check_existing_2_db_test/000089.sst and /dev/null differ diff --git a/sdk/tests/wallet/fixtures/check_existing_2_db_test/CURRENT b/sdk/tests/wallet/fixtures/check_existing_2_db_test/CURRENT deleted file mode 100644 index 53dc7316bb..0000000000 --- a/sdk/tests/wallet/fixtures/check_existing_2_db_test/CURRENT +++ /dev/null @@ -1 +0,0 @@ -MANIFEST-000155 diff --git a/sdk/tests/wallet/fixtures/check_existing_2_db_test/IDENTITY b/sdk/tests/wallet/fixtures/check_existing_2_db_test/IDENTITY deleted file mode 100644 index 2ec940ecde..0000000000 --- a/sdk/tests/wallet/fixtures/check_existing_2_db_test/IDENTITY +++ /dev/null @@ -1 +0,0 @@ -d85ecfeb-d0ee-4e44-96f6-c6a4077b6b5d \ No newline at end of file diff --git a/sdk/tests/wallet/fixtures/check_existing_2_db_test/MANIFEST-000155 b/sdk/tests/wallet/fixtures/check_existing_2_db_test/MANIFEST-000155 deleted file mode 100644 index ba5b23da5e..0000000000 Binary files a/sdk/tests/wallet/fixtures/check_existing_2_db_test/MANIFEST-000155 and /dev/null differ diff --git a/sdk/tests/wallet/fixtures/check_existing_2_db_test/walletstronghold b/sdk/tests/wallet/fixtures/check_existing_2_db_test/walletstronghold deleted file mode 100644 index 55a6c5cd3a..0000000000 Binary files a/sdk/tests/wallet/fixtures/check_existing_2_db_test/walletstronghold and /dev/null differ diff --git a/sdk/tests/wallet/fixtures/check_existing_db_test/000097.sst b/sdk/tests/wallet/fixtures/check_existing_db_test/000097.sst deleted file mode 100644 index dca88d312d..0000000000 Binary files a/sdk/tests/wallet/fixtures/check_existing_db_test/000097.sst and /dev/null differ diff --git a/sdk/tests/wallet/fixtures/check_existing_db_test/000100.sst b/sdk/tests/wallet/fixtures/check_existing_db_test/000100.sst deleted file mode 100644 index d9b0d210db..0000000000 Binary files a/sdk/tests/wallet/fixtures/check_existing_db_test/000100.sst and /dev/null differ diff --git a/sdk/tests/wallet/fixtures/check_existing_db_test/000105.sst b/sdk/tests/wallet/fixtures/check_existing_db_test/000105.sst deleted file mode 100644 index aa6bfa411e..0000000000 Binary files a/sdk/tests/wallet/fixtures/check_existing_db_test/000105.sst and /dev/null differ diff --git a/sdk/tests/wallet/fixtures/check_existing_db_test/CURRENT b/sdk/tests/wallet/fixtures/check_existing_db_test/CURRENT deleted file mode 100644 index aecd689375..0000000000 --- a/sdk/tests/wallet/fixtures/check_existing_db_test/CURRENT +++ /dev/null @@ -1 +0,0 @@ -MANIFEST-000107 diff --git a/sdk/tests/wallet/fixtures/check_existing_db_test/IDENTITY b/sdk/tests/wallet/fixtures/check_existing_db_test/IDENTITY deleted file mode 100644 index 445c097940..0000000000 --- a/sdk/tests/wallet/fixtures/check_existing_db_test/IDENTITY +++ /dev/null @@ -1 +0,0 @@ -0033d7da-ea2f-4755-b332-c02d9240c886 \ No newline at end of file diff --git a/sdk/tests/wallet/fixtures/check_existing_db_test/MANIFEST-000107 b/sdk/tests/wallet/fixtures/check_existing_db_test/MANIFEST-000107 deleted file mode 100644 index 8192bdce2e..0000000000 Binary files a/sdk/tests/wallet/fixtures/check_existing_db_test/MANIFEST-000107 and /dev/null differ diff --git a/sdk/tests/wallet/fixtures/check_existing_db_test/strongholdfile b/sdk/tests/wallet/fixtures/check_existing_db_test/strongholdfile deleted file mode 100644 index 2f60141860..0000000000 Binary files a/sdk/tests/wallet/fixtures/check_existing_db_test/strongholdfile and /dev/null differ diff --git a/sdk/tests/wallet/mod.rs b/sdk/tests/wallet/mod.rs index 64cf36b942..913326c930 100644 --- a/sdk/tests/wallet/mod.rs +++ b/sdk/tests/wallet/mod.rs @@ -24,6 +24,3 @@ mod syncing; 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_storage.rs b/sdk/tests/wallet/wallet_storage.rs deleted file mode 100644 index 970890bd1c..0000000000 --- a/sdk/tests/wallet/wallet_storage.rs +++ /dev/null @@ -1,225 +0,0 @@ -// Copyright 2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -use std::{fs, io, path::Path}; - -#[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(feature = "stronghold")] -#[tokio::test] -async fn check_existing_db() -> Result<()> { - iota_stronghold::engine::snapshot::try_set_encrypt_work_factor(0).unwrap(); - - let storage_path = "check_existing_db_test"; - setup(storage_path)?; - // Copy db so the original doesn't get modified - copy_folder("./tests/wallet/fixtures/check_existing_db_test", storage_path).unwrap(); - - let wallet = Wallet::builder().with_storage_path(storage_path).finish().await?; - - // Migrate old snapshots. - let _ = StrongholdAdapter::migrate_snapshot_v2_to_v3( - "check_existing_db_test/strongholdfile", - "STRONGHOLD_PASSWORD".to_owned().into(), - "wallet.rs", - 100, - None, - None, - ); - - // Test if setting stronghold password still works - 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 and one internal address - assert_eq!(addresses.len(), 2); - // Wallet was created with mnemonic: "rapid help true please need desk oppose seminar busy large tree speed pepper - // adult hair duty mad chief boil pass coin biology survey fish" - assert_eq!( - addresses[0].address().to_string(), - "rms1qzsw70tha0y4n78s0x0p99ayvz7nl7mzcye7yk8l3s8m6zrfg7slud2ve9f" - ); - assert!(!addresses[0].internal()); - assert_eq!( - addresses[1].address().to_string(), - "rms1qzjwe5plkaywncpv32x5dqqav8fe9zgyzl78cmjlnvzlcghnx489wuevhzf" - ); - assert!(addresses[1].internal()); - - assert_eq!( - account.generate_ed25519_addresses(1, None).await?[0] - .address() - .to_string(), - "rms1qzjclfjq0azmq2yzkkk7ugfhdf55nzvs57r8twk2h36wuqv950dxv00tzfx" - ); - - let transactions = account.transactions().await; - assert_eq!(transactions.len(), 2); - - let pending_transactions = account.pending_transactions().await; - assert_eq!(pending_transactions.len(), 1); - - let incoming_transactions = account.incoming_transactions().await; - assert_eq!(incoming_transactions.len(), 1); - - let unspent_outputs = account.unspent_outputs(None).await?; - assert_eq!(unspent_outputs.len(), 9); - - // balance depends on the network - if &account.client().get_network_name().await? == "private_tangle1" { - let balance = account.balance().await?; - assert_eq!(balance.base_coin().total(), 100000000000); - assert_eq!(balance.base_coin().available(), 99996954100); - } - - tear_down(storage_path) -} - -// Db created with wallet.rs commit 2dd9974c1bc05c2b0b7d6f0ee100deb2da60d071 -#[cfg(feature = "ledger_nano")] -#[tokio::test] -async fn check_existing_db_1() -> Result<()> { - let storage_path = "check_existing_1_db_test"; - setup(storage_path)?; - // Copy db so the original doesn't get modified - copy_folder("./tests/wallet/fixtures/check_existing_1_db_test", storage_path).unwrap(); - - let wallet = Wallet::builder().with_storage_path(storage_path).finish().await?; - - assert!(matches!( - *wallet.get_secret_manager().read().await, - iota_sdk::client::secret::SecretManager::LedgerNano(_) - )); - - 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: "glory promote mansion idle axis finger extra february uncover one trip - // resource lawn turtle enact monster seven myth punch hobby comfort wild raise skin" - assert_eq!( - addresses[0].address().to_string(), - "tst1qqqxdxwaq8ewc7xaph7x9mjpd9fysr0qsj4fpc6kw20wxswmjt7t5r4eupa" - ); - assert!(!addresses[0].internal()); - - let transactions = account.transactions().await; - assert_eq!(transactions.len(), 5); - - let pending_transactions = account.pending_transactions().await; - assert_eq!(pending_transactions.len(), 0); - - let incoming_transactions = account.incoming_transactions().await; - assert_eq!(incoming_transactions.len(), 0); - - let unspent_outputs = account.unspent_outputs(None).await?; - assert_eq!(unspent_outputs.len(), 6); - - tear_down(storage_path) -} - -// Db created with wallet.rs commit b5132eb545cd0a2043640677bca335efee4029b8 -#[cfg(feature = "stronghold")] -#[tokio::test] -async fn check_existing_db_2() -> Result<()> { - iota_stronghold::engine::snapshot::try_set_encrypt_work_factor(0).unwrap(); - - let storage_path = "check_existing_2_db_test"; - setup(storage_path)?; - // Copy db so the original doesn't get modified - copy_folder("./tests/wallet/fixtures/check_existing_2_db_test", storage_path).unwrap(); - - let wallet = Wallet::builder().with_storage_path(storage_path).finish().await?; - - // Migrate old snapshots. - let _ = StrongholdAdapter::migrate_snapshot_v2_to_v3( - "check_existing_2_db_test/walletstronghold", - "STRONGHOLD_PASSWORD".to_owned().into(), - "wallet.rs", - 100, - None, - None, - ); - - // Test if setting stronghold password still works - 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: "memory waste latin swing spy must tail leaf eyebrow meat any river resist sort - // paper bacon aware edit tragic shop mirror ramp foster blue" - assert_eq!( - addresses[0].address().to_string(), - "tst1qqpaynvgh3d3q30zjzjz27g95pzsevw2m5pk75rq32vm7x8ap7hpy2pdy9y" - ); - assert!(!addresses[0].internal()); - - let transactions = account.transactions().await; - assert_eq!(transactions.len(), 5); - - use std::str::FromStr; - let tx = account - .get_transaction(&iota_sdk::types::block::payload::transaction::TransactionId::from_str( - "0x09bb7e0a77f944a4625428d2cdc7a637f5bb5d9a877c9c0b116c909ab4a6795d", - )?) - .await - .expect("missing tx"); - - let iota_sdk::types::block::payload::transaction::TransactionEssence::Regular(essence) = tx.payload.essence(); - if let iota_sdk::types::block::payload::Payload::TaggedData(tagged_data_payload) = essence.payload().unwrap() { - assert_eq!(tagged_data_payload.tag(), "Stardust".as_bytes()); - assert_eq!(tagged_data_payload.data(), "Stardust".as_bytes()); - } else { - panic!("expected tagged data payload") - } - assert_eq!( - tx.inclusion_state, - iota_sdk::wallet::account::types::InclusionState::Pending - ); - - let pending_transactions = account.pending_transactions().await; - assert_eq!(pending_transactions.len(), 1); - - let incoming_transactions = account.incoming_transactions().await; - assert_eq!(incoming_transactions.len(), 0); - - let unspent_outputs = account.unspent_outputs(None).await?; - assert_eq!(unspent_outputs.len(), 4); - - 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)? { - let entry = entry?; - fs::copy(entry.path(), dest.as_ref().join(entry.file_name()))?; - } - Ok(()) -}