diff --git a/Cargo.lock b/Cargo.lock index f0fc6070c4..c766285d37 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1592,12 +1592,39 @@ name = "iota-crypto" version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b059f1e0f2ba0b7253419ff4308fb4f9729f2ad76d49d6bfcf0a64b63a429904" +dependencies = [ + "aead", + "autocfg", + "base64 0.21.2", + "blake2", + "chacha20poly1305", + "cipher", + "curve25519-dalek 3.2.0", + "digest 0.10.7", + "generic-array", + "getrandom", + "hkdf", + "hmac", + "k256", + "pbkdf2", + "rand", + "scrypt", + "serde", + "sha2", + "x25519-dalek", + "zeroize", +] + +[[package]] +name = "iota-crypto" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5d5a986d972c3a703d48ced24fdc0bf16fb2d02959ff4b152fa77b9132f6fb0" dependencies = [ "aead", "aes", "aes-gcm", "autocfg", - "base64 0.21.2", "blake2", "chacha20poly1305", "cipher", @@ -1606,14 +1633,12 @@ dependencies = [ "ed25519-zebra", "generic-array", "getrandom", - "hkdf", "hmac", "iterator-sorted", "k256", "num-traits", "pbkdf2", "rand", - "scrypt", "serde", "sha2", "tiny-keccak", @@ -1664,7 +1689,7 @@ dependencies = [ "heck", "hex", "instant", - "iota-crypto", + "iota-crypto 0.23.0", "iota-ledger-nano", "iota-sdk", "iota_stronghold", @@ -1701,7 +1726,7 @@ dependencies = [ "derivative", "fern-logger", "futures", - "iota-crypto", + "iota-crypto 0.23.0", "iota-sdk", "log", "packable", @@ -1770,13 +1795,13 @@ dependencies = [ [[package]] name = "iota_stronghold" -version = "2.0.0-rc.1" +version = "2.0.0-rc.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec36553cbc1499de54e3c6c6cc8f7f88108a6eb360ded33d97cd207a1b27859d" +checksum = "073d65d06cb5bb352871d2285c44fc0d0e1a654f1bf109fca515ba8229fd1e12" dependencies = [ "bincode", "hkdf", - "iota-crypto", + "iota-crypto 0.23.0", "rust-argon2", "serde", "stronghold-derive", @@ -3165,7 +3190,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51ded9181ba64ef82d0c417cd10779e76900e057f19e135659652f3d5b5d84b6" dependencies = [ "dirs", - "iota-crypto", + "iota-crypto 0.22.2", "libc", "libsodium-sys", "log", @@ -3196,7 +3221,7 @@ dependencies = [ "anyhow", "dirs-next", "hex", - "iota-crypto", + "iota-crypto 0.22.2", "once_cell", "paste", "serde", diff --git a/bindings/core/Cargo.toml b/bindings/core/Cargo.toml index 0b915e7469..fb4190fca0 100644 --- a/bindings/core/Cargo.toml +++ b/bindings/core/Cargo.toml @@ -15,7 +15,7 @@ backtrace = { version = "0.3.68", default-features = false, features = [ "std" ] derivative = { version = "2.2.0", default-features = false } fern-logger = { version = "0.5.0", default-features = false } futures = { version = "0.3.28", default-features = false } -iota-crypto = { version = "0.22.2", default-features = false, features = [ "slip10" ] } +iota-crypto = { version = "0.23.0", default-features = false, features = [ "slip10", "bip44" ] } log = { version = "0.4.19", default-features = false } packable = { version = "0.8.1", default-features = false } prefix-hex = { version = "0.7.0", default-features = false } diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index c8072e25e0..1b54a32d0e 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -25,7 +25,7 @@ derive_more = { version = "0.99.17", default-features = false, features = [ "fro getset = { version = "0.1.2", default-features = false } hashbrown = { version = "0.14.0", default-features = false, features = [ "ahash", "inline-more" ] } hex = { version = "0.4.3", default-features = false } -iota-crypto = { version = "0.22.2", default-features = false, features = [ "blake2b", "ed25519", "secp256k1", "ternary_encoding" ] } +iota-crypto = { version = "0.23.0", default-features = false, features = [ "blake2b", "ed25519", "secp256k1", "ternary_encoding" ] } iterator-sorted = { version = "0.1.0", default-features = false } itertools = { version = "0.11.0", default-features = false, features = [ "use_alloc" ] } packable = { version = "0.8.1", default-features = false, features = [ "primitive-types" ] } @@ -43,7 +43,7 @@ futures = { version = "0.3.28", default-features = false, features = [ "thread-p heck = { version = "0.4.1", default-features = false, optional = true } instant = { version = "0.1.12", default-features = false, optional = true } iota-ledger-nano = { version = "1.0.0-alpha.4", default-features = false, optional = true } -iota_stronghold = { version = "2.0.0-rc.1", default-features = false, optional = true } +iota_stronghold = { version = "2.0.0-rc.2", default-features = false, optional = true } log = { version = "0.4.19", default-features = false, optional = true } num_cpus = { version = "1.16.0", default-features = false, optional = true } once_cell = { version = "1.18.0", default-features = false, optional = true } diff --git a/sdk/examples/how_tos/sign_and_verify_ed25519/sign_ed25519.rs b/sdk/examples/how_tos/sign_and_verify_ed25519/sign_ed25519.rs index 09eb573fef..fde71e50a2 100644 --- a/sdk/examples/how_tos/sign_and_verify_ed25519/sign_ed25519.rs +++ b/sdk/examples/how_tos/sign_and_verify_ed25519/sign_ed25519.rs @@ -38,8 +38,7 @@ async fn main() -> Result<()> { .store_mnemonic(Mnemonic::from(std::env::var("MNEMONIC").unwrap())) .await?; - let bip44_chain = Bip44::new() - .with_coin_type(SHIMMER_COIN_TYPE) + let bip44_chain = Bip44::new(SHIMMER_COIN_TYPE) .with_account(ACCOUNT_INDEX) .with_change(INTERNAL_ADDRESS as _) .with_address_index(ADDRESS_INDEX); diff --git a/sdk/src/client/api/block_builder/input_selection/automatic.rs b/sdk/src/client/api/block_builder/input_selection/automatic.rs index e31675f3be..53f0606b45 100644 --- a/sdk/src/client/api/block_builder/input_selection/automatic.rs +++ b/sdk/src/client/api/block_builder/input_selection/automatic.rs @@ -176,8 +176,7 @@ impl<'a> ClientBlockBuilder<'a> { output: output_with_meta.output, output_metadata: output_with_meta.metadata, chain: Some( - Bip44::new() - .with_coin_type(self.coin_type) + Bip44::new(self.coin_type) .with_account(account_index) .with_change(internal as _) .with_address_index(address_index), diff --git a/sdk/src/client/api/block_builder/input_selection/manual.rs b/sdk/src/client/api/block_builder/input_selection/manual.rs index 5f40b40f0f..d2ad690d2a 100644 --- a/sdk/src/client/api/block_builder/input_selection/manual.rs +++ b/sdk/src/client/api/block_builder/input_selection/manual.rs @@ -80,8 +80,7 @@ impl<'a> ClientBlockBuilder<'a> { output: output_with_meta.output, output_metadata: output_with_meta.metadata, chain: address_index_internal.map(|(address_index, internal)| { - Bip44::new() - .with_coin_type(self.coin_type) + Bip44::new(self.coin_type) .with_account(self.account_index) .with_change(internal as _) .with_address_index(address_index) diff --git a/sdk/src/client/api/block_builder/input_selection/sender_issuer.rs b/sdk/src/client/api/block_builder/input_selection/sender_issuer.rs index e76234d984..d869d65f11 100644 --- a/sdk/src/client/api/block_builder/input_selection/sender_issuer.rs +++ b/sdk/src/client/api/block_builder/input_selection/sender_issuer.rs @@ -71,8 +71,7 @@ impl<'a> ClientBlockBuilder<'a> { output: output_with_meta.output().to_owned(), output_metadata: output_with_meta.metadata().to_owned(), chain: Some( - Bip44::new() - .with_coin_type(self.coin_type) + Bip44::new(self.coin_type) .with_account(self.account_index) .with_change(internal as _) .with_address_index(address_index), @@ -130,8 +129,7 @@ impl<'a> ClientBlockBuilder<'a> { output: output_with_meta.output().to_owned(), output_metadata: output_with_meta.metadata().to_owned(), chain: address_index_internal.map(|(address_index, internal)| { - Bip44::new() - .with_coin_type(self.coin_type) + Bip44::new(self.coin_type) .with_account(self.account_index) .with_change(internal as _) .with_address_index(address_index) @@ -185,8 +183,7 @@ impl<'a> ClientBlockBuilder<'a> { output: output_with_meta.output, output_metadata: output_with_meta.metadata, chain: address_index_internal.map(|(address_index, internal)| { - Bip44::new() - .with_coin_type(self.coin_type) + Bip44::new(self.coin_type) .with_account(self.account_index) .with_change(internal as _) .with_address_index(address_index) diff --git a/sdk/src/client/api/block_builder/input_selection/utxo_chains.rs b/sdk/src/client/api/block_builder/input_selection/utxo_chains.rs index 94c99f70d2..43572124ab 100644 --- a/sdk/src/client/api/block_builder/input_selection/utxo_chains.rs +++ b/sdk/src/client/api/block_builder/input_selection/utxo_chains.rs @@ -189,8 +189,7 @@ impl<'a> ClientBlockBuilder<'a> { output: output_with_meta.output, output_metadata: output_with_meta.metadata, chain: address_index_internal.map(|(address_index, internal)| { - Bip44::new() - .with_coin_type(self.coin_type) + Bip44::new(self.coin_type) .with_account(self.account_index) .with_change(internal as _) .with_address_index(address_index) diff --git a/sdk/src/client/secret/mnemonic.rs b/sdk/src/client/secret/mnemonic.rs index 09aab95466..4ada388673 100644 --- a/sdk/src/client/secret/mnemonic.rs +++ b/sdk/src/client/secret/mnemonic.rs @@ -48,8 +48,7 @@ impl SecretManage for MnemonicSecretManager { Ok(address_indexes .map(|address_index| { - let chain = Bip44::new() - .with_coin_type(coin_type) + let chain = Bip44::new(coin_type) .with_account(account_index) .with_change(internal as _) .with_address_index(address_index); @@ -81,8 +80,7 @@ impl SecretManage for MnemonicSecretManager { Ok(address_indexes .map(|address_index| { - let chain = Bip44::new() - .with_coin_type(coin_type) + let chain = Bip44::new(coin_type) .with_account(account_index) .with_change(internal as _) .with_address_index(address_index); diff --git a/sdk/src/client/stronghold/secret.rs b/sdk/src/client/stronghold/secret.rs index 8baeaf4d49..9f83f69621 100644 --- a/sdk/src/client/stronghold/secret.rs +++ b/sdk/src/client/stronghold/secret.rs @@ -66,8 +66,7 @@ impl SecretManage for StrongholdAdapter { let internal = options.into().map(|o| o.internal).unwrap_or_default(); for address_index in address_indexes { - let chain = Bip44::new() - .with_coin_type(coin_type) + let chain = Bip44::new(coin_type) .with_account(account_index) .with_change(internal as _) .with_address_index(address_index); @@ -139,8 +138,7 @@ impl SecretManage for StrongholdAdapter { let internal = options.into().map(|o| o.internal).unwrap_or_default(); for address_index in address_indexes { - let chain = Bip44::new() - .with_coin_type(coin_type) + let chain = Bip44::new(coin_type) .with_account(account_index) .with_change(internal as _) .with_address_index(address_index); diff --git a/sdk/src/utils/serde.rs b/sdk/src/utils/serde.rs index ee570aa950..bdb91730a7 100644 --- a/sdk/src/utils/serde.rs +++ b/sdk/src/utils/serde.rs @@ -109,17 +109,16 @@ pub mod bip44 { use serde::{Deserialize, Serialize}; #[derive(Default, Serialize, Deserialize)] - #[serde(default, rename_all = "camelCase", remote = "Bip44")] + #[serde(default = "default_bip44", rename_all = "camelCase", remote = "Bip44")] pub struct Bip44Def { - #[serde(default = "default_coin_type")] coin_type: u32, account: u32, change: u32, address_index: u32, } - const fn default_coin_type() -> u32 { - crate::client::constants::IOTA_COIN_TYPE + fn default_bip44() -> Bip44 { + Bip44::new(crate::client::constants::IOTA_COIN_TYPE) } pub mod option_bip44 { diff --git a/sdk/src/wallet/account/operations/syncing/outputs.rs b/sdk/src/wallet/account/operations/syncing/outputs.rs index c63c3face8..4f49f8aedc 100644 --- a/sdk/src/wallet/account/operations/syncing/outputs.rs +++ b/sdk/src/wallet/account/operations/syncing/outputs.rs @@ -49,8 +49,7 @@ where .map_or(false, |tx| !tx.incoming); // BIP 44 (HD wallets) and 4218 is the registered index for IOTA https://github.com/satoshilabs/slips/blob/master/slip-0044.md - let chain = Bip44::new() - .with_coin_type(account_details.coin_type) + let chain = Bip44::new(account_details.coin_type) .with_account(account_details.index) .with_change(associated_address.internal as _) .with_address_index(associated_address.key_index); diff --git a/sdk/src/wallet/account/types/mod.rs b/sdk/src/wallet/account/types/mod.rs index ac9482d969..77b5630d57 100644 --- a/sdk/src/wallet/account/types/mod.rs +++ b/sdk/src/wallet/account/types/mod.rs @@ -71,8 +71,7 @@ impl OutputData { .find(|a| a.address.inner == unlock_address) { Some( - Bip44::new() - .with_coin_type(account.coin_type) + Bip44::new(account.coin_type) .with_account(account.index) .with_change(address.internal as _) .with_address_index(address.key_index), diff --git a/sdk/tests/client/addresses.rs b/sdk/tests/client/addresses.rs index 26c0e2e752..09048a1d6b 100644 --- a/sdk/tests/client/addresses.rs +++ b/sdk/tests/client/addresses.rs @@ -17,7 +17,7 @@ use iota_sdk::{ use serde::{Deserialize, Serialize}; #[tokio::test] -async fn addresses() { +async fn ed25519_addresses() { let secret_manager = crate::client::node_api::setup_secret_manager(); let opts = GetAddressesOptions::default() @@ -40,6 +40,24 @@ async fn addresses() { ); } +#[tokio::test] +async fn evm_addresses() { + let secret_manager = crate::client::node_api::setup_secret_manager(); + + let opts = GetAddressesOptions::default() + .with_bech32_hrp(IOTA_TESTNET_BECH32_HRP) + .with_coin_type(IOTA_COIN_TYPE) + .with_range(0..1); + let public = secret_manager.generate_evm_addresses(opts.clone()).await.unwrap(); + let internal = secret_manager.generate_evm_addresses(opts.internal()).await.unwrap(); + + // Address generated with bip32 path: [44, 4218, 0, 0, 0]. + // This address was generated with a MnemonicSecretManager and verified with an outside source. + // Seed: 0x256a818b2aac458941f7274985a410e57fb750f3a3a67969ece5bd9ae7eef5b2. + assert_eq!(public[0], "0xb23e784f0464a30d536c961e414925eab6b3107d"); + assert_eq!(internal[0], "0x98d8833ec4b82587d66207eb9c578fd0134c51b6"); +} + #[tokio::test] async fn public_key_to_address() { let client = Client::builder().finish().await.unwrap(); @@ -236,6 +254,7 @@ async fn search_address() -> Result<()> { let secret_manager = SecretManager::try_from_mnemonic(generate_mnemonic()?)?; + // Public let addresses = secret_manager .generate_ed25519_addresses( GetAddressesOptions::from_client(&client) @@ -259,5 +278,40 @@ async fn search_address() -> Result<()> { assert_eq!(res, (9, false)); + // Internal + let addresses = secret_manager + .generate_ed25519_addresses( + GetAddressesOptions::from_client(&client) + .await? + .internal() + .with_coin_type(IOTA_COIN_TYPE) + .with_account_index(0) + .with_range(9..10) + .with_bech32_hrp(IOTA_BECH32_HRP), + ) + .await?; + + let res = iota_sdk::client::api::search_address( + &secret_manager, + IOTA_BECH32_HRP, + IOTA_COIN_TYPE, + 0, + 0..10, + &addresses[0], + ) + .await?; + + assert_eq!(res, (9, true)); + + // not in range + let res = + iota_sdk::client::api::search_address(&secret_manager, IOTA_BECH32_HRP, IOTA_COIN_TYPE, 0, 0..9, &addresses[0]) + .await; + + match res { + Err(iota_sdk::client::Error::InputAddressNotFound { .. }) => {} + _ => panic!("should not have found search address range & public"), + } + Ok(()) } diff --git a/sdk/tests/client/input_signing_data.rs b/sdk/tests/client/input_signing_data.rs index e4696e4dfc..b228823772 100644 --- a/sdk/tests/client/input_signing_data.rs +++ b/sdk/tests/client/input_signing_data.rs @@ -21,7 +21,7 @@ use iota_sdk::{ fn input_signing_data_conversion() { let protocol_parameters = protocol_parameters(); - let bip44_chain = Bip44::new().with_coin_type(SHIMMER_COIN_TYPE); + let bip44_chain = Bip44::new(SHIMMER_COIN_TYPE); let output = BasicOutput::build_with_amount(1_000_000) .add_unlock_condition(AddressUnlockCondition::new( diff --git a/sdk/tests/client/node_api/core.rs b/sdk/tests/client/node_api/core.rs index 5628c2a6d3..6eba009642 100644 --- a/sdk/tests/client/node_api/core.rs +++ b/sdk/tests/client/node_api/core.rs @@ -251,7 +251,7 @@ async fn test_get_utxo_changes_by_id() { let node_info = client.get_info().await.unwrap(); let r = client - .get_utxo_changes_by_id(&node_info.node_info.status.latest_milestone.milestone_id.unwrap()) + .get_utxo_changes_by_id(&node_info.node_info.status.confirmed_milestone.milestone_id.unwrap()) .await .unwrap(); @@ -266,9 +266,10 @@ async fn test_get_utxo_changes_by_index() { let node_info = client.get_info().await.unwrap(); let r = client - .get_utxo_changes_by_index(node_info.node_info.status.latest_milestone.index) + .get_utxo_changes_by_index(node_info.node_info.status.confirmed_milestone.index) .await .unwrap(); + assert_eq!(r.index, node_info.node_info.status.confirmed_milestone.index); println!("{r:#?}"); } diff --git a/sdk/tests/client/signing/alias.rs b/sdk/tests/client/signing/alias.rs index c3d00e4cc9..df5f185a19 100644 --- a/sdk/tests/client/signing/alias.rs +++ b/sdk/tests/client/signing/alias.rs @@ -67,7 +67,7 @@ async fn sign_alias_state_transition() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE)), + Some(Bip44::new(SHIMMER_COIN_TYPE)), )]); let outputs = build_outputs([Alias( @@ -158,7 +158,7 @@ async fn sign_alias_governance_transition() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE).with_address_index(1)), + Some(Bip44::new(SHIMMER_COIN_TYPE).with_address_index(1)), )]); let outputs = build_outputs([Alias( @@ -251,7 +251,7 @@ async fn alias_reference_unlocks() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE)), + Some(Bip44::new(SHIMMER_COIN_TYPE)), ), Basic( 1_000_000, diff --git a/sdk/tests/client/signing/basic.rs b/sdk/tests/client/signing/basic.rs index 14718408fb..ed13bd7259 100644 --- a/sdk/tests/client/signing/basic.rs +++ b/sdk/tests/client/signing/basic.rs @@ -51,7 +51,7 @@ async fn single_ed25519_unlock() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE)), + Some(Bip44::new(SHIMMER_COIN_TYPE)), )]); let outputs = build_outputs([Basic( @@ -62,7 +62,7 @@ async fn single_ed25519_unlock() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE)), + Some(Bip44::new(SHIMMER_COIN_TYPE)), )]); let essence = TransactionEssence::Regular( @@ -132,7 +132,7 @@ async fn ed25519_reference_unlocks() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE)), + Some(Bip44::new(SHIMMER_COIN_TYPE)), ), Basic( 1_000_000, @@ -142,7 +142,7 @@ async fn ed25519_reference_unlocks() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE)), + Some(Bip44::new(SHIMMER_COIN_TYPE)), ), Basic( 1_000_000, @@ -152,7 +152,7 @@ async fn ed25519_reference_unlocks() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE)), + Some(Bip44::new(SHIMMER_COIN_TYPE)), ), ]); @@ -164,7 +164,7 @@ async fn ed25519_reference_unlocks() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE)), + Some(Bip44::new(SHIMMER_COIN_TYPE)), )]); let essence = TransactionEssence::Regular( @@ -254,7 +254,7 @@ async fn two_signature_unlocks() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE)), + Some(Bip44::new(SHIMMER_COIN_TYPE)), ), Basic( 1_000_000, @@ -264,7 +264,7 @@ async fn two_signature_unlocks() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE).with_address_index(1)), + Some(Bip44::new(SHIMMER_COIN_TYPE).with_address_index(1)), ), ]); @@ -276,7 +276,7 @@ async fn two_signature_unlocks() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE)), + Some(Bip44::new(SHIMMER_COIN_TYPE)), )]); let essence = TransactionEssence::Regular( diff --git a/sdk/tests/client/signing/mod.rs b/sdk/tests/client/signing/mod.rs index 4298561969..14baff9061 100644 --- a/sdk/tests/client/signing/mod.rs +++ b/sdk/tests/client/signing/mod.rs @@ -93,7 +93,7 @@ async fn all_combined() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE)), + Some(Bip44::new(SHIMMER_COIN_TYPE)), ), Basic( 1_000_000, @@ -163,7 +163,7 @@ async fn all_combined() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE)), + Some(Bip44::new(SHIMMER_COIN_TYPE)), ), Basic( 1_000_000, @@ -173,7 +173,7 @@ async fn all_combined() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE).with_address_index(1)), + Some(Bip44::new(SHIMMER_COIN_TYPE).with_address_index(1)), ), Basic( 1_000_000, @@ -183,7 +183,7 @@ async fn all_combined() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE).with_address_index(2)), + Some(Bip44::new(SHIMMER_COIN_TYPE).with_address_index(2)), ), Basic( 1_000_000, @@ -193,7 +193,7 @@ async fn all_combined() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE).with_address_index(2)), + Some(Bip44::new(SHIMMER_COIN_TYPE).with_address_index(2)), ), Nft( 1_000_000, @@ -204,7 +204,7 @@ async fn all_combined() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE)), + Some(Bip44::new(SHIMMER_COIN_TYPE)), ), Nft( 1_000_000, @@ -246,7 +246,7 @@ async fn all_combined() -> Result<()> { None, None, Some((&nft_3_bech32_address.to_string(), 150)), - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE)), + Some(Bip44::new(SHIMMER_COIN_TYPE)), ), Nft( 1_000_000, diff --git a/sdk/tests/client/signing/nft.rs b/sdk/tests/client/signing/nft.rs index 4204a8e725..7c67ef4e18 100644 --- a/sdk/tests/client/signing/nft.rs +++ b/sdk/tests/client/signing/nft.rs @@ -61,7 +61,7 @@ async fn nft_reference_unlocks() -> Result<()> { None, None, None, - Some(Bip44::new().with_coin_type(SHIMMER_COIN_TYPE)), + Some(Bip44::new(SHIMMER_COIN_TYPE)), ), Basic( 1_000_000, diff --git a/sdk/tests/wallet/balance.rs b/sdk/tests/wallet/balance.rs index 94de55440a..860d0c625b 100644 --- a/sdk/tests/wallet/balance.rs +++ b/sdk/tests/wallet/balance.rs @@ -165,6 +165,76 @@ async fn balance_expiration() -> Result<()> { tear_down(storage_path) } +#[ignore] +#[tokio::test] +async fn addresses_balance() -> Result<()> { + let storage_path = "test-storage/addresses_balance"; + setup(storage_path)?; + + let wallet = make_wallet(storage_path, None, None).await?; + + let account_0 = &create_accounts_with_funds(&wallet, 1).await?[0]; + let account_1 = wallet.create_account().finish().await?; + let addresses_0 = account_0.addresses_with_unspent_outputs().await?; + let acc_1_addr = &account_1.generate_ed25519_addresses(1, None).await?[0]; + + let balance_0 = account_0 + .addresses_balance(addresses_0.iter().map(|a| a.address()).collect()) + .await?; + let balance_0_sync = account_0.balance().await?; + let to_send = balance_0.base_coin().available(); + + // Check if 0 has balance and sync() and address_balance() match + assert!(to_send > 0); + assert_eq!(balance_0, balance_0_sync); + + // Make sure 1 is empty + let balance_1 = account_1.sync(None).await?; + assert_eq!(balance_1.base_coin().available(), 0); + + // Send to 1 + let tx = account_0.send(to_send, acc_1_addr.address(), None).await?; + // Balance should update without sync + let balance_0 = account_0 + .addresses_balance(addresses_0.iter().map(|a| a.address()).collect()) + .await?; + let balance_0_sync = account_0.balance().await?; + assert_eq!(balance_0.base_coin().available(), 0); + assert_eq!(balance_0, balance_0_sync); + + account_0 + .retry_transaction_until_included(&tx.transaction_id, None, None) + .await?; + account_1.sync(None).await?; + + // Balance should have transferred entirely + let balance_1 = account_1.addresses_balance(vec![acc_1_addr.address()]).await?; + let balance_1_sync = account_1.balance().await?; + assert!(balance_1.base_coin().available() > 0); + assert_eq!(balance_1, balance_1_sync); + + // Internal transfer on account 1 + let acc_1_addr_2 = &account_1.generate_ed25519_addresses(1, None).await?[0]; + + let tx = account_1.send(to_send / 2, acc_1_addr_2.address(), None).await?; + account_1 + .retry_transaction_until_included(&tx.transaction_id, None, None) + .await?; + let balance_1_sync = account_1.sync(None).await?; + + // Check the new address + let balance_1 = account_1.addresses_balance(vec![acc_1_addr_2.address()]).await?; + assert_eq!(to_send / 2, balance_1.base_coin().available()); + + // Check old and new together + let balance_1_total = account_1 + .addresses_balance(vec![acc_1_addr.address(), acc_1_addr_2.address()]) + .await?; + assert_eq!(balance_1_total, balance_1_sync); + + tear_down(storage_path) +} + #[ignore] #[tokio::test] #[cfg(feature = "participation")] diff --git a/sdk/tests/wallet/output_preparation.rs b/sdk/tests/wallet/output_preparation.rs index 48dd862b22..827b6933ad 100644 --- a/sdk/tests/wallet/output_preparation.rs +++ b/sdk/tests/wallet/output_preparation.rs @@ -494,7 +494,7 @@ async fn output_preparation_sdr() -> Result<()> { #[ignore] #[tokio::test] async fn prepare_nft_output_features_update() -> Result<()> { - let storage_path = "test-storage/output_preparation"; + let storage_path = "test-storage/prepare_nft_output_features_update"; setup(storage_path)?; let wallet = make_wallet(storage_path, None, None).await?;