From 7265a92661235ea76097b21e3c83e112fb0479fa Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 3 Oct 2023 17:58:41 +0200 Subject: [PATCH] Warnings --- sdk/src/types/block/output/account.rs | 6 +-- .../client/input_selection/account_outputs.rs | 36 +++++++------ .../client/input_selection/basic_outputs.rs | 50 +++++++++++-------- .../input_selection/storage_deposit_return.rs | 20 +++++--- sdk/tests/client/signing/account.rs | 42 ++++------------ 5 files changed, 72 insertions(+), 82 deletions(-) diff --git a/sdk/src/types/block/output/account.rs b/sdk/src/types/block/output/account.rs index 4b17baaf15..46002aeec5 100644 --- a/sdk/src/types/block/output/account.rs +++ b/sdk/src/types/block/output/account.rs @@ -46,11 +46,7 @@ impl From<&OutputId> for AccountId { impl AccountId { /// pub fn or_from_output_id(self, output_id: &OutputId) -> Self { - if self.is_null() { - Self::from(output_id) - } else { - self - } + if self.is_null() { Self::from(output_id) } else { self } } } diff --git a/sdk/tests/client/input_selection/account_outputs.rs b/sdk/tests/client/input_selection/account_outputs.rs index b2f5f94683..548a1c92bf 100644 --- a/sdk/tests/client/input_selection/account_outputs.rs +++ b/sdk/tests/client/input_selection/account_outputs.rs @@ -1323,22 +1323,26 @@ fn two_accounts_required() { assert!(unsorted_eq(&selected.inputs, &inputs)); assert_eq!(selected.outputs.len(), 3); assert!(selected.outputs.contains(&outputs[0])); - assert!(selected - .outputs - .iter() - .any(|output| if let Output::Account(output) = output { - output.account_id() == &account_id_1 - } else { - false - })); - assert!(selected - .outputs - .iter() - .any(|output| if let Output::Account(output) = output { - output.account_id() == &account_id_2 - } else { - false - })) + assert!( + selected + .outputs + .iter() + .any(|output| if let Output::Account(output) = output { + output.account_id() == &account_id_1 + } else { + false + }) + ); + assert!( + selected + .outputs + .iter() + .any(|output| if let Output::Account(output) = output { + output.account_id() == &account_id_2 + } else { + false + }) + ) } #[test] diff --git a/sdk/tests/client/input_selection/basic_outputs.rs b/sdk/tests/client/input_selection/basic_outputs.rs index 52094bd919..47b757a45f 100644 --- a/sdk/tests/client/input_selection/basic_outputs.rs +++ b/sdk/tests/client/input_selection/basic_outputs.rs @@ -493,10 +493,12 @@ fn ed25519_sender() { // Sender + another for amount assert_eq!(selected.inputs.len(), 2); - assert!(selected - .inputs - .iter() - .any(|input| *input.output.as_basic().address() == sender)); + assert!( + selected + .inputs + .iter() + .any(|input| *input.output.as_basic().address() == sender) + ); // Provided output + remainder assert_eq!(selected.outputs.len(), 2); } @@ -583,10 +585,12 @@ fn account_sender() { // Sender + another for amount assert_eq!(selected.inputs.len(), 2); - assert!(selected - .inputs - .iter() - .any(|input| input.output.is_account() && *input.output.as_account().account_id() == account_id_1)); + assert!( + selected + .inputs + .iter() + .any(|input| input.output.is_account() && *input.output.as_account().account_id() == account_id_1) + ); // Provided output + account assert_eq!(selected.outputs.len(), 2); assert!(selected.outputs.contains(&outputs[0])); @@ -636,10 +640,12 @@ fn account_sender_zero_id() { assert!(unsorted_eq(&selected.inputs, &inputs)); assert_eq!(selected.outputs.len(), 2); - assert!(selected - .outputs - .iter() - .any(|output| output.is_account() && *output.as_account().account_id() == account_id)); + assert!( + selected + .outputs + .iter() + .any(|output| output.is_account() && *output.as_account().account_id() == account_id) + ); } #[test] @@ -725,10 +731,12 @@ fn nft_sender() { // Sender + another for amount assert_eq!(selected.inputs.len(), 2); - assert!(selected - .inputs - .iter() - .any(|input| input.output.is_nft() && *input.output.as_nft().nft_id() == nft_id_1)); + assert!( + selected + .inputs + .iter() + .any(|input| input.output.is_nft() && *input.output.as_nft().nft_id() == nft_id_1) + ); // Provided output + nft assert_eq!(selected.outputs.len(), 2); assert!(selected.outputs.contains(&inputs[2].output)); @@ -781,10 +789,12 @@ fn nft_sender_zero_id() { assert!(unsorted_eq(&selected.inputs, &inputs)); assert_eq!(selected.outputs.len(), 2); - assert!(selected - .outputs - .iter() - .any(|output| output.is_nft() && *output.as_nft().nft_id() == nft_id)); + assert!( + selected + .outputs + .iter() + .any(|output| output.is_nft() && *output.as_nft().nft_id() == nft_id) + ); } #[test] diff --git a/sdk/tests/client/input_selection/storage_deposit_return.rs b/sdk/tests/client/input_selection/storage_deposit_return.rs index 47067ee709..bc90f7e61c 100644 --- a/sdk/tests/client/input_selection/storage_deposit_return.rs +++ b/sdk/tests/client/input_selection/storage_deposit_return.rs @@ -317,14 +317,18 @@ fn two_sdrucs_to_different_addresses_both_needed() { assert!(unsorted_eq(&selected.inputs, &inputs)); assert_eq!(selected.outputs.len(), 3); assert!(selected.outputs.contains(&outputs[0])); - assert!(selected - .outputs - .iter() - .any(|output| { is_remainder_or_return(output, 1_000_000, BECH32_ADDRESS_ED25519_1, None) })); - assert!(selected - .outputs - .iter() - .any(|output| { is_remainder_or_return(output, 1_000_000, BECH32_ADDRESS_ED25519_2, None) })); + assert!( + selected + .outputs + .iter() + .any(|output| { is_remainder_or_return(output, 1_000_000, BECH32_ADDRESS_ED25519_1, None) }) + ); + assert!( + selected + .outputs + .iter() + .any(|output| { is_remainder_or_return(output, 1_000_000, BECH32_ADDRESS_ED25519_2, None) }) + ); } #[test] diff --git a/sdk/tests/client/signing/account.rs b/sdk/tests/client/signing/account.rs index 22840ef566..90fccd41c3 100644 --- a/sdk/tests/client/signing/account.rs +++ b/sdk/tests/client/signing/account.rs @@ -38,7 +38,7 @@ use crate::client::{ async fn sign_account_state_transition() -> Result<()> { let secret_manager = SecretManager::try_from_mnemonic(Client::generate_mnemonic()?)?; - let bech32_address_0 = &secret_manager + let bech32_address = &secret_manager .generate_ed25519_addresses( GetAddressesOptions::default() .with_coin_type(SHIMMER_COIN_TYPE) @@ -46,14 +46,6 @@ async fn sign_account_state_transition() -> Result<()> { ) .await?[0] .to_bech32(SHIMMER_TESTNET_BECH32_HRP); - let bech32_address_1 = &secret_manager - .generate_ed25519_addresses( - GetAddressesOptions::default() - .with_coin_type(SHIMMER_COIN_TYPE) - .with_range(1..2), - ) - .await?[0] - .to_bech32(SHIMMER_TESTNET_BECH32_HRP); let protocol_parameters = protocol_parameters(); let account_id = AccountId::from_str(ACCOUNT_ID_1)?; @@ -61,7 +53,7 @@ async fn sign_account_state_transition() -> Result<()> { let inputs = build_inputs([Account( 1_000_000, account_id, - &bech32_address_0.to_string(), + &bech32_address.to_string(), None, None, None, @@ -71,7 +63,7 @@ async fn sign_account_state_transition() -> Result<()> { let outputs = build_outputs([Account( 1_000_000, account_id, - &bech32_address_0.to_string(), + &bech32_address.to_string(), None, None, None, @@ -124,7 +116,7 @@ async fn sign_account_state_transition() -> Result<()> { async fn sign_account_governance_transition() -> Result<()> { let secret_manager = SecretManager::try_from_mnemonic(Client::generate_mnemonic()?)?; - let bech32_address_0 = &secret_manager + let bech32_address = &secret_manager .generate_ed25519_addresses( GetAddressesOptions::default() .with_coin_type(SHIMMER_COIN_TYPE) @@ -132,14 +124,6 @@ async fn sign_account_governance_transition() -> Result<()> { ) .await?[0] .to_bech32(SHIMMER_TESTNET_BECH32_HRP); - let bech32_address_1 = &secret_manager - .generate_ed25519_addresses( - GetAddressesOptions::default() - .with_coin_type(SHIMMER_COIN_TYPE) - .with_range(1..2), - ) - .await?[0] - .to_bech32(SHIMMER_TESTNET_BECH32_HRP); let protocol_parameters = protocol_parameters(); let account_id = AccountId::from_str(ACCOUNT_ID_1)?; @@ -147,7 +131,7 @@ async fn sign_account_governance_transition() -> Result<()> { let inputs = build_inputs([Account( 1_000_000, account_id, - &bech32_address_0.to_string(), + &bech32_address.to_string(), None, None, None, @@ -157,7 +141,7 @@ async fn sign_account_governance_transition() -> Result<()> { let outputs = build_outputs([Account( 1_000_000, account_id, - &bech32_address_0.to_string(), + &bech32_address.to_string(), None, None, None, @@ -210,7 +194,7 @@ async fn sign_account_governance_transition() -> Result<()> { async fn account_reference_unlocks() -> Result<()> { let secret_manager = SecretManager::try_from_mnemonic(Client::generate_mnemonic()?)?; - let bech32_address_0 = &secret_manager + let bech32_address = &secret_manager .generate_ed25519_addresses( GetAddressesOptions::default() .with_coin_type(SHIMMER_COIN_TYPE) @@ -218,14 +202,6 @@ async fn account_reference_unlocks() -> Result<()> { ) .await?[0] .to_bech32(SHIMMER_TESTNET_BECH32_HRP); - let bech32_address_1 = &secret_manager - .generate_ed25519_addresses( - GetAddressesOptions::default() - .with_coin_type(SHIMMER_COIN_TYPE) - .with_range(1..2), - ) - .await?[0] - .to_bech32(SHIMMER_TESTNET_BECH32_HRP); let protocol_parameters = protocol_parameters(); let account_id = AccountId::from_str(ACCOUNT_ID_1)?; @@ -236,7 +212,7 @@ async fn account_reference_unlocks() -> Result<()> { Account( 1_000_000, account_id, - &bech32_address_0.to_string(), + &bech32_address.to_string(), None, None, None, @@ -268,7 +244,7 @@ async fn account_reference_unlocks() -> Result<()> { Account( 1_000_000, account_id, - &bech32_address_0.to_string(), + &bech32_address.to_string(), None, None, None,