From c51f7c8b01b9cdf2f55d0d7c3de609bcfeec1e62 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Mon, 27 Nov 2023 13:55:12 -0500 Subject: [PATCH 01/11] validate some mana semantics --- .../client/api/block_builder/transaction.rs | 3 + sdk/src/client/secret/mod.rs | 2 +- sdk/src/types/block/semantic.rs | 62 +++++++++++++++++-- sdk/src/wallet/operations/transaction/mod.rs | 6 +- sdk/tests/client/signing/account.rs | 4 +- sdk/tests/client/signing/basic.rs | 6 +- sdk/tests/client/signing/mod.rs | 2 +- sdk/tests/client/signing/nft.rs | 2 +- 8 files changed, 72 insertions(+), 15 deletions(-) diff --git a/sdk/src/client/api/block_builder/transaction.rs b/sdk/src/client/api/block_builder/transaction.rs index b8016821cd..b155886939 100644 --- a/sdk/src/client/api/block_builder/transaction.rs +++ b/sdk/src/client/api/block_builder/transaction.rs @@ -10,6 +10,7 @@ use crate::{ types::block::{ output::{Output, OutputId}, payload::signed_transaction::{SignedTransactionPayload, Transaction}, + protocol::ProtocolParameters, semantic::{SemanticValidationContext, TransactionFailureReason}, signature::Ed25519Signature, Block, BlockId, @@ -28,6 +29,7 @@ const REFERENCE_ACCOUNT_NFT_UNLOCK_LENGTH: usize = 1 + 2; pub fn verify_semantic( input_signing_data: &[InputSigningData], transaction_payload: &SignedTransactionPayload, + protocol_parameters: ProtocolParameters, ) -> crate::client::Result> { let transaction_id = transaction_payload.transaction().id(); let inputs = input_signing_data @@ -40,6 +42,7 @@ pub fn verify_semantic( &transaction_id, &inputs, transaction_payload.unlocks(), + protocol_parameters, ); Ok(context.validate()?) diff --git a/sdk/src/client/secret/mod.rs b/sdk/src/client/secret/mod.rs index c9af7bc968..034e80383a 100644 --- a/sdk/src/client/secret/mod.rs +++ b/sdk/src/client/secret/mod.rs @@ -611,7 +611,7 @@ where validate_signed_transaction_payload_length(&tx_payload)?; - let conflict = verify_semantic(&inputs_data, &tx_payload)?; + let conflict = verify_semantic(&inputs_data, &tx_payload, todo!())?; if let Some(conflict) = conflict { log::debug!("[sign_transaction] conflict: {conflict:?} for {:#?}", tx_payload); diff --git a/sdk/src/types/block/semantic.rs b/sdk/src/types/block/semantic.rs index b43ebbaab6..bfb5c1672e 100644 --- a/sdk/src/types/block/semantic.rs +++ b/sdk/src/types/block/semantic.rs @@ -10,10 +10,11 @@ use primitive_types::U256; use crate::types::block::{ address::{Address, AddressCapabilityFlag}, output::{ - AccountId, AnchorOutput, ChainId, FoundryId, NativeTokens, Output, OutputId, StateTransitionError, TokenId, - UnlockCondition, + AccountId, AnchorOutput, ChainId, FoundryId, MinimumOutputAmount, NativeTokens, Output, OutputId, + StateTransitionError, TokenId, UnlockCondition, }, payload::signed_transaction::{Transaction, TransactionCapabilityFlag, TransactionId, TransactionSigningHash}, + protocol::ProtocolParameters, unlock::Unlocks, Error, }; @@ -206,6 +207,7 @@ pub struct SemanticValidationContext<'a> { pub(crate) unlocked_addresses: HashSet
, pub(crate) storage_deposit_returns: HashMap, pub(crate) simple_deposits: HashMap, + pub(crate) protocol_parameters: ProtocolParameters, } impl<'a> SemanticValidationContext<'a> { @@ -215,6 +217,7 @@ impl<'a> SemanticValidationContext<'a> { transaction_id: &TransactionId, inputs: &'a [(&'a OutputId, &'a Output)], unlocks: &'a Unlocks, + protocol_parameters: ProtocolParameters, ) -> Self { let input_chains = inputs .iter() @@ -258,6 +261,7 @@ impl<'a> SemanticValidationContext<'a> { unlocked_addresses: HashSet::new(), storage_deposit_returns: HashMap::new(), simple_deposits: HashMap::new(), + protocol_parameters, } } @@ -330,7 +334,37 @@ impl<'a> SemanticValidationContext<'a> { .checked_add(amount) .ok_or(Error::ConsumedAmountOverflow)?; - self.input_mana = self.input_mana.checked_add(mana).ok_or(Error::ConsumedManaOverflow)?; + let potential_mana = { + let min_amount = consumed_output.minimum_amount(self.protocol_parameters.storage_score_parameters()); + + let generation_amount = consumed_output.amount().checked_sub(min_amount).unwrap_or_default(); + + self.protocol_parameters.potential_mana( + generation_amount, + output_id.transaction_id().slot_index(), + self.transaction.creation_slot(), + ) + }?; + + // Add potential mana + self.input_mana = self + .input_mana + .checked_add(potential_mana) + .ok_or(Error::ConsumedManaOverflow)?; + + let stored_mana = self.protocol_parameters.mana_with_decay( + mana, + output_id.transaction_id().slot_index(), + self.transaction.creation_slot(), + )?; + + // Add stored mana + self.input_mana = self + .input_mana + .checked_add(stored_mana) + .ok_or(Error::ConsumedManaOverflow)?; + + // TODO: Add reward mana if let Some(consumed_native_token) = consumed_native_token { let native_token_amount = self @@ -440,8 +474,17 @@ impl<'a> SemanticValidationContext<'a> { .checked_add(amount) .ok_or(Error::CreatedAmountOverflow)?; + // Add stored mana self.output_mana = self.output_mana.checked_add(mana).ok_or(Error::CreatedManaOverflow)?; + // Add allotted mana + for mana_allotment in self.transaction.allotments() { + self.output_mana = self + .output_mana + .checked_add(mana_allotment.mana()) + .ok_or(Error::CreatedManaOverflow)?; + } + if let Some(created_native_token) = created_native_token { let native_token_amount = self .output_native_tokens @@ -470,9 +513,16 @@ impl<'a> SemanticValidationContext<'a> { return Ok(Some(TransactionFailureReason::SumInputsOutputsAmountMismatch)); } - if self.input_mana > self.output_mana && !self.transaction.has_capability(TransactionCapabilityFlag::BurnMana) { - // TODO: add a variant https://github.com/iotaledger/iota-sdk/issues/1430 - return Ok(Some(TransactionFailureReason::SemanticValidationFailed)); + if self.input_mana != self.output_mana { + if self.input_mana > self.output_mana + && !self.transaction.has_capability(TransactionCapabilityFlag::BurnMana) + { + return Ok(Some( + TransactionFailureReason::TransactionCapabilityManaBurningNotAllowed, + )); + } else { + return Ok(Some(TransactionFailureReason::InvalidManaAmount)); + } } // Validation of input native tokens. diff --git a/sdk/src/wallet/operations/transaction/mod.rs b/sdk/src/wallet/operations/transaction/mod.rs index 5bf828b771..4f68a96b1d 100644 --- a/sdk/src/wallet/operations/transaction/mod.rs +++ b/sdk/src/wallet/operations/transaction/mod.rs @@ -130,7 +130,11 @@ where let options = options.into(); // Validate transaction before sending and storing it - let conflict = verify_semantic(&signed_transaction_data.inputs_data, &signed_transaction_data.payload)?; + let conflict = verify_semantic( + &signed_transaction_data.inputs_data, + &signed_transaction_data.payload, + self.client().get_protocol_parameters().await?, + )?; if let Some(conflict) = conflict { log::debug!( diff --git a/sdk/tests/client/signing/account.rs b/sdk/tests/client/signing/account.rs index 1299085942..df2a711137 100644 --- a/sdk/tests/client/signing/account.rs +++ b/sdk/tests/client/signing/account.rs @@ -93,7 +93,7 @@ async fn sign_account_state_transition() -> Result<()> { validate_signed_transaction_payload_length(&tx_payload)?; - let conflict = verify_semantic(&prepared_transaction_data.inputs_data, &tx_payload)?; + let conflict = verify_semantic(&prepared_transaction_data.inputs_data, &tx_payload, protocol_parameters)?; if let Some(conflict) = conflict { panic!("{conflict:?}, with {tx_payload:#?}"); @@ -204,7 +204,7 @@ async fn account_reference_unlocks() -> Result<()> { validate_signed_transaction_payload_length(&tx_payload)?; - let conflict = verify_semantic(&prepared_transaction_data.inputs_data, &tx_payload)?; + let conflict = verify_semantic(&prepared_transaction_data.inputs_data, &tx_payload, protocol_parameters)?; if let Some(conflict) = conflict { panic!("{conflict:?}, with {tx_payload:#?}"); diff --git a/sdk/tests/client/signing/basic.rs b/sdk/tests/client/signing/basic.rs index e0b1519fbb..2506f22cce 100644 --- a/sdk/tests/client/signing/basic.rs +++ b/sdk/tests/client/signing/basic.rs @@ -89,7 +89,7 @@ async fn single_ed25519_unlock() -> Result<()> { validate_signed_transaction_payload_length(&tx_payload)?; - let conflict = verify_semantic(&prepared_transaction_data.inputs_data, &tx_payload)?; + let conflict = verify_semantic(&prepared_transaction_data.inputs_data, &tx_payload, protocol_parameters)?; if let Some(conflict) = conflict { panic!("{conflict:?}, with {tx_payload:#?}"); @@ -196,7 +196,7 @@ async fn ed25519_reference_unlocks() -> Result<()> { validate_signed_transaction_payload_length(&tx_payload)?; - let conflict = verify_semantic(&prepared_transaction_data.inputs_data, &tx_payload)?; + let conflict = verify_semantic(&prepared_transaction_data.inputs_data, &tx_payload, protocol_parameters)?; if let Some(conflict) = conflict { panic!("{conflict:?}, with {tx_payload:#?}"); @@ -291,7 +291,7 @@ async fn two_signature_unlocks() -> Result<()> { validate_signed_transaction_payload_length(&tx_payload)?; - let conflict = verify_semantic(&prepared_transaction_data.inputs_data, &tx_payload)?; + let conflict = verify_semantic(&prepared_transaction_data.inputs_data, &tx_payload, protocol_parameters)?; if let Some(conflict) = conflict { panic!("{conflict:?}, with {tx_payload:#?}"); diff --git a/sdk/tests/client/signing/mod.rs b/sdk/tests/client/signing/mod.rs index fba3641404..d76889e386 100644 --- a/sdk/tests/client/signing/mod.rs +++ b/sdk/tests/client/signing/mod.rs @@ -457,7 +457,7 @@ async fn all_combined() -> Result<()> { validate_signed_transaction_payload_length(&tx_payload)?; - let conflict = verify_semantic(&prepared_transaction_data.inputs_data, &tx_payload)?; + let conflict = verify_semantic(&prepared_transaction_data.inputs_data, &tx_payload, protocol_parameters)?; if let Some(conflict) = conflict { panic!("{conflict:?}, with {tx_payload:#?}"); diff --git a/sdk/tests/client/signing/nft.rs b/sdk/tests/client/signing/nft.rs index 8ca9d544f1..92c940e70d 100644 --- a/sdk/tests/client/signing/nft.rs +++ b/sdk/tests/client/signing/nft.rs @@ -144,7 +144,7 @@ async fn nft_reference_unlocks() -> Result<()> { validate_signed_transaction_payload_length(&tx_payload)?; - let conflict = verify_semantic(&prepared_transaction_data.inputs_data, &tx_payload)?; + let conflict = verify_semantic(&prepared_transaction_data.inputs_data, &tx_payload, protocol_parameters)?; if let Some(conflict) = conflict { panic!("{conflict:?}, with {tx_payload:#?}"); From a0ad146dcb0439d040c9bbb190a0d063dc801713 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 18 Dec 2023 18:43:12 +0100 Subject: [PATCH 02/11] Cleanup --- sdk/src/types/block/mana/allotment.rs | 128 ++++++++++++++++++++++- sdk/src/types/block/mana/mod.rs | 136 ++----------------------- sdk/src/types/block/mana/parameters.rs | 7 ++ 3 files changed, 140 insertions(+), 131 deletions(-) diff --git a/sdk/src/types/block/mana/allotment.rs b/sdk/src/types/block/mana/allotment.rs index dc9295c11d..20a771148b 100644 --- a/sdk/src/types/block/mana/allotment.rs +++ b/sdk/src/types/block/mana/allotment.rs @@ -1,7 +1,12 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use packable::Packable; +use alloc::{boxed::Box, collections::BTreeSet, vec::Vec}; +use core::ops::RangeInclusive; + +use derive_more::Deref; +use iterator_sorted::is_unique_sorted; +use packable::{bounded::BoundedU16, prefix::BoxedSlicePrefix, Packable}; use crate::types::block::{ output::AccountId, @@ -62,6 +67,127 @@ fn verify_mana(mana: &u64, params: &ProtocolParameters) -> R Ok(()) } +pub(crate) type ManaAllotmentCount = + BoundedU16<{ *ManaAllotments::COUNT_RANGE.start() }, { *ManaAllotments::COUNT_RANGE.end() }>; + +/// A list of [`ManaAllotment`]s with unique [`AccountId`]s. +#[derive(Clone, Debug, Eq, PartialEq, Deref, Packable)] +#[packable(unpack_visitor = ProtocolParameters)] +#[packable(unpack_error = Error, with = |e| e.unwrap_item_err_or_else(|p| Error::InvalidManaAllotmentCount(p.into())))] +pub struct ManaAllotments( + #[packable(verify_with = verify_mana_allotments)] BoxedSlicePrefix, +); + +impl ManaAllotments { + /// The minimum number of mana allotments of a transaction. + pub const COUNT_MIN: u16 = 0; + /// The maximum number of mana allotments of a transaction. + pub const COUNT_MAX: u16 = 128; + /// The range of valid numbers of mana allotments of a transaction. + pub const COUNT_RANGE: RangeInclusive = Self::COUNT_MIN..=Self::COUNT_MAX; // [1..128] + + /// Creates a new [`ManaAllotments`] from a vec. + pub fn from_vec(allotments: Vec) -> Result { + verify_mana_allotments_unique_sorted(&allotments)?; + + Ok(Self( + allotments + .into_boxed_slice() + .try_into() + .map_err(Error::InvalidManaAllotmentCount)?, + )) + } + + /// Creates a new [`ManaAllotments`] from an ordered set. + pub fn from_set(allotments: BTreeSet) -> Result { + Ok(Self( + allotments + .into_iter() + .collect::>() + .try_into() + .map_err(Error::InvalidManaAllotmentCount)?, + )) + } + + /// Gets a reference to an [`ManaAllotment`], if one exists, using an [`AccountId`]. + #[inline(always)] + pub fn get(&self, account_id: &AccountId) -> Option<&ManaAllotment> { + self.0.iter().find(|a| a.account_id() == account_id) + } +} + +fn verify_mana_allotments( + allotments: &[ManaAllotment], + protocol_params: &ProtocolParameters, +) -> Result<(), Error> { + if VERIFY { + verify_mana_allotments_unique_sorted(allotments)?; + verify_mana_allotments_sum(allotments, protocol_params)?; + } + + Ok(()) +} + +fn verify_mana_allotments_unique_sorted<'a>( + allotments: impl IntoIterator, +) -> Result<(), Error> { + if !is_unique_sorted(allotments.into_iter()) { + return Err(Error::ManaAllotmentsNotUniqueSorted); + } + Ok(()) +} + +pub(crate) fn verify_mana_allotments_sum<'a>( + allotments: impl IntoIterator, + protocol_params: &ProtocolParameters, +) -> Result<(), Error> { + let mut mana_sum: u64 = 0; + let max_mana = protocol_params.mana_parameters().max_mana(); + + for ManaAllotment { mana, .. } in allotments { + mana_sum = mana_sum.checked_add(*mana).ok_or(Error::InvalidManaAllotmentSum { + sum: mana_sum as u128 + *mana as u128, + max: max_mana, + })?; + + if mana_sum > max_mana { + return Err(Error::InvalidManaAllotmentSum { + sum: mana_sum as u128, + max: max_mana, + }); + } + } + + Ok(()) +} + +impl TryFrom> for ManaAllotments { + type Error = Error; + + #[inline(always)] + fn try_from(allotments: Vec) -> Result { + Self::from_vec(allotments) + } +} + +impl TryFrom> for ManaAllotments { + type Error = Error; + + #[inline(always)] + fn try_from(allotments: BTreeSet) -> Result { + Self::from_set(allotments) + } +} + +impl IntoIterator for ManaAllotments { + type Item = ManaAllotment; + type IntoIter = alloc::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + Vec::from(Into::>::into(self.0)).into_iter() + } +} + #[cfg(feature = "serde")] pub(super) mod dto { use serde::{Deserialize, Serialize}; diff --git a/sdk/src/types/block/mana/mod.rs b/sdk/src/types/block/mana/mod.rs index 72328c74db..f9eb15e924 100644 --- a/sdk/src/types/block/mana/mod.rs +++ b/sdk/src/types/block/mana/mod.rs @@ -5,135 +5,11 @@ mod allotment; mod parameters; mod rewards; -use alloc::{boxed::Box, collections::BTreeSet, vec::Vec}; -use core::ops::RangeInclusive; - -use derive_more::Deref; -use iterator_sorted::is_unique_sorted; -use packable::{bounded::BoundedU16, prefix::BoxedSlicePrefix, Packable}; - #[cfg(feature = "serde")] pub use self::allotment::dto::ManaAllotmentDto; -pub use self::{allotment::ManaAllotment, parameters::ManaParameters, rewards::RewardsParameters}; -use super::{output::AccountId, protocol::ProtocolParameters, Error}; - -pub(crate) type ManaAllotmentCount = - BoundedU16<{ *ManaAllotments::COUNT_RANGE.start() }, { *ManaAllotments::COUNT_RANGE.end() }>; - -/// A list of [`ManaAllotment`]s with unique [`AccountId`]s. -#[derive(Clone, Debug, Eq, PartialEq, Deref, Packable)] -#[packable(unpack_visitor = ProtocolParameters)] -#[packable(unpack_error = Error, with = |e| e.unwrap_item_err_or_else(|p| Error::InvalidManaAllotmentCount(p.into())))] -pub struct ManaAllotments( - #[packable(verify_with = verify_mana_allotments)] BoxedSlicePrefix, -); - -impl ManaAllotments { - /// The minimum number of mana allotments of a transaction. - pub const COUNT_MIN: u16 = 0; - /// The maximum number of mana allotments of a transaction. - pub const COUNT_MAX: u16 = 128; - /// The range of valid numbers of mana allotments of a transaction. - pub const COUNT_RANGE: RangeInclusive = Self::COUNT_MIN..=Self::COUNT_MAX; // [1..128] - - /// Creates a new [`ManaAllotments`] from a vec. - pub fn from_vec(allotments: Vec) -> Result { - verify_mana_allotments_unique_sorted(&allotments)?; - - Ok(Self( - allotments - .into_boxed_slice() - .try_into() - .map_err(Error::InvalidManaAllotmentCount)?, - )) - } - - /// Creates a new [`ManaAllotments`] from an ordered set. - pub fn from_set(allotments: BTreeSet) -> Result { - Ok(Self( - allotments - .into_iter() - .collect::>() - .try_into() - .map_err(Error::InvalidManaAllotmentCount)?, - )) - } - - /// Gets a reference to an [`ManaAllotment`], if one exists, using an [`AccountId`]. - #[inline(always)] - pub fn get(&self, account_id: &AccountId) -> Option<&ManaAllotment> { - self.0.iter().find(|a| a.account_id() == account_id) - } -} - -fn verify_mana_allotments( - allotments: &[ManaAllotment], - protocol_params: &ProtocolParameters, -) -> Result<(), Error> { - if VERIFY { - verify_mana_allotments_unique_sorted(allotments)?; - verify_mana_allotments_sum(allotments, protocol_params)?; - } - - Ok(()) -} - -fn verify_mana_allotments_unique_sorted<'a>( - allotments: impl IntoIterator, -) -> Result<(), Error> { - if !is_unique_sorted(allotments.into_iter()) { - return Err(Error::ManaAllotmentsNotUniqueSorted); - } - Ok(()) -} - -pub(crate) fn verify_mana_allotments_sum<'a>( - allotments: impl IntoIterator, - protocol_params: &ProtocolParameters, -) -> Result<(), Error> { - let mut mana_sum: u64 = 0; - let max_mana = protocol_params.mana_parameters().max_mana(); - - for ManaAllotment { mana, .. } in allotments { - mana_sum = mana_sum.checked_add(*mana).ok_or(Error::InvalidManaAllotmentSum { - sum: mana_sum as u128 + *mana as u128, - max: max_mana, - })?; - - if mana_sum > max_mana { - return Err(Error::InvalidManaAllotmentSum { - sum: mana_sum as u128, - max: max_mana, - }); - } - } - - Ok(()) -} - -impl TryFrom> for ManaAllotments { - type Error = Error; - - #[inline(always)] - fn try_from(allotments: Vec) -> Result { - Self::from_vec(allotments) - } -} - -impl TryFrom> for ManaAllotments { - type Error = Error; - - #[inline(always)] - fn try_from(allotments: BTreeSet) -> Result { - Self::from_set(allotments) - } -} - -impl IntoIterator for ManaAllotments { - type Item = ManaAllotment; - type IntoIter = alloc::vec::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - Vec::from(Into::>::into(self.0)).into_iter() - } -} +pub(crate) use self::allotment::{verify_mana_allotments_sum, ManaAllotmentCount}; +pub use self::{ + allotment::{ManaAllotment, ManaAllotments}, + parameters::ManaParameters, + rewards::RewardsParameters, +}; diff --git a/sdk/src/types/block/mana/parameters.rs b/sdk/src/types/block/mana/parameters.rs index e6d68aa698..925b57a574 100644 --- a/sdk/src/types/block/mana/parameters.rs +++ b/sdk/src/types/block/mana/parameters.rs @@ -84,6 +84,7 @@ impl ManaParameters { if self.generation_rate() == 0 || slot_delta == 0 { return 0; } + fixed_point_multiply( amount, slot_delta * self.generation_rate() as u32, @@ -121,12 +122,14 @@ impl ProtocolParameters { self.epoch_index_of(slot_index_created), self.epoch_index_of(slot_index_target), ); + if epoch_index_created > epoch_index_target { return Err(Error::InvalidEpochDelta { created: epoch_index_created, target: epoch_index_target, }); } + Ok(self .mana_parameters() .decay(mana, epoch_index_target.0 - epoch_index_created.0)) @@ -140,12 +143,14 @@ impl ProtocolParameters { claimed_epoch: impl Into, ) -> Result { let (reward_epoch, claimed_epoch) = (reward_epoch.into(), claimed_epoch.into()); + if reward_epoch > claimed_epoch { return Err(Error::InvalidEpochDelta { created: reward_epoch, target: claimed_epoch, }); } + Ok(self.mana_parameters().decay(reward, claimed_epoch.0 - reward_epoch.0)) } @@ -162,6 +167,7 @@ impl ProtocolParameters { self.epoch_index_of(slot_index_created), self.epoch_index_of(slot_index_target), ); + if epoch_index_created > epoch_index_target { return Err(Error::InvalidEpochDelta { created: epoch_index_created, @@ -171,6 +177,7 @@ impl ProtocolParameters { if slot_index_created >= slot_index_target { return Ok(0); } + let mana_parameters = self.mana_parameters(); Ok(if epoch_index_created == epoch_index_target { From 5cc119f75ccc1685b1ccf818f3fc22d477d419f4 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 18 Dec 2023 18:55:00 +0100 Subject: [PATCH 03/11] delta->diff --- sdk/src/types/block/error.rs | 6 +++--- sdk/src/types/block/mana/parameters.rs | 29 +++++++++++++------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/sdk/src/types/block/error.rs b/sdk/src/types/block/error.rs index ee8d5b44c8..b44bd1b619 100644 --- a/sdk/src/types/block/error.rs +++ b/sdk/src/types/block/error.rs @@ -196,7 +196,7 @@ pub enum Error { DuplicateOutputChain(ChainId), InvalidField(&'static str), NullDelegationValidatorId, - InvalidEpochDelta { + InvalidEpochDiff { created: EpochIndex, target: EpochIndex, }, @@ -428,8 +428,8 @@ impl fmt::Display for Error { Self::DuplicateOutputChain(chain_id) => write!(f, "duplicate output chain {chain_id}"), Self::InvalidField(field) => write!(f, "invalid field: {field}"), Self::NullDelegationValidatorId => write!(f, "null delegation validator ID"), - Self::InvalidEpochDelta { created, target } => { - write!(f, "invalid epoch delta: created {created}, target {target}") + Self::InvalidEpochDiff { created, target } => { + write!(f, "invalid epoch diff: created {created}, target {target}") } Self::TrailingCapabilityBytes => write!(f, "capability bytes have trailing zeroes"), } diff --git a/sdk/src/types/block/mana/parameters.rs b/sdk/src/types/block/mana/parameters.rs index 925b57a574..127e0b2320 100644 --- a/sdk/src/types/block/mana/parameters.rs +++ b/sdk/src/types/block/mana/parameters.rs @@ -58,13 +58,13 @@ impl ManaParameters { (1 << self.bits_count) - 1 } - fn decay(&self, mut mana: u64, epoch_delta: u32) -> u64 { - if mana == 0 || epoch_delta == 0 || self.decay_factors().is_empty() { + fn decay(&self, mut mana: u64, epoch_diff: u32) -> u64 { + if mana == 0 || epoch_diff == 0 || self.decay_factors().is_empty() { return mana; } // we keep applying the lookup table factors as long as n epochs are left - let mut remaining_epochs = epoch_delta; + let mut remaining_epochs = epoch_diff; while remaining_epochs > 0 { let epochs_to_decay = remaining_epochs.min(self.decay_factors().len() as u32); @@ -80,14 +80,14 @@ impl ManaParameters { mana } - fn generate_mana(&self, amount: u64, slot_delta: u32) -> u64 { - if self.generation_rate() == 0 || slot_delta == 0 { + fn generate_mana(&self, amount: u64, slot_diff: u32) -> u64 { + if self.generation_rate() == 0 || slot_diff == 0 { return 0; } fixed_point_multiply( amount, - slot_delta * self.generation_rate() as u32, + slot_diff * self.generation_rate() as u32, self.generation_rate_exponent(), ) } @@ -117,14 +117,13 @@ impl ProtocolParameters { slot_index_created: impl Into, slot_index_target: impl Into, ) -> Result { - let (slot_index_created, slot_index_target) = (slot_index_created.into(), slot_index_target.into()); let (epoch_index_created, epoch_index_target) = ( self.epoch_index_of(slot_index_created), self.epoch_index_of(slot_index_target), ); if epoch_index_created > epoch_index_target { - return Err(Error::InvalidEpochDelta { + return Err(Error::InvalidEpochDiff { created: epoch_index_created, target: epoch_index_target, }); @@ -145,7 +144,7 @@ impl ProtocolParameters { let (reward_epoch, claimed_epoch) = (reward_epoch.into(), claimed_epoch.into()); if reward_epoch > claimed_epoch { - return Err(Error::InvalidEpochDelta { + return Err(Error::InvalidEpochDiff { created: reward_epoch, target: claimed_epoch, }); @@ -169,7 +168,7 @@ impl ProtocolParameters { ); if epoch_index_created > epoch_index_target { - return Err(Error::InvalidEpochDelta { + return Err(Error::InvalidEpochDiff { created: epoch_index_created, target: epoch_index_target, }); @@ -196,14 +195,14 @@ impl ProtocolParameters { mana_parameters.decay_factor_epochs_sum_exponent() + mana_parameters.generation_rate_exponent() - self.slots_per_epoch_exponent(), ); - let epoch_delta = epoch_index_target.0 - epoch_index_created.0; + let epoch_diff = epoch_index_target.0 - epoch_index_created.0; let slots_before_next_epoch = self.first_slot_of(epoch_index_created + 1) - slot_index_created; let slots_since_epoch_start = slot_index_target - self.first_slot_of(epoch_index_target); let potential_mana_n = mana_parameters.decay( mana_parameters.generate_mana(amount, slots_before_next_epoch.0), - epoch_delta, + epoch_diff, ); - let potential_mana_n_1 = mana_parameters.decay(c, epoch_delta - 1); + let potential_mana_n_1 = mana_parameters.decay(c, epoch_diff - 1); let potential_mana_0 = c + mana_parameters.generate_mana(amount, slots_since_epoch_start.0) - (c >> mana_parameters.decay_factors_exponent()); potential_mana_0 - potential_mana_n_1 + potential_mana_n @@ -297,7 +296,7 @@ mod test { fn mana_decay_negative_delta() { assert_eq!( params().mana_with_decay(100, params().first_slot_of(2), params().first_slot_of(1)), - Err(Error::InvalidEpochDelta { + Err(Error::InvalidEpochDiff { created: 2.into(), target: 1.into() }) @@ -356,7 +355,7 @@ mod test { fn potential_mana_negative_delta() { assert_eq!( params().potential_mana(100, params().first_slot_of(2), params().first_slot_of(1)), - Err(Error::InvalidEpochDelta { + Err(Error::InvalidEpochDiff { created: 2.into(), target: 1.into() }) From 9540ac5424c45d95c0fc31796d197a8912e6b198 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Wed, 10 Jan 2024 16:36:29 +0100 Subject: [PATCH 04/11] Nit --- sdk/src/types/block/semantic/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sdk/src/types/block/semantic/mod.rs b/sdk/src/types/block/semantic/mod.rs index 1b270eb125..d7d98d4767 100644 --- a/sdk/src/types/block/semantic/mod.rs +++ b/sdk/src/types/block/semantic/mod.rs @@ -163,9 +163,8 @@ impl<'a> SemanticValidationContext<'a> { .ok_or(Error::ConsumedAmountOverflow)?; let potential_mana = { - let min_amount = consumed_output.minimum_amount(self.protocol_parameters.storage_score_parameters()); - - let generation_amount = consumed_output.amount().checked_sub(min_amount).unwrap_or_default(); + let min_deposit = consumed_output.minimum_amount(self.protocol_parameters.storage_score_parameters()); + let generation_amount = consumed_output.amount().saturating_sub(min_deposit); self.protocol_parameters.potential_mana( generation_amount, From 4ff8ed7b9d231e979bb6961ded9874edb55dd335 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Wed, 10 Jan 2024 18:57:26 +0100 Subject: [PATCH 05/11] Allow passing an index for test inputs IDs --- sdk/src/types/block/rand/transaction.rs | 11 +- sdk/src/types/block/semantic/mod.rs | 13 +- .../client/input_selection/account_outputs.rs | 747 +++++---- .../client/input_selection/basic_outputs.rs | 1455 +++++++++-------- .../client/input_selection/expiration.rs | 610 +++---- .../client/input_selection/foundry_outputs.rs | 592 ++++--- .../client/input_selection/nft_outputs.rs | 665 ++++---- sdk/tests/client/input_selection/outputs.rs | 174 +- .../input_selection/storage_deposit_return.rs | 425 ++--- sdk/tests/client/input_selection/timelock.rs | 157 +- sdk/tests/client/mod.rs | 17 +- sdk/tests/client/signing/account.rs | 63 +- sdk/tests/client/signing/basic.rs | 163 +- sdk/tests/client/signing/mod.rs | 245 +-- sdk/tests/client/signing/nft.rs | 41 +- 15 files changed, 2938 insertions(+), 2440 deletions(-) diff --git a/sdk/src/types/block/rand/transaction.rs b/sdk/src/types/block/rand/transaction.rs index 20036d143b..d147183e61 100644 --- a/sdk/src/types/block/rand/transaction.rs +++ b/sdk/src/types/block/rand/transaction.rs @@ -1,9 +1,18 @@ // Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use crate::types::block::{payload::signed_transaction::TransactionId, rand::bytes::rand_bytes_array}; +use crate::types::block::{ + payload::signed_transaction::{TransactionHash, TransactionId}, + rand::bytes::rand_bytes_array, + slot::SlotIndex, +}; /// Generates a random transaction id. pub fn rand_transaction_id() -> TransactionId { TransactionId::new(rand_bytes_array()) } + +/// Generates a random transaction id with a given slot index. +pub fn rand_transaction_id_with_slot_index(slot_index: impl Into) -> TransactionId { + TransactionHash::new(rand_bytes_array()).into_transaction_id(slot_index.into()) +} diff --git a/sdk/src/types/block/semantic/mod.rs b/sdk/src/types/block/semantic/mod.rs index d7d98d4767..b45d7713c9 100644 --- a/sdk/src/types/block/semantic/mod.rs +++ b/sdk/src/types/block/semantic/mod.rs @@ -291,14 +291,13 @@ impl<'a> SemanticValidationContext<'a> { return Ok(Some(TransactionFailureReason::SumInputsOutputsAmountMismatch)); } - // TODO re-enable with https://github.com/iotaledger/iota-sdk/issues/1692 if self.input_mana != self.output_mana { - if self.input_mana > self.output_mana - && !self.transaction.has_capability(TransactionCapabilityFlag::BurnMana) - { - return Ok(Some( - TransactionFailureReason::TransactionCapabilityManaBurningNotAllowed, - )); + if self.input_mana > self.output_mana { + if !self.transaction.has_capability(TransactionCapabilityFlag::BurnMana) { + return Ok(Some( + TransactionFailureReason::TransactionCapabilityManaBurningNotAllowed, + )); + } } else { return Ok(Some(TransactionFailureReason::InvalidManaAmount)); } diff --git a/sdk/tests/client/input_selection/account_outputs.rs b/sdk/tests/client/input_selection/account_outputs.rs index a350d1a584..ade83ef47a 100644 --- a/sdk/tests/client/input_selection/account_outputs.rs +++ b/sdk/tests/client/input_selection/account_outputs.rs @@ -25,14 +25,17 @@ fn input_account_eq_output_account() { let protocol_parameters = protocol_parameters(); let account_id_2 = AccountId::from_str(ACCOUNT_ID_2).unwrap(); - let inputs = build_inputs([Account( - 1_000_000, - account_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, + let inputs = build_inputs( + [Account( + 1_000_000, + account_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Account( 1_000_000, account_id_2, @@ -60,14 +63,17 @@ fn transition_account_id_zero() { let protocol_parameters = protocol_parameters(); let account_id_0 = AccountId::from_str(ACCOUNT_ID_0).unwrap(); - let inputs = build_inputs([Account( - 1_000_000, - account_id_0, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, + let inputs = build_inputs( + [Account( + 1_000_000, + account_id_0, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + )], None, - )]); + ); let account_id = AccountId::from(inputs[0].output_id()); let outputs = build_outputs([Account( 1_000_000, @@ -230,16 +236,19 @@ fn create_account() { let protocol_parameters = protocol_parameters(); let account_id_0 = AccountId::from_str(ACCOUNT_ID_0).unwrap(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Account( 1_000_000, account_id_0, @@ -276,14 +285,17 @@ fn burn_account() { let protocol_parameters = protocol_parameters(); let account_id_2 = AccountId::from_str(ACCOUNT_ID_2).unwrap(); - let inputs = build_inputs([Account( - 2_000_000, - account_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, + let inputs = build_inputs( + [Account( + 2_000_000, + account_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -359,16 +371,19 @@ fn missing_input_for_account_output() { let protocol_parameters = protocol_parameters(); let account_id_2 = AccountId::from_str(ACCOUNT_ID_2).unwrap(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Account( 1_000_000, account_id_2, @@ -398,26 +413,29 @@ fn missing_input_for_account_output_2() { let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); let account_id_2 = AccountId::from_str(ACCOUNT_ID_2).unwrap(); - let inputs = build_inputs([ - Account( - 2_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Account( + 2_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Account( 1_000_000, account_id_2, @@ -446,16 +464,19 @@ fn missing_input_for_account_output_but_created() { let protocol_parameters = protocol_parameters(); let account_id_0 = AccountId::from_str(ACCOUNT_ID_0).unwrap(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Account( 1_000_000, account_id_0, @@ -481,26 +502,29 @@ fn account_in_output_and_sender() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([ - Account( - 1_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Account( + 1_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let account_output = AccountOutputBuilder::from(inputs[0].output.as_account()) .finish_output() .unwrap(); @@ -534,14 +558,17 @@ fn missing_ed25519_sender() { let protocol_parameters = protocol_parameters(); let account_id_2 = AccountId::from_str(ACCOUNT_ID_2).unwrap(); - let inputs = build_inputs([Account( - 1_000_000, - account_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, + let inputs = build_inputs( + [Account( + 1_000_000, + account_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Account( 1_000_000, account_id_2, @@ -570,16 +597,19 @@ fn missing_ed25519_issuer_created() { let protocol_parameters = protocol_parameters(); let account_id_0 = AccountId::from_str(ACCOUNT_ID_0).unwrap(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Account( 1_000_000, account_id_0, @@ -608,14 +638,17 @@ fn missing_ed25519_issuer_transition() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([Account( - 1_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - Some(Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap()), + let inputs = build_inputs( + [Account( + 1_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + Some(Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap()), + None, + )], None, - )]); + ); let outputs = build_outputs([Account( 1_000_000, account_id_1, @@ -641,14 +674,17 @@ fn missing_account_sender() { let protocol_parameters = protocol_parameters(); let account_id_2 = AccountId::from_str(ACCOUNT_ID_2).unwrap(); - let inputs = build_inputs([Account( - 1_000_000, - account_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, + let inputs = build_inputs( + [Account( + 1_000_000, + account_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Account( 1_000_000, account_id_2, @@ -677,16 +713,19 @@ fn missing_account_issuer_created() { let protocol_parameters = protocol_parameters(); let account_id_0 = AccountId::from_str(ACCOUNT_ID_0).unwrap(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Account( 1_000_000, account_id_0, @@ -715,14 +754,17 @@ fn missing_account_issuer_transition() { let protocol_parameters = protocol_parameters(); let account_id_2 = AccountId::from_str(ACCOUNT_ID_2).unwrap(); - let inputs = build_inputs([Account( - 1_000_000, - account_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - Some(Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap()), + let inputs = build_inputs( + [Account( + 1_000_000, + account_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + Some(Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap()), + None, + )], None, - )]); + ); let outputs = build_outputs([Account( 1_000_000, account_id_2, @@ -748,14 +790,17 @@ fn missing_nft_sender() { let protocol_parameters = protocol_parameters(); let account_id_2 = AccountId::from_str(ACCOUNT_ID_2).unwrap(); - let inputs = build_inputs([Account( - 1_000_000, - account_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, + let inputs = build_inputs( + [Account( + 1_000_000, + account_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Account( 1_000_000, account_id_2, @@ -784,16 +829,19 @@ fn missing_nft_issuer_created() { let protocol_parameters = protocol_parameters(); let account_id_0 = AccountId::from_str(ACCOUNT_ID_0).unwrap(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Account( 1_000_000, account_id_0, @@ -822,14 +870,17 @@ fn missing_nft_issuer_transition() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([Account( - 1_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - Some(Address::try_from_bech32(BECH32_ADDRESS_NFT_1).unwrap()), + let inputs = build_inputs( + [Account( + 1_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + Some(Address::try_from_bech32(BECH32_ADDRESS_NFT_1).unwrap()), + None, + )], None, - )]); + ); let outputs = build_outputs([Account( 1_000_000, account_id_1, @@ -855,26 +906,29 @@ fn increase_account_amount() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([ - Account( - 2_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Account( + 2_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Account( 3_000_000, account_id_1, @@ -902,26 +956,29 @@ fn decrease_account_amount() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([ - Account( - 2_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Account( + 2_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Account( 1_000_000, account_id_1, @@ -961,26 +1018,29 @@ fn prefer_basic_to_account() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([ - Account( - 1_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Account( + 1_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1011,26 +1071,29 @@ fn take_amount_from_account_to_fund_basic() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([ - Account( - 2_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Account( + 2_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 1_200_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1075,26 +1138,29 @@ fn account_burn_should_validate_account_sender() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Account( - 1_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Account( + 1_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1137,26 +1203,29 @@ fn account_burn_should_validate_account_address() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Account( - 1_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Account( + 1_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1199,14 +1268,17 @@ fn transitioned_zero_account_id_no_longer_is_zero() { let protocol_parameters = protocol_parameters(); let account_id_0 = AccountId::from_str(ACCOUNT_ID_0).unwrap(); - let inputs = build_inputs([Account( - 2_000_000, - account_id_0, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, + let inputs = build_inputs( + [Account( + 2_000_000, + account_id_0, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1252,24 +1324,27 @@ fn two_accounts_required() { let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); let account_id_2 = AccountId::from_str(ACCOUNT_ID_2).unwrap(); - let inputs = build_inputs([ - Account( - 2_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - Account( - 2_000_000, - account_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Account( + 2_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + Account( + 2_000_000, + account_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 3_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1320,14 +1395,17 @@ fn state_controller_sender_required() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([Account( - 2_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, + let inputs = build_inputs( + [Account( + 2_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1358,14 +1436,17 @@ fn state_controller_sender_required_already_selected() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([Account( - 2_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, + let inputs = build_inputs( + [Account( + 2_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([ Account( 1_000_000, @@ -1406,14 +1487,17 @@ fn state_transition_and_required() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([Account( - 2_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, + let inputs = build_inputs( + [Account( + 2_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Account( 2_000_000, account_id_1, @@ -1442,14 +1526,17 @@ fn remainder_address_in_state_controller() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([Account( - 2_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, + let inputs = build_inputs( + [Account( + 2_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Account( 1_000_000, account_id_1, diff --git a/sdk/tests/client/input_selection/basic_outputs.rs b/sdk/tests/client/input_selection/basic_outputs.rs index 7b190eeb3c..f20d862c8b 100644 --- a/sdk/tests/client/input_selection/basic_outputs.rs +++ b/sdk/tests/client/input_selection/basic_outputs.rs @@ -6,10 +6,7 @@ use std::str::FromStr; use iota_sdk::{ client::api::input_selection::{Error, InputSelection, Requirement}, types::block::{ - address::{ - Address, AddressCapabilities, ImplicitAccountCreationAddress, MultiAddress, RestrictedAddress, - WeightedAddress, - }, + address::{Address, AddressCapabilities, MultiAddress, RestrictedAddress, WeightedAddress}, output::{AccountId, NftId}, protocol::protocol_parameters, }, @@ -27,16 +24,19 @@ use crate::client::{ fn input_amount_equal_output_amount() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -65,16 +65,19 @@ fn input_amount_equal_output_amount() { fn input_amount_lower_than_output_amount() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -107,28 +110,31 @@ fn input_amount_lower_than_output_amount() { fn input_amount_lower_than_output_amount_2() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 3_500_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -161,16 +167,19 @@ fn input_amount_lower_than_output_amount_2() { fn input_amount_greater_than_output_amount() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 500_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -212,16 +221,19 @@ fn input_amount_greater_than_output_amount_with_remainder_address() { let protocol_parameters = protocol_parameters(); let remainder_address = Address::try_from_bech32(BECH32_ADDRESS_REMAINDER).unwrap(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 500_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -263,28 +275,31 @@ fn input_amount_greater_than_output_amount_with_remainder_address() { fn two_same_inputs_one_needed() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 500_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -326,28 +341,31 @@ fn two_same_inputs_one_needed() { fn two_inputs_one_needed() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -376,28 +394,31 @@ fn two_inputs_one_needed() { fn two_inputs_one_needed_reversed() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -426,28 +447,31 @@ fn two_inputs_one_needed_reversed() { fn two_inputs_both_needed() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 3_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -476,28 +500,31 @@ fn two_inputs_both_needed() { fn two_inputs_remainder() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 2_500_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -581,58 +608,61 @@ fn ed25519_sender() { let protocol_parameters = protocol_parameters(); let sender = Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -672,16 +702,19 @@ fn ed25519_sender() { fn missing_ed25519_sender() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 5_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 5_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -712,57 +745,59 @@ fn account_sender() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Account( - 1_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); - + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Account( + 1_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -801,26 +836,29 @@ fn account_sender_zero_id() { let protocol_parameters = protocol_parameters(); let account_id_0 = AccountId::from_str(ACCOUNT_ID_0).unwrap(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Account( - 1_000_000, - account_id_0, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Account( + 1_000_000, + account_id_0, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + ], + None, + ); let account_id = AccountId::from(inputs[1].output_id()); let outputs = build_outputs([Basic( 2_000_000, @@ -856,16 +894,19 @@ fn account_sender_zero_id() { fn missing_account_sender() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 5_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 5_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -896,58 +937,61 @@ fn nft_sender() { let protocol_parameters = protocol_parameters(); let nft_id_1 = NftId::from_str(NFT_ID_1).unwrap(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Nft( - 1_000_000, - nft_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Nft( + 1_000_000, + nft_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -987,28 +1031,31 @@ fn nft_sender_zero_id() { let protocol_parameters = protocol_parameters(); let nft_id_0 = NftId::from_str(NFT_ID_0).unwrap(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Nft( - 1_000_000, - nft_id_0, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Nft( + 1_000_000, + nft_id_0, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + ), + ], + None, + ); let nft_id = NftId::from(inputs[1].output_id()); let outputs = build_outputs([Basic( 2_000_000, @@ -1044,16 +1091,19 @@ fn nft_sender_zero_id() { fn missing_nft_sender() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 5_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 5_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1083,16 +1133,19 @@ fn missing_nft_sender() { fn simple_remainder() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 500_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1212,16 +1265,19 @@ fn simple_remainder() { fn one_provided_one_needed() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1250,16 +1306,19 @@ fn one_provided_one_needed() { fn insufficient_amount() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 1_250_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1292,28 +1351,31 @@ fn insufficient_amount() { fn two_inputs_remainder_2() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 500_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1354,28 +1416,31 @@ fn two_inputs_remainder_2() { fn two_inputs_remainder_3() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 1_750_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1455,16 +1520,19 @@ fn two_inputs_remainder_3() { fn sender_already_selected() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1497,16 +1565,19 @@ fn sender_already_selected() { fn single_mandatory_input() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1554,8 +1625,8 @@ fn too_many_inputs() { ) }) .take(129), + None, ); - let outputs = build_outputs([Basic( 129_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1600,18 +1671,22 @@ fn more_than_max_inputs_only_one_needed() { ) }) .take(1000), + None, ); // Add the needed input - let needed_input = build_inputs([Basic( - 129_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let needed_input = build_inputs( + [Basic( + 129_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); inputs.push(needed_input[0].clone()); let outputs = build_outputs([Basic( @@ -1642,17 +1717,19 @@ fn more_than_max_inputs_only_one_needed() { fn too_many_outputs() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 2_000_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); - + ); let outputs = build_outputs( std::iter::repeat_with(|| { Basic( @@ -1687,16 +1764,19 @@ fn too_many_outputs() { fn too_many_outputs_with_remainder() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 2_000_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs( std::iter::repeat_with(|| { @@ -1735,49 +1815,52 @@ fn restricted_ed25519() { let address = Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(); let restricted = Address::from(RestrictedAddress::new(address.clone()).unwrap()); - let inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic(1_000_000, restricted, None, None, None, None, None, None), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic(1_000_000, restricted, None, None, None, None, None, None), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1810,19 +1893,22 @@ fn restricted_nft() { let nft_address = Address::from(nft_id_1); let restricted = Address::from(RestrictedAddress::new(nft_address.clone()).unwrap()); - let inputs = build_inputs([ - Basic(2_000_000, restricted, None, None, None, None, None, None), - Nft( - 2_000_000, - nft_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic(2_000_000, restricted, None, None, None, None, None, None), + Nft( + 2_000_000, + nft_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 3_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1855,18 +1941,20 @@ fn restricted_account() { let account_address = Address::from(account_id_1); let restricted = Address::from(RestrictedAddress::new(account_address.clone()).unwrap()); - let inputs = build_inputs([ - Basic(3_000_000, restricted, None, None, None, None, None, None), - Account( - 2_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - ]); - + let inputs = build_inputs( + [ + Basic(3_000_000, restricted, None, None, None, None, None, None), + Account( + 2_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 3_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1898,58 +1986,61 @@ fn restricted_ed25519_sender() { let sender = Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(); let restricted_sender = Address::from(RestrictedAddress::new(sender.clone()).unwrap()); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -2003,38 +2094,41 @@ fn multi_address_sender_already_fulfilled() { .unwrap(), ); - let inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 3_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -2074,19 +2168,22 @@ fn ed25519_backed_available_address() { .with_allowed_capabilities(AddressCapabilities::all()), ); - let inputs = build_inputs([ - Basic( - 1_000_000, - restricted_address.clone(), - None, - None, - None, - None, - None, - None, - ), - Basic(1_000_000, ed25519.clone(), None, None, None, None, None, None), - ]); + let inputs = build_inputs( + [ + Basic( + 1_000_000, + restricted_address.clone(), + None, + None, + None, + None, + None, + None, + ), + Basic(1_000_000, ed25519.clone(), None, None, None, None, None, None), + ], + None, + ); let outputs = build_outputs([ Basic( 1_000_000, diff --git a/sdk/tests/client/input_selection/expiration.rs b/sdk/tests/client/input_selection/expiration.rs index 08852b876f..8dc60c5696 100644 --- a/sdk/tests/client/input_selection/expiration.rs +++ b/sdk/tests/client/input_selection/expiration.rs @@ -24,16 +24,19 @@ use crate::client::{ fn one_output_expiration_not_expired() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 200)), + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 200)), + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -61,16 +64,19 @@ fn one_output_expiration_not_expired() { fn expiration_equal_timestamp() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 200)), + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 200)), + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -100,16 +106,19 @@ fn expiration_equal_timestamp() { fn one_output_expiration_expired() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -139,28 +148,31 @@ fn one_output_expiration_expired() { fn two_outputs_one_expiration_expired() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 200)), - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 200)), + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), @@ -191,28 +203,31 @@ fn two_outputs_one_expiration_expired() { fn two_outputs_one_unexpired_one_missing() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 200)), - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 200)), + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), @@ -243,38 +258,41 @@ fn two_outputs_one_unexpired_one_missing() { fn two_outputs_two_expired() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 100)), - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), 100)), - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 100)), + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), 100)), + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), @@ -305,28 +323,31 @@ fn two_outputs_two_expired() { fn two_outputs_two_expired_2() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 100)), - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), 100)), - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 100)), + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), 100)), + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 4_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), @@ -359,16 +380,19 @@ fn two_outputs_two_expired_2() { fn expiration_expired_with_sdr() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), @@ -398,16 +422,19 @@ fn expiration_expired_with_sdr() { fn expiration_expired_with_sdr_2() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -437,16 +464,19 @@ fn expiration_expired_with_sdr_2() { fn expiration_expired_with_sdr_and_timelock() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 1_000_000)), - Some(50), - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 1_000_000)), + Some(50), + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), @@ -476,16 +506,19 @@ fn expiration_expired_with_sdr_and_timelock() { fn expiration_expired_with_sdr_and_timelock_2() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), - Some(50), - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), + Some(50), + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), @@ -515,58 +548,61 @@ fn expiration_expired_with_sdr_and_timelock_2() { fn sender_in_expiration() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 50)), - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 50)), + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -600,16 +636,19 @@ fn sender_in_expiration() { fn sender_in_expiration_already_selected() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 50)), + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 50)), + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -643,16 +682,19 @@ fn sender_in_expiration_already_selected() { fn remainder_in_expiration() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap(), - None, - None, - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 50)), + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap(), + None, + None, + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 50)), + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -696,16 +738,19 @@ fn remainder_in_expiration() { fn expiration_expired_non_ed25519_in_address_unlock_condition() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap(), - None, - None, - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap(), + None, + None, + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -736,26 +781,29 @@ fn expiration_expired_only_account_addresses() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap(), - None, - None, - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap(), 50)), - None, - ), - Account( - 1_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap(), + None, + None, + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap(), 50)), + None, + ), + Account( + 1_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 2_000_000, @@ -787,16 +835,19 @@ fn one_nft_output_expiration_unexpired() { let protocol_parameters = protocol_parameters(); let nft_id_1 = NftId::from_str(NFT_ID_1).unwrap(); - let inputs = build_inputs([Nft( - 2_000_000, - nft_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 150)), + let inputs = build_inputs( + [Nft( + 2_000_000, + nft_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 150)), + None, + )], None, - )]); + ); let outputs = build_outputs([Nft( 2_000_000, nft_id_1, @@ -827,16 +878,19 @@ fn one_nft_output_expiration_expired() { let protocol_parameters = protocol_parameters(); let nft_id_1 = NftId::from_str(NFT_ID_1).unwrap(); - let inputs = build_inputs([Nft( - 2_000_000, - nft_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), + let inputs = build_inputs( + [Nft( + 2_000_000, + nft_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), + None, + )], None, - )]); + ); let outputs = build_outputs([Nft( 2_000_000, nft_id_1, diff --git a/sdk/tests/client/input_selection/foundry_outputs.rs b/sdk/tests/client/input_selection/foundry_outputs.rs index 52c510b70c..bf8fe83707 100644 --- a/sdk/tests/client/input_selection/foundry_outputs.rs +++ b/sdk/tests/client/input_selection/foundry_outputs.rs @@ -31,16 +31,19 @@ fn missing_input_account_for_foundry() { let protocol_parameters = protocol_parameters(); let account_id_2 = AccountId::from_str(ACCOUNT_ID_2).unwrap(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Foundry( 1_000_000, account_id_2, @@ -106,26 +109,29 @@ fn minted_native_tokens_in_new_remainder() { let protocol_parameters = protocol_parameters(); let account_id_2 = AccountId::from_str(ACCOUNT_ID_2).unwrap(); - let inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Account( - 1_000_000, - account_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Account( + 1_000_000, + account_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Foundry( 1_000_000, account_id_2, @@ -162,26 +168,29 @@ fn minted_native_tokens_in_provided_output() { let foundry_id = FoundryId::build(&AccountAddress::from(account_id_2), 1, SimpleTokenScheme::KIND); let token_id = TokenId::from(foundry_id); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Account( - 1_000_000, - account_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Account( + 1_000_000, + account_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([ Foundry( 1_000_000, @@ -223,28 +232,31 @@ fn melt_native_tokens() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let mut inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Foundry( - 1_000_000, - account_id_1, - 1, - SimpleTokenScheme::new(10, 0, 10).unwrap(), - Some(( - "0x0811111111111111111111111111111111111111111111111111111111111111110100000000", - 10, - )), - ), - ]); + let mut inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Foundry( + 1_000_000, + account_id_1, + 1, + SimpleTokenScheme::new(10, 0, 10).unwrap(), + Some(( + "0x0811111111111111111111111111111111111111111111111111111111111111110100000000", + 10, + )), + ), + ], + None, + ); let account_output = AccountOutputBuilder::new_with_amount(1_000_000, account_id_1) .add_unlock_condition(AddressUnlockCondition::new( Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -292,23 +304,26 @@ fn destroy_foundry_with_account_state_transition() { let protocol_parameters = protocol_parameters(); let account_id_2 = AccountId::from_str(ACCOUNT_ID_2).unwrap(); - let inputs = build_inputs([ - Account( - 50_300, - account_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - Foundry( - 52_800, - account_id_2, - 1, - SimpleTokenScheme::new(10, 10, 10).unwrap(), - None, - ), - ]); + let inputs = build_inputs( + [ + Account( + 50_300, + account_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + Foundry( + 52_800, + account_id_2, + 1, + SimpleTokenScheme::new(10, 10, 10).unwrap(), + None, + ), + ], + None, + ); let account_output = AccountOutputBuilder::from(inputs[0].output.as_account()) .with_amount(103_100) .finish_output() @@ -336,23 +351,26 @@ fn destroy_foundry_with_account_burn() { let protocol_parameters = protocol_parameters(); let account_id_2 = AccountId::from_str(ACCOUNT_ID_2).unwrap(); - let inputs = build_inputs([ - Account( - 1_000_000, - account_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - Foundry( - 1_000_000, - account_id_2, - 1, - SimpleTokenScheme::new(10, 10, 10).unwrap(), - None, - ), - ]); + let inputs = build_inputs( + [ + Account( + 1_000_000, + account_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + Foundry( + 1_000_000, + account_id_2, + 1, + SimpleTokenScheme::new(10, 10, 10).unwrap(), + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -398,33 +416,36 @@ fn prefer_basic_to_foundry() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([ - Account( - 1_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - Foundry( - 1_000_000, - account_id_1, - 1, - SimpleTokenScheme::new(10, 10, 10).unwrap(), - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Account( + 1_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + Foundry( + 1_000_000, + account_id_1, + 1, + SimpleTokenScheme::new(10, 10, 10).unwrap(), + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -455,25 +476,28 @@ fn simple_foundry_transition_basic_not_needed() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let mut inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Foundry( - 1_000_000, - account_id_1, - 1, - SimpleTokenScheme::new(10, 10, 10).unwrap(), - None, - ), - ]); + let mut inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Foundry( + 1_000_000, + account_id_1, + 1, + SimpleTokenScheme::new(10, 10, 10).unwrap(), + None, + ), + ], + None, + ); let account_output = AccountOutputBuilder::new_with_amount(2_000_000, account_id_1) .add_unlock_condition(AddressUnlockCondition::new( Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -530,25 +554,28 @@ fn simple_foundry_transition_basic_not_needed_with_remainder() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let mut inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Foundry( - 2_000_000, - account_id_1, - 1, - SimpleTokenScheme::new(10, 10, 10).unwrap(), - None, - ), - ]); + let mut inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Foundry( + 2_000_000, + account_id_1, + 1, + SimpleTokenScheme::new(10, 10, 10).unwrap(), + None, + ), + ], + None, + ); let account_output = AccountOutputBuilder::new_with_amount(2_000_000, account_id_1) .add_unlock_condition(AddressUnlockCondition::new( Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -683,13 +710,16 @@ fn mint_and_burn_at_the_same_time() { let foundry_id = FoundryId::build(&AccountAddress::from(account_id_1), 1, SimpleTokenScheme::KIND); let token_id = TokenId::from(foundry_id); - let mut inputs = build_inputs([Foundry( - 1_000_000, - account_id_1, - 1, - SimpleTokenScheme::new(100, 0, 200).unwrap(), - Some((&token_id.to_string(), 100)), - )]); + let mut inputs = build_inputs( + [Foundry( + 1_000_000, + account_id_1, + 1, + SimpleTokenScheme::new(100, 0, 200).unwrap(), + Some((&token_id.to_string(), 100)), + )], + None, + ); let account_output = AccountOutputBuilder::new_with_amount(2_000_000, account_id_1) .add_unlock_condition(AddressUnlockCondition::new( Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -733,25 +763,28 @@ fn take_amount_from_account_and_foundry_to_fund_basic() { let foundry_id = FoundryId::build(&AccountAddress::from(account_id_1), 0, SimpleTokenScheme::KIND); let token_id = TokenId::from(foundry_id); - let mut inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Foundry( - 1_000_000, - account_id_1, - 1, - SimpleTokenScheme::new(100, 0, 200).unwrap(), - Some((&token_id.to_string(), 100)), - ), - ]); + let mut inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Foundry( + 1_000_000, + account_id_1, + 1, + SimpleTokenScheme::new(100, 0, 200).unwrap(), + Some((&token_id.to_string(), 100)), + ), + ], + None, + ); let account_output = AccountOutputBuilder::new_with_amount(2_000_000, account_id_1) .add_unlock_condition(AddressUnlockCondition::new( Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -802,23 +835,26 @@ fn create_native_token_but_burn_account() { let foundry_id = FoundryId::build(&AccountAddress::from(account_id_1), 1, SimpleTokenScheme::KIND); let token_id = TokenId::from(foundry_id); - let inputs = build_inputs([ - Account( - 2_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - Foundry( - 1_000_000, - account_id_1, - 1, - SimpleTokenScheme::new(0, 0, 100).unwrap(), - None, - ), - ]); + let inputs = build_inputs( + [ + Account( + 2_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + Foundry( + 1_000_000, + account_id_1, + 1, + SimpleTokenScheme::new(0, 0, 100).unwrap(), + None, + ), + ], + None, + ); let outputs = build_outputs([Foundry( 1_000_000, account_id_1, @@ -860,23 +896,26 @@ fn melted_tokens_not_provided() { let foundry_id = FoundryId::build(&AccountAddress::from(account_id_1), 1, SimpleTokenScheme::KIND); let token_id_1 = TokenId::from(foundry_id); - let inputs = build_inputs([ - Account( - 2_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - Foundry( - 1_000_000, - account_id_1, - 1, - SimpleTokenScheme::new(100, 0, 100).unwrap(), - None, - ), - ]); + let inputs = build_inputs( + [ + Account( + 2_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + Foundry( + 1_000_000, + account_id_1, + 1, + SimpleTokenScheme::new(100, 0, 100).unwrap(), + None, + ), + ], + None, + ); let outputs = build_outputs([Foundry( 1_000_000, account_id_1, @@ -909,23 +948,26 @@ fn burned_tokens_not_provided() { let foundry_id = FoundryId::build(&AccountAddress::from(account_id_1), 0, SimpleTokenScheme::KIND); let token_id_1 = TokenId::from(foundry_id); - let inputs = build_inputs([ - Account( - 2_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - Foundry( - 1_000_000, - account_id_1, - 1, - SimpleTokenScheme::new(100, 0, 100).unwrap(), - None, - ), - ]); + let inputs = build_inputs( + [ + Account( + 2_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + Foundry( + 1_000_000, + account_id_1, + 1, + SimpleTokenScheme::new(100, 0, 100).unwrap(), + None, + ), + ], + None, + ); let outputs = build_outputs([Foundry( 1_000_000, account_id_1, @@ -957,13 +999,16 @@ fn foundry_in_outputs_and_required() { let protocol_parameters = protocol_parameters(); let account_id_2 = AccountId::from_str(ACCOUNT_ID_2).unwrap(); - let mut inputs = build_inputs([Foundry( - 1_000_000, - account_id_2, - 1, - SimpleTokenScheme::new(0, 0, 10).unwrap(), + let mut inputs = build_inputs( + [Foundry( + 1_000_000, + account_id_2, + 1, + SimpleTokenScheme::new(0, 0, 10).unwrap(), + None, + )], None, - )]); + ); let account_output = AccountOutputBuilder::new_with_amount(1_251_500, account_id_2) .add_unlock_condition(AddressUnlockCondition::new( Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1011,25 +1056,28 @@ fn melt_and_burn_native_tokens() { let foundry_id = FoundryId::build(&AccountAddress::from(account_id), 1, SimpleTokenScheme::KIND); let token_id = TokenId::from(foundry_id); - let mut inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Foundry( - 1_000_000, - account_id, - 1, - SimpleTokenScheme::new(1000, 0, 1000).unwrap(), - Some((&token_id.to_string(), 1000)), - ), - ]); + let mut inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Foundry( + 1_000_000, + account_id, + 1, + SimpleTokenScheme::new(1000, 0, 1000).unwrap(), + Some((&token_id.to_string(), 1000)), + ), + ], + None, + ); let account_output = AccountOutputBuilder::new_with_amount(1_000_000, account_id) .add_unlock_condition(AddressUnlockCondition::new( Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), diff --git a/sdk/tests/client/input_selection/nft_outputs.rs b/sdk/tests/client/input_selection/nft_outputs.rs index 33ddf7c960..ad3d40db1e 100644 --- a/sdk/tests/client/input_selection/nft_outputs.rs +++ b/sdk/tests/client/input_selection/nft_outputs.rs @@ -29,16 +29,19 @@ fn input_nft_eq_output_nft() { let protocol_parameters = protocol_parameters(); let nft_id_2 = NftId::from_str(NFT_ID_2).unwrap(); - let inputs = build_inputs([Nft( - 1_000_000, - nft_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, + let inputs = build_inputs( + [Nft( + 1_000_000, + nft_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Nft( 1_000_000, nft_id_2, @@ -68,16 +71,19 @@ fn transition_nft_id_zero() { let protocol_parameters = protocol_parameters(); let nft_id_0 = NftId::from_str(NFT_ID_0).unwrap(); - let inputs = build_inputs([Nft( - 1_000_000, - nft_id_0, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, + let inputs = build_inputs( + [Nft( + 1_000_000, + nft_id_0, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + )], None, - )]); + ); let nft_id = NftId::from(inputs[0].output_id()); let outputs = build_outputs([Nft( 1_000_000, @@ -196,16 +202,19 @@ fn mint_nft() { let protocol_parameters = protocol_parameters(); let nft_id_0 = NftId::from_str(NFT_ID_0).unwrap(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Nft( 1_000_000, nft_id_0, @@ -244,16 +253,19 @@ fn burn_nft() { let protocol_parameters = protocol_parameters(); let nft_id_2 = NftId::from_str(NFT_ID_2).unwrap(); - let inputs = build_inputs([Nft( - 2_000_000, - nft_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, + let inputs = build_inputs( + [Nft( + 2_000_000, + nft_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -329,16 +341,19 @@ fn missing_input_for_nft_output() { let protocol_parameters = protocol_parameters(); let nft_id_2 = NftId::from_str(NFT_ID_2).unwrap(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Nft( 1_000_000, nft_id_2, @@ -369,16 +384,19 @@ fn missing_input_for_nft_output_but_created() { let protocol_parameters = protocol_parameters(); let nft_id_0 = NftId::from_str(NFT_ID_0).unwrap(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Nft( 1_000_000, nft_id_0, @@ -406,28 +424,31 @@ fn nft_in_output_and_sender() { let protocol_parameters = protocol_parameters(); let nft_id_1 = NftId::from_str(NFT_ID_1).unwrap(); - let inputs = build_inputs([ - Nft( - 1_000_000, - nft_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Nft( + 1_000_000, + nft_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([ Nft( 1_000_000, @@ -477,16 +498,19 @@ fn missing_ed25519_sender() { let protocol_parameters = protocol_parameters(); let nft_id_2 = NftId::from_str(NFT_ID_2).unwrap(); - let inputs = build_inputs([Nft( - 1_000_000, - nft_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, + let inputs = build_inputs( + [Nft( + 1_000_000, + nft_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Nft( 1_000_000, nft_id_2, @@ -517,16 +541,19 @@ fn missing_ed25519_issuer_created() { let protocol_parameters = protocol_parameters(); let nft_id_0 = NftId::from_str(NFT_ID_0).unwrap(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Nft( 1_000_000, nft_id_0, @@ -557,16 +584,19 @@ fn missing_ed25519_issuer_transition() { let protocol_parameters = protocol_parameters(); let nft_id_1 = NftId::from_str(NFT_ID_1).unwrap(); - let inputs = build_inputs([Nft( - 1_000_000, - nft_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - Some(Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap()), - None, - None, + let inputs = build_inputs( + [Nft( + 1_000_000, + nft_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + Some(Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap()), + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Nft( 1_000_000, nft_id_1, @@ -594,16 +624,19 @@ fn missing_account_sender() { let protocol_parameters = protocol_parameters(); let nft_id_2 = NftId::from_str(NFT_ID_2).unwrap(); - let inputs = build_inputs([Nft( - 1_000_000, - nft_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, + let inputs = build_inputs( + [Nft( + 1_000_000, + nft_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Nft( 1_000_000, nft_id_2, @@ -634,16 +667,19 @@ fn missing_account_issuer_created() { let protocol_parameters = protocol_parameters(); let nft_id_0 = NftId::from_str(NFT_ID_0).unwrap(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Nft( 1_000_000, nft_id_0, @@ -674,16 +710,19 @@ fn missing_account_issuer_transition() { let protocol_parameters = protocol_parameters(); let nft_id_2 = NftId::from_str(NFT_ID_2).unwrap(); - let inputs = build_inputs([Nft( - 1_000_000, - nft_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - Some(Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap()), - None, - None, + let inputs = build_inputs( + [Nft( + 1_000_000, + nft_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + Some(Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap()), + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Nft( 1_000_000, nft_id_2, @@ -711,16 +750,19 @@ fn missing_nft_sender() { let protocol_parameters = protocol_parameters(); let nft_id_2 = NftId::from_str(NFT_ID_2).unwrap(); - let inputs = build_inputs([Nft( - 1_000_000, - nft_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, + let inputs = build_inputs( + [Nft( + 1_000_000, + nft_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Nft( 1_000_000, nft_id_2, @@ -751,16 +793,19 @@ fn missing_nft_issuer_created() { let protocol_parameters = protocol_parameters(); let nft_id_0 = NftId::from_str(NFT_ID_0).unwrap(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Nft( 1_000_000, nft_id_0, @@ -791,16 +836,19 @@ fn missing_nft_issuer_transition() { let protocol_parameters = protocol_parameters(); let nft_id_2 = NftId::from_str(NFT_ID_2).unwrap(); - let inputs = build_inputs([Nft( - 1_000_000, - nft_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - Some(Address::try_from_bech32(BECH32_ADDRESS_NFT_1).unwrap()), - None, - None, + let inputs = build_inputs( + [Nft( + 1_000_000, + nft_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + Some(Address::try_from_bech32(BECH32_ADDRESS_NFT_1).unwrap()), + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Nft( 1_000_000, nft_id_2, @@ -828,28 +876,31 @@ fn increase_nft_amount() { let protocol_parameters = protocol_parameters(); let nft_id_1 = NftId::from_str(NFT_ID_1).unwrap(); - let inputs = build_inputs([ - Nft( - 2_000_000, - nft_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Nft( + 2_000_000, + nft_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Nft( 3_000_000, nft_id_1, @@ -879,28 +930,31 @@ fn decrease_nft_amount() { let protocol_parameters = protocol_parameters(); let nft_id_1 = NftId::from_str(NFT_ID_1).unwrap(); - let inputs = build_inputs([ - Nft( - 2_000_000, - nft_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Nft( + 2_000_000, + nft_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Nft( 1_000_000, nft_id_1, @@ -942,28 +996,31 @@ fn prefer_basic_to_nft() { let protocol_parameters = protocol_parameters(); let nft_id_1 = NftId::from_str(NFT_ID_1).unwrap(); - let inputs = build_inputs([ - Nft( - 2_000_000, - nft_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Nft( + 2_000_000, + nft_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -994,28 +1051,31 @@ fn take_amount_from_nft_to_fund_basic() { let protocol_parameters = protocol_parameters(); let nft_id_1 = NftId::from_str(NFT_ID_1).unwrap(); - let inputs = build_inputs([ - Nft( - 2_000_000, - nft_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Nft( + 2_000_000, + nft_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 1_200_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1058,28 +1118,31 @@ fn nft_burn_should_validate_nft_sender() { let protocol_parameters = protocol_parameters(); let nft_id_1 = NftId::from_str(NFT_ID_1).unwrap(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Nft( - 1_000_000, - nft_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Nft( + 1_000_000, + nft_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 3_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1110,28 +1173,31 @@ fn nft_burn_should_validate_nft_address() { let protocol_parameters = protocol_parameters(); let nft_id_1 = NftId::from_str(NFT_ID_1).unwrap(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_NFT_1).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Nft( - 1_000_000, - nft_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_NFT_1).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Nft( + 1_000_000, + nft_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 3_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -1162,16 +1228,19 @@ fn transitioned_zero_nft_id_no_longer_is_zero() { let protocol_parameters = protocol_parameters(); let nft_id_0 = NftId::from_str(NFT_ID_0).unwrap(); - let inputs = build_inputs([Nft( - 2_000_000, - nft_id_0, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, + let inputs = build_inputs( + [Nft( + 2_000_000, + nft_id_0, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), diff --git a/sdk/tests/client/input_selection/outputs.rs b/sdk/tests/client/input_selection/outputs.rs index 7fae73e9c5..98551690e9 100644 --- a/sdk/tests/client/input_selection/outputs.rs +++ b/sdk/tests/client/input_selection/outputs.rs @@ -46,16 +46,19 @@ fn no_inputs() { fn no_outputs() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = Vec::new(); let selected = InputSelection::new( @@ -74,14 +77,17 @@ fn no_outputs_but_burn() { let protocol_parameters = protocol_parameters(); let account_id_2 = AccountId::from_str(ACCOUNT_ID_2).unwrap(); - let inputs = build_inputs([Account( - 2_000_000, - account_id_2, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, + let inputs = build_inputs( + [Account( + 2_000_000, + account_id_2, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + )], None, - )]); + ); let outputs = Vec::new(); let selected = InputSelection::new( @@ -108,16 +114,19 @@ fn no_outputs_but_burn() { fn no_address_provided() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -138,16 +147,19 @@ fn no_address_provided() { fn no_matching_address_provided() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -174,28 +186,31 @@ fn no_matching_address_provided() { fn two_addresses_one_missing() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -228,28 +243,31 @@ fn two_addresses_one_missing() { fn two_addresses() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), diff --git a/sdk/tests/client/input_selection/storage_deposit_return.rs b/sdk/tests/client/input_selection/storage_deposit_return.rs index 5c7ba2b633..1ccec61b40 100644 --- a/sdk/tests/client/input_selection/storage_deposit_return.rs +++ b/sdk/tests/client/input_selection/storage_deposit_return.rs @@ -20,16 +20,19 @@ use crate::client::{ fn sdruc_output_not_provided_no_remainder() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), - None, - None, + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -69,16 +72,19 @@ fn sdruc_output_not_provided_no_remainder() { fn sdruc_output_provided_no_remainder() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), - None, - None, + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([ Basic( 1_000_000, @@ -119,16 +125,19 @@ fn sdruc_output_provided_no_remainder() { fn sdruc_output_provided_remainder() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), - None, - None, + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), @@ -168,28 +177,31 @@ fn sdruc_output_provided_remainder() { fn two_sdrucs_to_the_same_address_both_needed() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -229,28 +241,31 @@ fn two_sdrucs_to_the_same_address_both_needed() { fn two_sdrucs_to_the_same_address_one_needed() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -291,28 +306,31 @@ fn two_sdrucs_to_the_same_address_one_needed() { fn two_sdrucs_to_different_addresses_both_needed() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), - None, - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), 1_000_000)), - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), + None, + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), 1_000_000)), + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -358,28 +376,31 @@ fn two_sdrucs_to_different_addresses_both_needed() { fn two_sdrucs_to_different_addresses_one_needed() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), 1_000_000)), - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), 1_000_000)), + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -420,16 +441,19 @@ fn two_sdrucs_to_different_addresses_one_needed() { fn insufficient_amount_because_of_sdruc() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), - None, - None, + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 1_000_000)), + None, + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -462,28 +486,31 @@ fn insufficient_amount_because_of_sdruc() { fn useless_sdruc_required_for_sender_feature() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), 1_000_000)), - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), 1_000_000)), + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), @@ -527,26 +554,29 @@ fn sdruc_required_non_ed25519_in_address_unlock() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), 1_000_000)), - None, - None, - None, - ), - Account( - 1_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), 1_000_000)), + None, + None, + None, + ), + Account( + 1_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), @@ -587,36 +617,39 @@ fn useless_sdruc_non_ed25519_in_address_unlock() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([ - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap(), - None, - None, - Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), 1_000_000)), - None, - None, - None, - ), - Basic( - 1_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap(), - None, - None, - None, - None, - None, - None, - ), - Account( - 1_000_000, - account_id_1, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap(), + None, + None, + Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), 1_000_000)), + None, + None, + None, + ), + Basic( + 1_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap(), + None, + None, + None, + None, + None, + None, + ), + Account( + 1_000_000, + account_id_1, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), diff --git a/sdk/tests/client/input_selection/timelock.rs b/sdk/tests/client/input_selection/timelock.rs index 7c27a9bad9..d5a100cf6d 100644 --- a/sdk/tests/client/input_selection/timelock.rs +++ b/sdk/tests/client/input_selection/timelock.rs @@ -15,16 +15,19 @@ use crate::client::{ fn one_output_timelock_not_expired() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - Some(200), - None, + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + Some(200), + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 1_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), @@ -52,16 +55,19 @@ fn one_output_timelock_not_expired() { fn timelock_equal_timestamp() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - Some(200), - None, + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + Some(200), + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), @@ -91,28 +97,31 @@ fn timelock_equal_timestamp() { fn two_outputs_one_timelock_expired() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - Some(200), - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - Some(50), - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + Some(200), + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + Some(50), + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), @@ -143,28 +152,31 @@ fn two_outputs_one_timelock_expired() { fn two_outputs_one_timelocked_one_missing() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - Some(200), - None, - None, - ), - Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs( + [ + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + Some(200), + None, + None, + ), + Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + None, + None, + None, + ), + ], + None, + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), @@ -195,16 +207,19 @@ fn two_outputs_one_timelocked_one_missing() { fn one_output_timelock_expired() { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 2_000_000, - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - None, - None, - None, - Some(50), - None, + let inputs = build_inputs( + [Basic( + 2_000_000, + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + None, + None, + None, + Some(50), + None, + None, + )], None, - )]); + ); let outputs = build_outputs([Basic( 2_000_000, Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), diff --git a/sdk/tests/client/mod.rs b/sdk/tests/client/mod.rs index 987ef89ea8..e65ca490d2 100644 --- a/sdk/tests/client/mod.rs +++ b/sdk/tests/client/mod.rs @@ -31,7 +31,11 @@ use iota_sdk::{ AccountId, AccountOutputBuilder, BasicOutputBuilder, FoundryOutputBuilder, NativeToken, NftId, NftOutputBuilder, Output, OutputId, SimpleTokenScheme, TokenId, TokenScheme, }, - rand::{output::rand_output_metadata_with_id, transaction::rand_transaction_id}, + rand::{ + output::rand_output_metadata_with_id, + transaction::{rand_transaction_id, rand_transaction_id_with_slot_index}, + }, + slot::SlotIndex, }, }; @@ -208,15 +212,22 @@ fn build_output_inner(build: Build) -> (Output, Option) { } } -fn build_inputs<'a>(outputs: impl IntoIterator>) -> Vec { +fn build_inputs<'a>( + outputs: impl IntoIterator>, + slot_index: Option, +) -> Vec { outputs .into_iter() .map(|build| { let (output, chain) = build_output_inner(build); + let transaction_id = slot_index.map_or_else( + || rand_transaction_id(), + |index| rand_transaction_id_with_slot_index(index), + ); InputSigningData { output, - output_metadata: rand_output_metadata_with_id(OutputId::new(rand_transaction_id(), 0)), + output_metadata: rand_output_metadata_with_id(OutputId::new(transaction_id, 0)), chain, } }) diff --git a/sdk/tests/client/signing/account.rs b/sdk/tests/client/signing/account.rs index 30eafbb97c..9d19b42193 100644 --- a/sdk/tests/client/signing/account.rs +++ b/sdk/tests/client/signing/account.rs @@ -20,7 +20,6 @@ use iota_sdk::{ output::AccountId, payload::{signed_transaction::Transaction, SignedTransactionPayload}, protocol::protocol_parameters, - rand::mana::rand_mana_allotment, unlock::{SignatureUnlock, Unlock}, }, }; @@ -49,14 +48,17 @@ async fn sign_account_state_transition() -> Result<()> { let protocol_parameters = protocol_parameters(); let account_id = AccountId::from_str(ACCOUNT_ID_1)?; - let inputs = build_inputs([Account( - 1_000_000, - account_id, - address.clone(), - None, + let inputs = build_inputs( + [Account( + 1_000_000, + account_id, + address.clone(), + None, + None, + Some(Bip44::new(SHIMMER_COIN_TYPE)), + )], None, - Some(Bip44::new(SHIMMER_COIN_TYPE)), - )]); + ); let outputs = build_outputs([Account(1_000_000, account_id, address.clone(), None, None, None)]); @@ -68,7 +70,14 @@ async fn sign_account_state_transition() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) + .with_creation_slot( + inputs + .iter() + .map(|i| i.output_id().transaction_id().slot_index()) + .max() + .unwrap() + + 1, + ) .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { @@ -115,18 +124,21 @@ async fn account_reference_unlocks() -> Result<()> { let account_id = AccountId::from_str(ACCOUNT_ID_1)?; let account_address = Address::Account(AccountAddress::new(account_id)); - let inputs = build_inputs([ - Account( - 1_000_000, - account_id, - address.clone(), - None, - None, - Some(Bip44::new(SHIMMER_COIN_TYPE)), - ), - Basic(1_000_000, account_address.clone(), None, None, None, None, None, None), - Basic(1_000_000, account_address.clone(), None, None, None, None, None, None), - ]); + let inputs = build_inputs( + [ + Account( + 1_000_000, + account_id, + address.clone(), + None, + None, + Some(Bip44::new(SHIMMER_COIN_TYPE)), + ), + Basic(1_000_000, account_address.clone(), None, None, None, None, None, None), + Basic(1_000_000, account_address.clone(), None, None, None, None, None, None), + ], + None, + ); let outputs = build_outputs([ Account(1_000_000, account_id, address, None, None, None), @@ -141,7 +153,14 @@ async fn account_reference_unlocks() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) + .with_creation_slot( + inputs + .iter() + .map(|i| i.output_id().transaction_id().slot_index()) + .max() + .unwrap() + + 1, + ) .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { diff --git a/sdk/tests/client/signing/basic.rs b/sdk/tests/client/signing/basic.rs index ba9a2eb5b0..2988f2bccf 100644 --- a/sdk/tests/client/signing/basic.rs +++ b/sdk/tests/client/signing/basic.rs @@ -16,7 +16,6 @@ use iota_sdk::{ input::{Input, UtxoInput}, payload::{signed_transaction::Transaction, SignedTransactionPayload}, protocol::protocol_parameters, - rand::mana::rand_mana_allotment, unlock::{SignatureUnlock, Unlock}, }, }; @@ -40,16 +39,19 @@ async fn single_ed25519_unlock() -> Result<()> { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([Basic( - 1_000_000, - address_0.clone(), - None, - None, - None, - None, + let inputs = build_inputs( + [Basic( + 1_000_000, + address_0.clone(), + None, + None, + None, + None, + None, + Some(Bip44::new(SHIMMER_COIN_TYPE)), + )], None, - Some(Bip44::new(SHIMMER_COIN_TYPE)), - )]); + ); let outputs = build_outputs([Basic( 1_000_000, @@ -70,7 +72,14 @@ async fn single_ed25519_unlock() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) + .with_creation_slot( + inputs + .iter() + .map(|i| i.output_id().transaction_id().slot_index()) + .max() + .unwrap() + + 1, + ) .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { @@ -115,38 +124,41 @@ async fn ed25519_reference_unlocks() -> Result<()> { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 1_000_000, - address_0.clone(), - None, - None, - None, - None, - None, - Some(Bip44::new(SHIMMER_COIN_TYPE)), - ), - Basic( - 1_000_000, - address_0.clone(), - None, - None, - None, - None, - None, - Some(Bip44::new(SHIMMER_COIN_TYPE)), - ), - Basic( - 1_000_000, - address_0.clone(), - None, - None, - None, - None, - None, - Some(Bip44::new(SHIMMER_COIN_TYPE)), - ), - ]); + let inputs = build_inputs( + [ + Basic( + 1_000_000, + address_0.clone(), + None, + None, + None, + None, + None, + Some(Bip44::new(SHIMMER_COIN_TYPE)), + ), + Basic( + 1_000_000, + address_0.clone(), + None, + None, + None, + None, + None, + Some(Bip44::new(SHIMMER_COIN_TYPE)), + ), + Basic( + 1_000_000, + address_0.clone(), + None, + None, + None, + None, + None, + Some(Bip44::new(SHIMMER_COIN_TYPE)), + ), + ], + None, + ); let outputs = build_outputs([Basic( 3_000_000, @@ -167,7 +179,14 @@ async fn ed25519_reference_unlocks() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) + .with_creation_slot( + inputs + .iter() + .map(|i| i.output_id().transaction_id().slot_index()) + .max() + .unwrap() + + 1, + ) .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { @@ -233,28 +252,31 @@ async fn two_signature_unlocks() -> Result<()> { let protocol_parameters = protocol_parameters(); - let inputs = build_inputs([ - Basic( - 1_000_000, - address_0.clone(), - None, - None, - None, - None, - None, - Some(Bip44::new(SHIMMER_COIN_TYPE)), - ), - Basic( - 1_000_000, - address_1, - None, - None, - None, - None, - None, - Some(Bip44::new(SHIMMER_COIN_TYPE).with_address_index(1)), - ), - ]); + let inputs = build_inputs( + [ + Basic( + 1_000_000, + address_0.clone(), + None, + None, + None, + None, + None, + Some(Bip44::new(SHIMMER_COIN_TYPE)), + ), + Basic( + 1_000_000, + address_1, + None, + None, + None, + None, + None, + Some(Bip44::new(SHIMMER_COIN_TYPE).with_address_index(1)), + ), + ], + None, + ); let outputs = build_outputs([Basic( 2_000_000, @@ -275,7 +297,14 @@ async fn two_signature_unlocks() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) + .with_creation_slot( + inputs + .iter() + .map(|i| i.output_id().transaction_id().slot_index()) + .max() + .unwrap() + + 1, + ) .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { diff --git a/sdk/tests/client/signing/mod.rs b/sdk/tests/client/signing/mod.rs index a5149ec73a..44e65b9de2 100644 --- a/sdk/tests/client/signing/mod.rs +++ b/sdk/tests/client/signing/mod.rs @@ -19,13 +19,12 @@ use iota_sdk::{ Result, }, types::block::{ - address::{AccountAddress, Address, NftAddress, ToBech32Ext}, + address::{AccountAddress, Address, NftAddress}, context_input::{CommitmentContextInput, ContextInput}, input::{Input, UtxoInput}, output::{AccountId, NftId}, payload::{signed_transaction::Transaction, SignedTransactionPayload}, protocol::protocol_parameters, - rand::mana::rand_mana_allotment, slot::{SlotCommitmentId, SlotIndex}, unlock::{SignatureUnlock, Unlock}, }, @@ -72,125 +71,128 @@ async fn all_combined() -> Result<()> { let nft_3 = Address::Nft(NftAddress::new(nft_id_3)); let nft_4 = Address::Nft(NftAddress::new(nft_id_4)); - let inputs = build_inputs([ - Account(1_000_000, account_id_1, nft_1.clone(), None, None, None), - Account( - 1_000_000, - account_id_2, - ed25519_0.clone(), - None, - None, - Some(Bip44::new(SHIMMER_COIN_TYPE)), - ), - Basic(1_000_000, account_1.clone(), None, None, None, None, None, None), - Basic(1_000_000, account_2.clone(), None, None, None, None, None, None), - Basic(1_000_000, account_2, None, None, None, None, None, None), - Basic(1_000_000, nft_2.clone(), None, None, None, None, None, None), - Basic(1_000_000, nft_2, None, None, None, None, None, None), - Basic(1_000_000, nft_4.clone(), None, None, None, None, None, None), - Basic( - 1_000_000, - ed25519_0.clone(), - None, - None, - None, - None, - None, - Some(Bip44::new(SHIMMER_COIN_TYPE)), - ), - Basic( - 1_000_000, - ed25519_1.clone(), - None, - None, - None, - None, - None, - Some(Bip44::new(SHIMMER_COIN_TYPE).with_address_index(1)), - ), - Basic( - 1_000_000, - ed25519_2.clone(), - None, - None, - None, - None, - None, - Some(Bip44::new(SHIMMER_COIN_TYPE).with_address_index(2)), - ), - Basic( - 1_000_000, - ed25519_2.clone(), - None, - None, - None, - None, - None, - Some(Bip44::new(SHIMMER_COIN_TYPE).with_address_index(2)), - ), - Nft( - 1_000_000, - nft_id_1, - ed25519_0.clone(), - None, - None, - None, - None, - Some(Bip44::new(SHIMMER_COIN_TYPE)), - ), - Nft(1_000_000, nft_id_2, account_1.clone(), None, None, None, None, None), - // Expirations - Basic( - 2_000_000, - ed25519_0.clone(), - None, - None, - None, - None, - Some((account_1.clone(), 50)), - None, - ), - Basic( - 2_000_000, - ed25519_0.clone(), - None, - None, - None, - None, - Some((nft_3.clone(), 50)), - None, - ), - Basic( - 2_000_000, - ed25519_0.clone(), - None, - None, - None, - None, - Some((nft_3.clone(), 150)), - Some(Bip44::new(SHIMMER_COIN_TYPE)), - ), - Nft( - 1_000_000, - nft_id_3, - account_1.clone(), - None, - None, - None, - Some((nft_4, 50)), - None, - ), - Nft( - 1_000_000, - nft_id_4, - account_1, - None, - None, - None, - Some((nft_3, 150)), - None, - ), - ]); + let inputs = build_inputs( + [ + Account(1_000_000, account_id_1, nft_1.clone(), None, None, None), + Account( + 1_000_000, + account_id_2, + ed25519_0.clone(), + None, + None, + Some(Bip44::new(SHIMMER_COIN_TYPE)), + ), + Basic(1_000_000, account_1.clone(), None, None, None, None, None, None), + Basic(1_000_000, account_2.clone(), None, None, None, None, None, None), + Basic(1_000_000, account_2, None, None, None, None, None, None), + Basic(1_000_000, nft_2.clone(), None, None, None, None, None, None), + Basic(1_000_000, nft_2, None, None, None, None, None, None), + Basic(1_000_000, nft_4.clone(), None, None, None, None, None, None), + Basic( + 1_000_000, + ed25519_0.clone(), + None, + None, + None, + None, + None, + Some(Bip44::new(SHIMMER_COIN_TYPE)), + ), + Basic( + 1_000_000, + ed25519_1.clone(), + None, + None, + None, + None, + None, + Some(Bip44::new(SHIMMER_COIN_TYPE).with_address_index(1)), + ), + Basic( + 1_000_000, + ed25519_2.clone(), + None, + None, + None, + None, + None, + Some(Bip44::new(SHIMMER_COIN_TYPE).with_address_index(2)), + ), + Basic( + 1_000_000, + ed25519_2.clone(), + None, + None, + None, + None, + None, + Some(Bip44::new(SHIMMER_COIN_TYPE).with_address_index(2)), + ), + Nft( + 1_000_000, + nft_id_1, + ed25519_0.clone(), + None, + None, + None, + None, + Some(Bip44::new(SHIMMER_COIN_TYPE)), + ), + Nft(1_000_000, nft_id_2, account_1.clone(), None, None, None, None, None), + // Expirations + Basic( + 2_000_000, + ed25519_0.clone(), + None, + None, + None, + None, + Some((account_1.clone(), 50)), + None, + ), + Basic( + 2_000_000, + ed25519_0.clone(), + None, + None, + None, + None, + Some((nft_3.clone(), 50)), + None, + ), + Basic( + 2_000_000, + ed25519_0.clone(), + None, + None, + None, + None, + Some((nft_3.clone(), 150)), + Some(Bip44::new(SHIMMER_COIN_TYPE)), + ), + Nft( + 1_000_000, + nft_id_3, + account_1.clone(), + None, + None, + None, + Some((nft_4, 50)), + None, + ), + Nft( + 1_000_000, + nft_id_4, + account_1, + None, + None, + None, + Some((nft_3, 150)), + None, + ), + ], + None, + ); let outputs = build_outputs([ Account(1_000_000, account_id_1, nft_1, None, None, None), @@ -227,7 +229,6 @@ async fn all_combined() -> Result<()> { ) .with_outputs(outputs) .with_creation_slot(slot_index) - .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { diff --git a/sdk/tests/client/signing/nft.rs b/sdk/tests/client/signing/nft.rs index 65e0470d18..20494c00bf 100644 --- a/sdk/tests/client/signing/nft.rs +++ b/sdk/tests/client/signing/nft.rs @@ -20,7 +20,6 @@ use iota_sdk::{ output::NftId, payload::{signed_transaction::Transaction, SignedTransactionPayload}, protocol::protocol_parameters, - rand::mana::rand_mana_allotment, unlock::{SignatureUnlock, Unlock}, }, }; @@ -50,20 +49,23 @@ async fn nft_reference_unlocks() -> Result<()> { let nft_id = NftId::from_str(NFT_ID_1)?; let nft_address = Address::Nft(NftAddress::new(nft_id)); - let inputs = build_inputs([ - Nft( - 1_000_000, - nft_id, - address_0.clone(), - None, - None, - None, - None, - Some(Bip44::new(SHIMMER_COIN_TYPE)), - ), - Basic(1_000_000, nft_address.clone(), None, None, None, None, None, None), - Basic(1_000_000, nft_address.clone(), None, None, None, None, None, None), - ]); + let inputs = build_inputs( + [ + Nft( + 1_000_000, + nft_id, + address_0.clone(), + None, + None, + None, + None, + Some(Bip44::new(SHIMMER_COIN_TYPE)), + ), + Basic(1_000_000, nft_address.clone(), None, None, None, None, None, None), + Basic(1_000_000, nft_address.clone(), None, None, None, None, None, None), + ], + None, + ); let outputs = build_outputs([ Nft(1_000_000, nft_id, address_0, None, None, None, None, None), @@ -78,7 +80,14 @@ async fn nft_reference_unlocks() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) + .with_creation_slot( + inputs + .iter() + .map(|i| i.output_id().transaction_id().slot_index()) + .max() + .unwrap() + + 1, + ) .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { From 2239db38b24c300428356f362faf95737f62d047 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 11 Jan 2024 09:26:34 +0100 Subject: [PATCH 06/11] Fix tests --- sdk/tests/client/signing/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/tests/client/signing/mod.rs b/sdk/tests/client/signing/mod.rs index 44e65b9de2..dc38b1fd3d 100644 --- a/sdk/tests/client/signing/mod.rs +++ b/sdk/tests/client/signing/mod.rs @@ -71,6 +71,8 @@ async fn all_combined() -> Result<()> { let nft_3 = Address::Nft(NftAddress::new(nft_id_3)); let nft_4 = Address::Nft(NftAddress::new(nft_id_4)); + let slot_index = SlotIndex::from(90); + let inputs = build_inputs( [ Account(1_000_000, account_id_1, nft_1.clone(), None, None, None), @@ -191,7 +193,7 @@ async fn all_combined() -> Result<()> { None, ), ], - None, + Some(slot_index), ); let outputs = build_outputs([ @@ -204,8 +206,6 @@ async fn all_combined() -> Result<()> { Nft(1_000_000, nft_id_4, ed25519_0.clone(), None, None, None, None, None), ]); - let slot_index = SlotIndex::from(90); - let selected = InputSelection::new( inputs.clone(), outputs.clone(), From 71b34ef3b603a2bd55a54ed62b1544ce7ebbd01b Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 11 Jan 2024 10:09:21 +0100 Subject: [PATCH 07/11] rand nit --- sdk/src/types/block/rand/transaction.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sdk/src/types/block/rand/transaction.rs b/sdk/src/types/block/rand/transaction.rs index d147183e61..5a12cdcac1 100644 --- a/sdk/src/types/block/rand/transaction.rs +++ b/sdk/src/types/block/rand/transaction.rs @@ -3,16 +3,16 @@ use crate::types::block::{ payload::signed_transaction::{TransactionHash, TransactionId}, - rand::bytes::rand_bytes_array, + rand::{bytes::rand_bytes_array, number::rand_number}, slot::SlotIndex, }; -/// Generates a random transaction id. -pub fn rand_transaction_id() -> TransactionId { - TransactionId::new(rand_bytes_array()) -} - /// Generates a random transaction id with a given slot index. pub fn rand_transaction_id_with_slot_index(slot_index: impl Into) -> TransactionId { TransactionHash::new(rand_bytes_array()).into_transaction_id(slot_index.into()) } + +/// Generates a random transaction id. +pub fn rand_transaction_id() -> TransactionId { + rand_transaction_id_with_slot_index(rand_number::()) +} From 14dd3cc4f77aefac760c76c87003fbd25ad8b068 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 11 Jan 2024 10:22:12 +0100 Subject: [PATCH 08/11] Simplify tests --- sdk/tests/client/signing/account.rs | 25 ++++++------------- sdk/tests/client/signing/basic.rs | 37 ++++++++--------------------- sdk/tests/client/signing/nft.rs | 13 ++++------ 3 files changed, 21 insertions(+), 54 deletions(-) diff --git a/sdk/tests/client/signing/account.rs b/sdk/tests/client/signing/account.rs index 9d19b42193..a97ed6d29e 100644 --- a/sdk/tests/client/signing/account.rs +++ b/sdk/tests/client/signing/account.rs @@ -20,6 +20,7 @@ use iota_sdk::{ output::AccountId, payload::{signed_transaction::Transaction, SignedTransactionPayload}, protocol::protocol_parameters, + slot::SlotIndex, unlock::{SignatureUnlock, Unlock}, }, }; @@ -47,6 +48,7 @@ async fn sign_account_state_transition() -> Result<()> { let protocol_parameters = protocol_parameters(); let account_id = AccountId::from_str(ACCOUNT_ID_1)?; + let slot_index = SlotIndex::from(10); let inputs = build_inputs( [Account( @@ -57,7 +59,7 @@ async fn sign_account_state_transition() -> Result<()> { None, Some(Bip44::new(SHIMMER_COIN_TYPE)), )], - None, + Some(slot_index), ); let outputs = build_outputs([Account(1_000_000, account_id, address.clone(), None, None, None)]); @@ -70,14 +72,7 @@ async fn sign_account_state_transition() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .with_creation_slot( - inputs - .iter() - .map(|i| i.output_id().transaction_id().slot_index()) - .max() - .unwrap() - + 1, - ) + .with_creation_slot(slot_index + 1) .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { @@ -123,6 +118,7 @@ async fn account_reference_unlocks() -> Result<()> { let protocol_parameters = protocol_parameters(); let account_id = AccountId::from_str(ACCOUNT_ID_1)?; let account_address = Address::Account(AccountAddress::new(account_id)); + let slot_index = SlotIndex::from(10); let inputs = build_inputs( [ @@ -137,7 +133,7 @@ async fn account_reference_unlocks() -> Result<()> { Basic(1_000_000, account_address.clone(), None, None, None, None, None, None), Basic(1_000_000, account_address.clone(), None, None, None, None, None, None), ], - None, + Some(slot_index), ); let outputs = build_outputs([ @@ -153,14 +149,7 @@ async fn account_reference_unlocks() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .with_creation_slot( - inputs - .iter() - .map(|i| i.output_id().transaction_id().slot_index()) - .max() - .unwrap() - + 1, - ) + .with_creation_slot(slot_index + 1) .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { diff --git a/sdk/tests/client/signing/basic.rs b/sdk/tests/client/signing/basic.rs index 2988f2bccf..07b7a4144d 100644 --- a/sdk/tests/client/signing/basic.rs +++ b/sdk/tests/client/signing/basic.rs @@ -16,6 +16,7 @@ use iota_sdk::{ input::{Input, UtxoInput}, payload::{signed_transaction::Transaction, SignedTransactionPayload}, protocol::protocol_parameters, + slot::SlotIndex, unlock::{SignatureUnlock, Unlock}, }, }; @@ -38,6 +39,7 @@ async fn single_ed25519_unlock() -> Result<()> { .into_inner(); let protocol_parameters = protocol_parameters(); + let slot_index = SlotIndex::from(10); let inputs = build_inputs( [Basic( @@ -50,7 +52,7 @@ async fn single_ed25519_unlock() -> Result<()> { None, Some(Bip44::new(SHIMMER_COIN_TYPE)), )], - None, + Some(slot_index), ); let outputs = build_outputs([Basic( @@ -72,14 +74,7 @@ async fn single_ed25519_unlock() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .with_creation_slot( - inputs - .iter() - .map(|i| i.output_id().transaction_id().slot_index()) - .max() - .unwrap() - + 1, - ) + .with_creation_slot(slot_index + 1) .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { @@ -123,6 +118,7 @@ async fn ed25519_reference_unlocks() -> Result<()> { .into_inner(); let protocol_parameters = protocol_parameters(); + let slot_index = SlotIndex::from(10); let inputs = build_inputs( [ @@ -157,7 +153,7 @@ async fn ed25519_reference_unlocks() -> Result<()> { Some(Bip44::new(SHIMMER_COIN_TYPE)), ), ], - None, + Some(slot_index), ); let outputs = build_outputs([Basic( @@ -179,14 +175,7 @@ async fn ed25519_reference_unlocks() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .with_creation_slot( - inputs - .iter() - .map(|i| i.output_id().transaction_id().slot_index()) - .max() - .unwrap() - + 1, - ) + .with_creation_slot(slot_index + 1) .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { @@ -251,6 +240,7 @@ async fn two_signature_unlocks() -> Result<()> { .into_inner(); let protocol_parameters = protocol_parameters(); + let slot_index = SlotIndex::from(10); let inputs = build_inputs( [ @@ -275,7 +265,7 @@ async fn two_signature_unlocks() -> Result<()> { Some(Bip44::new(SHIMMER_COIN_TYPE).with_address_index(1)), ), ], - None, + Some(slot_index), ); let outputs = build_outputs([Basic( @@ -297,14 +287,7 @@ async fn two_signature_unlocks() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .with_creation_slot( - inputs - .iter() - .map(|i| i.output_id().transaction_id().slot_index()) - .max() - .unwrap() - + 1, - ) + .with_creation_slot(slot_index + 1) .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { diff --git a/sdk/tests/client/signing/nft.rs b/sdk/tests/client/signing/nft.rs index 20494c00bf..72b4c4d374 100644 --- a/sdk/tests/client/signing/nft.rs +++ b/sdk/tests/client/signing/nft.rs @@ -20,6 +20,7 @@ use iota_sdk::{ output::NftId, payload::{signed_transaction::Transaction, SignedTransactionPayload}, protocol::protocol_parameters, + slot::SlotIndex, unlock::{SignatureUnlock, Unlock}, }, }; @@ -48,6 +49,7 @@ async fn nft_reference_unlocks() -> Result<()> { let protocol_parameters = protocol_parameters(); let nft_id = NftId::from_str(NFT_ID_1)?; let nft_address = Address::Nft(NftAddress::new(nft_id)); + let slot_index = SlotIndex::from(10); let inputs = build_inputs( [ @@ -64,7 +66,7 @@ async fn nft_reference_unlocks() -> Result<()> { Basic(1_000_000, nft_address.clone(), None, None, None, None, None, None), Basic(1_000_000, nft_address.clone(), None, None, None, None, None, None), ], - None, + Some(slot_index), ); let outputs = build_outputs([ @@ -80,14 +82,7 @@ async fn nft_reference_unlocks() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .with_creation_slot( - inputs - .iter() - .map(|i| i.output_id().transaction_id().slot_index()) - .max() - .unwrap() - + 1, - ) + .with_creation_slot(slot_index + 1) .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { From 3923f248823fd2605de26eeec44bff20c616f905 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 11 Jan 2024 10:24:26 +0100 Subject: [PATCH 09/11] Add link to issue --- sdk/src/types/block/semantic/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/types/block/semantic/mod.rs b/sdk/src/types/block/semantic/mod.rs index b45d7713c9..d152faf9a4 100644 --- a/sdk/src/types/block/semantic/mod.rs +++ b/sdk/src/types/block/semantic/mod.rs @@ -191,7 +191,7 @@ impl<'a> SemanticValidationContext<'a> { .checked_add(stored_mana) .ok_or(Error::ConsumedManaOverflow)?; - // TODO: Add reward mana + // TODO: Add reward mana https://github.com/iotaledger/iota-sdk/issues/1310 if let Some(consumed_native_token) = consumed_native_token { let native_token_amount = self From fc9ef2e42744ed950f6641b3d0b2b86b0b6f9960 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 11 Jan 2024 10:56:28 +0100 Subject: [PATCH 10/11] Update sdk/src/types/block/semantic/mod.rs Co-authored-by: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> --- sdk/src/types/block/semantic/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/src/types/block/semantic/mod.rs b/sdk/src/types/block/semantic/mod.rs index d152faf9a4..e9bf091ef3 100644 --- a/sdk/src/types/block/semantic/mod.rs +++ b/sdk/src/types/block/semantic/mod.rs @@ -163,6 +163,7 @@ impl<'a> SemanticValidationContext<'a> { .ok_or(Error::ConsumedAmountOverflow)?; let potential_mana = { + // Deposit amount doesn't generate mana let min_deposit = consumed_output.minimum_amount(self.protocol_parameters.storage_score_parameters()); let generation_amount = consumed_output.amount().saturating_sub(min_deposit); From e220ea5399998f1223223eb5583b390d4e6295b7 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 11 Jan 2024 14:40:54 +0100 Subject: [PATCH 11/11] Format --- bindings/core/src/method/secret_manager.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/core/src/method/secret_manager.rs b/bindings/core/src/method/secret_manager.rs index a4298f2b1e..2a13acbca0 100644 --- a/bindings/core/src/method/secret_manager.rs +++ b/bindings/core/src/method/secret_manager.rs @@ -99,7 +99,7 @@ pub enum SecretManagerMethod { /// Expected response: [`Ok`](crate::Response::Ok) #[cfg(feature = "stronghold")] #[cfg_attr(docsrs, doc(cfg(feature = "stronghold")))] - ClearStrongholdPassword + ClearStrongholdPassword, } #[cfg(test)]