From c51f7c8b01b9cdf2f55d0d7c3de609bcfeec1e62 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Mon, 27 Nov 2023 13:55:12 -0500 Subject: [PATCH 01/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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)] From 2adbb3bc20749bcd98c22e69358f4fddd65b82fc Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 11 Jan 2024 14:44:40 +0100 Subject: [PATCH 12/45] ISA: mana remainder --- .../api/block_builder/input_selection/mod.rs | 8 ++- .../input_selection/remainder.rs | 53 +++++++++++++++++-- sdk/src/client/api/high_level.rs | 10 ++-- sdk/src/types/block/output/mod.rs | 24 +++++++++ sdk/src/types/block/semantic/mod.rs | 15 ++++++ .../wallet/operations/transaction/account.rs | 10 ++-- .../transaction/build_transaction.rs | 22 ++++---- .../operations/transaction/input_selection.rs | 9 ++-- 8 files changed, 122 insertions(+), 29 deletions(-) diff --git a/sdk/src/client/api/block_builder/input_selection/mod.rs b/sdk/src/client/api/block_builder/input_selection/mod.rs index ef13ae2fa1..835c102b62 100644 --- a/sdk/src/client/api/block_builder/input_selection/mod.rs +++ b/sdk/src/client/api/block_builder/input_selection/mod.rs @@ -429,7 +429,7 @@ impl InputSelection { self.validate_transitions()?; - Ok(Selected { + let selected = Selected { inputs: Self::sort_input_signing_data( self.selected_inputs, self.slot_index, @@ -437,7 +437,11 @@ impl InputSelection { )?, outputs: self.outputs, remainder, - }) + }; + + println!("{selected:?}"); + + Ok(selected) } fn validate_transitions(&self) -> Result<(), Error> { diff --git a/sdk/src/client/api/block_builder/input_selection/remainder.rs b/sdk/src/client/api/block_builder/input_selection/remainder.rs index 3f3c06adfb..2e52e314cf 100644 --- a/sdk/src/client/api/block_builder/input_selection/remainder.rs +++ b/sdk/src/client/api/block_builder/input_selection/remainder.rs @@ -14,7 +14,10 @@ use crate::{ client::api::RemainderData, types::block::{ address::{Address, Ed25519Address}, - output::{unlock_condition::AddressUnlockCondition, BasicOutputBuilder, NativeTokensBuilder, Output}, + output::{ + unlock_condition::AddressUnlockCondition, BasicOutputBuilder, MinimumOutputAmount, NativeTokensBuilder, + Output, + }, }, }; @@ -118,7 +121,43 @@ impl InputSelection { let native_tokens_diff = get_native_tokens_diff(&input_native_tokens, &output_native_tokens)?; - if inputs_sum == outputs_sum && native_tokens_diff.is_none() { + let mut input_mana = 0; + + for input in &self.selected_inputs { + let potential_mana = { + let min_deposit = input + .output + .minimum_amount(self.protocol_parameters.storage_score_parameters()); + let generation_amount = input.output.amount().saturating_sub(min_deposit); + + self.protocol_parameters.potential_mana( + generation_amount, + input.output_id().transaction_id().slot_index(), + self.slot_index, + ) + }?; + let stored_mana = self.protocol_parameters.mana_with_decay( + input.output.mana(), + input.output_id().transaction_id().slot_index(), + self.slot_index, + )?; + + println!( + "ISA created {}, target {}", + input.output_id().transaction_id().slot_index(), + self.slot_index, + ); + + input_mana += potential_mana + stored_mana; + // TODO rewards + } + + let output_mana = self.outputs.iter().map(|o| o.mana()).sum::(); + // TODO allotment + + println!("ISA input_mana {input_mana}, output_mana {output_mana}"); + + if inputs_sum == outputs_sum && input_mana == output_mana && native_tokens_diff.is_none() { log::debug!("No remainder required"); return Ok((None, storage_deposit_returns)); } @@ -127,8 +166,9 @@ impl InputSelection { return Err(Error::MissingInputWithEd25519Address); }; - let diff = inputs_sum - outputs_sum; - let mut remainder_builder = BasicOutputBuilder::new_with_amount(diff); + let amount_diff = inputs_sum - outputs_sum; + let mana_diff = input_mana - output_mana; + let mut remainder_builder = BasicOutputBuilder::new_with_amount(amount_diff).with_mana(mana_diff); remainder_builder = remainder_builder.add_unlock_condition(AddressUnlockCondition::new(remainder_address.clone())); @@ -141,7 +181,10 @@ impl InputSelection { let remainder = remainder_builder.finish_output()?; - log::debug!("Created remainder output of {diff} for {remainder_address:?}"); + println!("remainder {remainder:?}"); + + // TODO add log + log::debug!("Created remainder output of {amount_diff} for {remainder_address:?}"); remainder.verify_storage_deposit(self.protocol_parameters.storage_score_parameters())?; diff --git a/sdk/src/client/api/high_level.rs b/sdk/src/client/api/high_level.rs index 55a67e4194..da1b275537 100644 --- a/sdk/src/client/api/high_level.rs +++ b/sdk/src/client/api/high_level.rs @@ -111,23 +111,23 @@ impl Client { // Returns the slot index corresponding to the current timestamp. pub async fn get_slot_index(&self) -> Result { - let current_time = unix_timestamp_now().as_nanos() as u64; + let unix_timestamp = unix_timestamp_now(); + let current_time_nanos = unix_timestamp.as_nanos() as u64; let network_info = self.get_network_info().await?; if let Some(tangle_time) = network_info.tangle_time { // Check the local time is in the range of +-5 minutes of the node to prevent locking funds by accident if !(tangle_time - FIVE_MINUTES_IN_NANOSECONDS..tangle_time + FIVE_MINUTES_IN_NANOSECONDS) - .contains(¤t_time) + .contains(¤t_time_nanos) { return Err(Error::TimeNotSynced { - current_time, + current_time: current_time_nanos, tangle_time, }); } } - // TODO double check with TIP if this should be seconds or nanoseconds - Ok(network_info.protocol_parameters.slot_index(current_time)) + Ok(network_info.protocol_parameters.slot_index(unix_timestamp.as_secs())) } } diff --git a/sdk/src/types/block/output/mod.rs b/sdk/src/types/block/output/mod.rs index 196986c4bc..018879fa07 100644 --- a/sdk/src/types/block/output/mod.rs +++ b/sdk/src/types/block/output/mod.rs @@ -217,6 +217,30 @@ impl Output { } } + /// + pub fn all_mana( + &self, + protocol_parameters: &ProtocolParameters, + creation_index: SlotIndex, + target_index: SlotIndex, + ) -> Result { + let (amount, mana) = match self { + Self::Basic(output) => (output.amount(), output.mana()), + Self::Account(output) => (output.amount(), output.mana()), + Self::Anchor(output) => (output.amount(), output.mana()), + Self::Foundry(output) => (output.amount(), 0), + Self::Nft(output) => (output.amount(), output.mana()), + Self::Delegation(output) => (output.amount(), 0), + }; + + let min_deposit = self.minimum_amount(protocol_parameters.storage_score_parameters()); + let generation_amount = amount.saturating_sub(min_deposit); + let potential_mana = protocol_parameters.potential_mana(generation_amount, creation_index, target_index)?; + let stored_mana = protocol_parameters.mana_with_decay(mana, creation_index, target_index)?; + + Ok(potential_mana + stored_mana) + } + /// Returns the unlock conditions of an [`Output`], if any. pub fn unlock_conditions(&self) -> Option<&UnlockConditions> { match self { diff --git a/sdk/src/types/block/semantic/mod.rs b/sdk/src/types/block/semantic/mod.rs index e9bf091ef3..ddf27ad7f8 100644 --- a/sdk/src/types/block/semantic/mod.rs +++ b/sdk/src/types/block/semantic/mod.rs @@ -174,6 +174,14 @@ impl<'a> SemanticValidationContext<'a> { ) }?; + println!( + "semantic created {}, target {}", + output_id.transaction_id().slot_index(), + self.transaction.creation_slot() + ); + + println!("potential_mana {potential_mana}"); + // Add potential mana self.input_mana = self .input_mana @@ -186,6 +194,8 @@ impl<'a> SemanticValidationContext<'a> { self.transaction.creation_slot(), )?; + println!("stored_mana {stored_mana}"); + // Add stored mana self.input_mana = self .input_mana @@ -292,6 +302,11 @@ impl<'a> SemanticValidationContext<'a> { return Ok(Some(TransactionFailureReason::SumInputsOutputsAmountMismatch)); } + println!( + "Semantic input_mana {} output_mana {}", + self.input_mana, self.output_mana + ); + if self.input_mana != self.output_mana { if self.input_mana > self.output_mana { if !self.transaction.has_capability(TransactionCapabilityFlag::BurnMana) { diff --git a/sdk/src/wallet/operations/transaction/account.rs b/sdk/src/wallet/operations/transaction/account.rs index 81d64777a3..ee14f62fe9 100644 --- a/sdk/src/wallet/operations/transaction/account.rs +++ b/sdk/src/wallet/operations/transaction/account.rs @@ -53,9 +53,9 @@ where { let implicit_account_data = self.data().await.unspent_outputs.get(output_id).cloned(); - let implicit_account = if let Some(implicit_account_data) = &implicit_account_data { + let implicit_account = if let Some(implicit_account_data) = implicit_account_data.clone() { if implicit_account_data.output.is_implicit_account() { - implicit_account_data.output.as_basic() + implicit_account_data.output.as_basic().clone() } else { return Err(Error::ImplicitAccountNotFound); } @@ -86,7 +86,11 @@ where let account_id = AccountId::from(output_id); let account = AccountOutput::build_with_amount(implicit_account.amount(), account_id) - .with_mana(implicit_account.mana()) + .with_mana(implicit_account_data.clone().unwrap().output.all_mana( + &self.client().get_protocol_parameters().await?, + implicit_account_data.unwrap().output_id.transaction_id().slot_index(), + self.client().get_slot_index().await?, + )?) .with_unlock_conditions([AddressUnlockCondition::from(Address::from( *implicit_account .address() diff --git a/sdk/src/wallet/operations/transaction/build_transaction.rs b/sdk/src/wallet/operations/transaction/build_transaction.rs index 079ceb3f35..c2dcda6d87 100644 --- a/sdk/src/wallet/operations/transaction/build_transaction.rs +++ b/sdk/src/wallet/operations/transaction/build_transaction.rs @@ -54,17 +54,17 @@ where builder = builder.with_context_inputs(context_inputs); } - // TODO remove when https://github.com/iotaledger/iota-sdk/issues/1744 is done - match options.capabilities.as_mut() { - Some(capabilities) => { - capabilities.add_capability(TransactionCapabilityFlag::BurnMana); - } - None => { - let mut capabilities = TransactionCapabilities::default(); - capabilities.add_capability(TransactionCapabilityFlag::BurnMana); - options.capabilities = Some(capabilities); - } - } + // // TODO remove when https://github.com/iotaledger/iota-sdk/issues/1744 is done + // match options.capabilities.as_mut() { + // Some(capabilities) => { + // capabilities.add_capability(TransactionCapabilityFlag::BurnMana); + // } + // None => { + // let mut capabilities = TransactionCapabilities::default(); + // capabilities.add_capability(TransactionCapabilityFlag::BurnMana); + // options.capabilities = Some(capabilities); + // } + // } if let Some(capabilities) = options.capabilities { builder = builder.add_capabilities(capabilities.capabilities_iter()); diff --git a/sdk/src/wallet/operations/transaction/input_selection.rs b/sdk/src/wallet/operations/transaction/input_selection.rs index 0460ad4f4f..b7759deb4b 100644 --- a/sdk/src/wallet/operations/transaction/input_selection.rs +++ b/sdk/src/wallet/operations/transaction/input_selection.rs @@ -97,7 +97,8 @@ where protocol_parameters.clone(), ) .with_required_inputs(custom_inputs) - .with_forbidden_inputs(forbidden_inputs); + .with_forbidden_inputs(forbidden_inputs) + .with_slot_index(slot_index); if let Some(address) = remainder_address { input_selection = input_selection.with_remainder_address(address); @@ -136,7 +137,8 @@ where protocol_parameters.clone(), ) .with_required_inputs(mandatory_inputs) - .with_forbidden_inputs(forbidden_inputs); + .with_forbidden_inputs(forbidden_inputs) + .with_slot_index(slot_index); if let Some(address) = remainder_address { input_selection = input_selection.with_remainder_address(address); @@ -171,7 +173,8 @@ where Some(wallet_data.address.clone().into_inner()), protocol_parameters.clone(), ) - .with_forbidden_inputs(forbidden_inputs); + .with_forbidden_inputs(forbidden_inputs) + .with_slot_index(slot_index); if let Some(address) = remainder_address { input_selection = input_selection.with_remainder_address(address); From 696ff5d6a2ff7340bb90f9440e21e822f8f0af8f Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Fri, 12 Jan 2024 12:45:17 +0100 Subject: [PATCH 13/45] Some fixes --- .../api/block_builder/input_selection/mod.rs | 10 +- .../operations/transaction/input_selection.rs | 12 +- .../client/input_selection/account_outputs.rs | 117 +++++++++++------- .../client/input_selection/basic_outputs.rs | 105 ++++++++++------ .../client/input_selection/expiration.rs | 38 +++--- .../client/input_selection/foundry_outputs.rs | 18 ++- .../client/input_selection/nft_outputs.rs | 26 +++- sdk/tests/client/input_selection/outputs.rs | 10 +- .../input_selection/storage_deposit_return.rs | 13 +- sdk/tests/client/input_selection/timelock.rs | 11 +- sdk/tests/client/mod.rs | 1 + sdk/tests/client/signing/mod.rs | 2 +- 12 files changed, 232 insertions(+), 131 deletions(-) diff --git a/sdk/src/client/api/block_builder/input_selection/mod.rs b/sdk/src/client/api/block_builder/input_selection/mod.rs index 835c102b62..4267a6e15e 100644 --- a/sdk/src/client/api/block_builder/input_selection/mod.rs +++ b/sdk/src/client/api/block_builder/input_selection/mod.rs @@ -155,6 +155,7 @@ impl InputSelection { available_inputs: impl Into>, outputs: impl Into>, addresses: impl IntoIterator, + slot_index: impl Into, protocol_parameters: ProtocolParameters, ) -> Self { let available_inputs = available_inputs.into(); @@ -189,9 +190,8 @@ impl InputSelection { burn: None, remainder_address: None, protocol_parameters, - // TODO may want to make this mandatory at some point // Should be set from a commitment context input - slot_index: SlotIndex::from(0), + slot_index: slot_index.into(), requirements: Vec::new(), automatically_transitioned: HashSet::new(), mana_allotments: 0, @@ -222,12 +222,6 @@ impl InputSelection { self } - /// Sets the slot index of an [`InputSelection`]. - pub fn with_slot_index(mut self, slot_index: impl Into) -> Self { - self.slot_index = slot_index.into(); - self - } - /// Sets the mana allotments sum of an [`InputSelection`]. pub fn with_mana_allotments<'a>(mut self, mana_allotments: impl Iterator) -> Self { self.mana_allotments = mana_allotments.map(ManaAllotment::mana).sum(); diff --git a/sdk/src/wallet/operations/transaction/input_selection.rs b/sdk/src/wallet/operations/transaction/input_selection.rs index b7759deb4b..9b06159ed9 100644 --- a/sdk/src/wallet/operations/transaction/input_selection.rs +++ b/sdk/src/wallet/operations/transaction/input_selection.rs @@ -94,11 +94,11 @@ where available_outputs_signing_data, outputs, Some(wallet_data.address.clone().into_inner()), + slot_index, protocol_parameters.clone(), ) .with_required_inputs(custom_inputs) - .with_forbidden_inputs(forbidden_inputs) - .with_slot_index(slot_index); + .with_forbidden_inputs(forbidden_inputs); if let Some(address) = remainder_address { input_selection = input_selection.with_remainder_address(address); @@ -134,11 +134,11 @@ where available_outputs_signing_data, outputs, Some(wallet_data.address.clone().into_inner()), + slot_index, protocol_parameters.clone(), ) .with_required_inputs(mandatory_inputs) - .with_forbidden_inputs(forbidden_inputs) - .with_slot_index(slot_index); + .with_forbidden_inputs(forbidden_inputs); if let Some(address) = remainder_address { input_selection = input_selection.with_remainder_address(address); @@ -171,10 +171,10 @@ where available_outputs_signing_data, outputs, Some(wallet_data.address.clone().into_inner()), + slot_index, protocol_parameters.clone(), ) - .with_forbidden_inputs(forbidden_inputs) - .with_slot_index(slot_index); + .with_forbidden_inputs(forbidden_inputs); if let Some(address) = remainder_address { input_selection = input_selection.with_remainder_address(address); diff --git a/sdk/tests/client/input_selection/account_outputs.rs b/sdk/tests/client/input_selection/account_outputs.rs index ade83ef47a..a67389ed04 100644 --- a/sdk/tests/client/input_selection/account_outputs.rs +++ b/sdk/tests/client/input_selection/account_outputs.rs @@ -17,7 +17,7 @@ use crate::client::{ build_inputs, build_outputs, is_remainder_or_return, unsorted_eq, Build::{Account, Basic}, ACCOUNT_ID_0, ACCOUNT_ID_1, ACCOUNT_ID_2, BECH32_ADDRESS_ACCOUNT_1, BECH32_ADDRESS_ED25519_0, - BECH32_ADDRESS_ED25519_1, BECH32_ADDRESS_NFT_1, + BECH32_ADDRESS_ED25519_1, BECH32_ADDRESS_NFT_1, SLOT_INDEX, }; #[test] @@ -34,7 +34,7 @@ fn input_account_eq_output_account() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Account( 1_000_000, @@ -49,6 +49,7 @@ fn input_account_eq_output_account() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -72,7 +73,7 @@ fn transition_account_id_zero() { None, None, )], - None, + Some(SLOT_INDEX), ); let account_id = AccountId::from(inputs[0].output_id()); let outputs = build_outputs([Account( @@ -88,6 +89,7 @@ fn transition_account_id_zero() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -128,7 +130,7 @@ fn transition_account_id_zero() { // inputs, // outputs, // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], -// protocol_parameters, +// SLOT_INDEX+1, protocol_parameters, // ) // .select(); @@ -176,7 +178,7 @@ fn transition_account_id_zero() { // inputs, // outputs, // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], -// protocol_parameters, +// SLOT_INDEX+1, protocol_parameters, // ) // .select(); @@ -221,7 +223,7 @@ fn transition_account_id_zero() { // inputs.clone(), // outputs, // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], -// protocol_parameters, +// SLOT_INDEX+1, protocol_parameters, // ) // .select() // .unwrap(); @@ -247,7 +249,7 @@ fn create_account() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Account( 1_000_000, @@ -262,6 +264,7 @@ fn create_account() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -294,7 +297,7 @@ fn burn_account() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 2_000_000, @@ -311,6 +314,7 @@ fn burn_account() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_2)) @@ -353,7 +357,7 @@ fn burn_account() { // inputs, // outputs, // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], -// protocol_parameters, +// SLOT_INDEX+1, protocol_parameters, // ) // .select(); @@ -397,6 +401,7 @@ fn missing_input_for_account_output() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -449,6 +454,7 @@ fn missing_input_for_account_output_2() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -475,7 +481,7 @@ fn missing_input_for_account_output_but_created() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Account( 1_000_000, @@ -490,6 +496,7 @@ fn missing_input_for_account_output_but_created() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -523,7 +530,7 @@ fn account_in_output_and_sender() { None, ), ], - None, + Some(SLOT_INDEX), ); let account_output = AccountOutputBuilder::from(inputs[0].output.as_account()) .finish_output() @@ -544,6 +551,7 @@ fn account_in_output_and_sender() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -582,6 +590,7 @@ fn missing_ed25519_sender() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -623,6 +632,7 @@ fn missing_ed25519_issuer_created() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -647,7 +657,7 @@ fn missing_ed25519_issuer_transition() { Some(Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap()), None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Account( 1_000_000, @@ -662,6 +672,7 @@ fn missing_ed25519_issuer_transition() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -698,6 +709,7 @@ fn missing_account_sender() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -739,6 +751,7 @@ fn missing_account_issuer_created() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -763,7 +776,7 @@ fn missing_account_issuer_transition() { Some(Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap()), None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Account( 1_000_000, @@ -778,6 +791,7 @@ fn missing_account_issuer_transition() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -814,6 +828,7 @@ fn missing_nft_sender() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -855,6 +870,7 @@ fn missing_nft_issuer_created() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -879,7 +895,7 @@ fn missing_nft_issuer_transition() { Some(Address::try_from_bech32(BECH32_ADDRESS_NFT_1).unwrap()), None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Account( 1_000_000, @@ -894,6 +910,7 @@ fn missing_nft_issuer_transition() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -927,7 +944,7 @@ fn increase_account_amount() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Account( 3_000_000, @@ -942,6 +959,7 @@ fn increase_account_amount() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -977,7 +995,7 @@ fn decrease_account_amount() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Account( 1_000_000, @@ -992,6 +1010,7 @@ fn decrease_account_amount() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1039,7 +1058,7 @@ fn prefer_basic_to_account() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -1056,6 +1075,7 @@ fn prefer_basic_to_account() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1092,7 +1112,7 @@ fn take_amount_from_account_to_fund_basic() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_200_000, @@ -1109,6 +1129,7 @@ fn take_amount_from_account_to_fund_basic() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1159,7 +1180,7 @@ fn account_burn_should_validate_account_sender() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 2_000_000, @@ -1176,6 +1197,7 @@ fn account_burn_should_validate_account_sender() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_1)) @@ -1224,7 +1246,7 @@ fn account_burn_should_validate_account_address() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 2_000_000, @@ -1241,6 +1263,7 @@ fn account_burn_should_validate_account_address() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_1)) @@ -1277,7 +1300,7 @@ fn transitioned_zero_account_id_no_longer_is_zero() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -1294,6 +1317,7 @@ fn transitioned_zero_account_id_no_longer_is_zero() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1343,7 +1367,7 @@ fn two_accounts_required() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 3_000_000, @@ -1360,6 +1384,7 @@ fn two_accounts_required() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1368,26 +1393,22 @@ fn two_accounts_required() { assert!(unsorted_eq(&selected.inputs, &inputs)); assert_eq!(selected.outputs.len(), 3); assert!(selected.outputs.contains(&outputs[0])); - assert!( - selected - .outputs - .iter() - .any(|output| if let Output::Account(output) = output { - output.account_id() == &account_id_1 - } else { - false - }) - ); - assert!( - selected - .outputs - .iter() - .any(|output| if let Output::Account(output) = output { - output.account_id() == &account_id_2 - } else { - false - }) - ) + assert!(selected + .outputs + .iter() + .any(|output| if let Output::Account(output) = output { + output.account_id() == &account_id_1 + } else { + false + })); + assert!(selected + .outputs + .iter() + .any(|output| if let Output::Account(output) = output { + output.account_id() == &account_id_2 + } else { + false + })) } #[test] @@ -1404,7 +1425,7 @@ fn state_controller_sender_required() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -1421,6 +1442,7 @@ fn state_controller_sender_required() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1445,7 +1467,7 @@ fn state_controller_sender_required_already_selected() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([ Account( @@ -1472,6 +1494,7 @@ fn state_controller_sender_required_already_selected() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) @@ -1496,7 +1519,7 @@ fn state_transition_and_required() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Account( 2_000_000, @@ -1511,6 +1534,7 @@ fn state_transition_and_required() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) @@ -1535,7 +1559,7 @@ fn remainder_address_in_state_controller() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Account( 1_000_000, @@ -1550,6 +1574,7 @@ fn remainder_address_in_state_controller() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() diff --git a/sdk/tests/client/input_selection/basic_outputs.rs b/sdk/tests/client/input_selection/basic_outputs.rs index f20d862c8b..88b5e2a1f3 100644 --- a/sdk/tests/client/input_selection/basic_outputs.rs +++ b/sdk/tests/client/input_selection/basic_outputs.rs @@ -17,7 +17,7 @@ use crate::client::{ build_inputs, build_outputs, is_remainder_or_return, unsorted_eq, Build::{Account, Basic, Nft}, ACCOUNT_ID_0, ACCOUNT_ID_1, BECH32_ADDRESS_ACCOUNT_1, BECH32_ADDRESS_ED25519_0, BECH32_ADDRESS_ED25519_1, - BECH32_ADDRESS_ED25519_2, BECH32_ADDRESS_NFT_1, BECH32_ADDRESS_REMAINDER, NFT_ID_0, NFT_ID_1, + BECH32_ADDRESS_ED25519_2, BECH32_ADDRESS_NFT_1, BECH32_ADDRESS_REMAINDER, NFT_ID_0, NFT_ID_1, SLOT_INDEX, }; #[test] @@ -52,6 +52,7 @@ fn input_amount_equal_output_amount() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -93,6 +94,7 @@ fn input_amount_lower_than_output_amount() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -150,6 +152,7 @@ fn input_amount_lower_than_output_amount_2() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -195,6 +198,7 @@ fn input_amount_greater_than_output_amount() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -249,6 +253,7 @@ fn input_amount_greater_than_output_amount_with_remainder_address() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .with_remainder_address(remainder_address) @@ -315,6 +320,7 @@ fn two_same_inputs_one_needed() { inputs, outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -381,6 +387,7 @@ fn two_inputs_one_needed() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -434,6 +441,7 @@ fn two_inputs_one_needed_reversed() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -487,6 +495,7 @@ fn two_inputs_both_needed() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -540,6 +549,7 @@ fn two_inputs_remainder() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -590,7 +600,7 @@ fn two_inputs_remainder() { // inputs, // outputs, // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], -// protocol_parameters, +// SLOT_INDEX+1,protocol_parameters, // ) // .select(); @@ -681,6 +691,7 @@ fn ed25519_sender() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), ], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -688,12 +699,10 @@ fn ed25519_sender() { // Sender + another for amount assert_eq!(selected.inputs.len(), 2); - assert!( - selected - .inputs - .iter() - .any(|input| *input.output.as_basic().address() == sender) - ); + assert!(selected + .inputs + .iter() + .any(|input| *input.output.as_basic().address() == sender)); // Provided output + remainder assert_eq!(selected.outputs.len(), 2); } @@ -730,6 +739,7 @@ fn missing_ed25519_sender() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -813,6 +823,7 @@ fn account_sender() { inputs, outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -820,12 +831,10 @@ fn account_sender() { // Sender + another for amount assert_eq!(selected.inputs.len(), 2); - assert!( - selected - .inputs - .iter() - .any(|input| input.output.is_account() && *input.output.as_account().account_id() == account_id_1) - ); + assert!(selected + .inputs + .iter() + .any(|input| input.output.is_account() && *input.output.as_account().account_id() == account_id_1)); // Provided output + account assert_eq!(selected.outputs.len(), 2); assert!(selected.outputs.contains(&outputs[0])); @@ -875,6 +884,7 @@ fn account_sender_zero_id() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -882,12 +892,10 @@ fn account_sender_zero_id() { assert!(unsorted_eq(&selected.inputs, &inputs)); assert_eq!(selected.outputs.len(), 2); - assert!( - selected - .outputs - .iter() - .any(|output| output.is_account() && *output.as_account().account_id() == account_id) - ); + assert!(selected + .outputs + .iter() + .any(|output| output.is_account() && *output.as_account().account_id() == account_id)); } #[test] @@ -922,6 +930,7 @@ fn missing_account_sender() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -1007,6 +1016,7 @@ fn nft_sender() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1014,12 +1024,10 @@ fn nft_sender() { // Sender + another for amount assert_eq!(selected.inputs.len(), 2); - assert!( - selected - .inputs - .iter() - .any(|input| input.output.is_nft() && *input.output.as_nft().nft_id() == nft_id_1) - ); + assert!(selected + .inputs + .iter() + .any(|input| input.output.is_nft() && *input.output.as_nft().nft_id() == nft_id_1)); // Provided output + nft assert_eq!(selected.outputs.len(), 2); assert!(selected.outputs.contains(&inputs[2].output)); @@ -1072,6 +1080,7 @@ fn nft_sender_zero_id() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1079,12 +1088,10 @@ fn nft_sender_zero_id() { assert!(unsorted_eq(&selected.inputs, &inputs)); assert_eq!(selected.outputs.len(), 2); - assert!( - selected - .outputs - .iter() - .any(|output| output.is_nft() && *output.as_nft().nft_id() == nft_id) - ); + assert!(selected + .outputs + .iter() + .any(|output| output.is_nft() && *output.as_nft().nft_id() == nft_id)); } #[test] @@ -1119,6 +1126,7 @@ fn missing_nft_sender() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -1161,6 +1169,7 @@ fn simple_remainder() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1210,7 +1219,7 @@ fn simple_remainder() { // inputs, // outputs, // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], -// protocol_parameters, +// SLOT_INDEX+1,protocol_parameters, // ) // .select(); @@ -1248,7 +1257,7 @@ fn simple_remainder() { // inputs, // outputs, // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], -// protocol_parameters, +// SLOT_INDEX+1,protocol_parameters, // ) // .select(); @@ -1293,6 +1302,7 @@ fn one_provided_one_needed() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1334,6 +1344,7 @@ fn insufficient_amount() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -1391,6 +1402,7 @@ fn two_inputs_remainder_2() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1456,6 +1468,7 @@ fn two_inputs_remainder_3() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1501,7 +1514,7 @@ fn two_inputs_remainder_3() { // inputs.clone(), // outputs.clone(), // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], -// protocol_parameters, +// SLOT_INDEX+1,protocol_parameters, // ) // .select() // .unwrap(); @@ -1551,6 +1564,7 @@ fn sender_already_selected() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), ], + SLOT_INDEX + 1, protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) @@ -1596,6 +1610,7 @@ fn single_mandatory_input() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), ], + SLOT_INDEX + 1, protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) @@ -1642,6 +1657,7 @@ fn too_many_inputs() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -1704,6 +1720,7 @@ fn more_than_max_inputs_only_one_needed() { inputs, outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1750,6 +1767,7 @@ fn too_many_outputs() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -1798,6 +1816,7 @@ fn too_many_outputs_with_remainder() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -1876,6 +1895,7 @@ fn restricted_ed25519() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1924,6 +1944,7 @@ fn restricted_nft() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1970,6 +1991,7 @@ fn restricted_account() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -2059,6 +2081,7 @@ fn restricted_ed25519_sender() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), ], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -2066,12 +2089,10 @@ fn restricted_ed25519_sender() { // Sender + another for amount assert_eq!(selected.inputs.len(), 2); - assert!( - selected - .inputs - .iter() - .any(|input| *input.output.as_basic().address() == sender) - ); + assert!(selected + .inputs + .iter() + .any(|input| *input.output.as_basic().address() == sender)); // Provided output + remainder assert_eq!(selected.outputs.len(), 2); } @@ -2148,6 +2169,7 @@ fn multi_address_sender_already_fulfilled() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), ], + SLOT_INDEX + 1, protocol_parameters, ) .with_required_inputs([*inputs[0].output_id(), *inputs[1].output_id(), *inputs[2].output_id()]) @@ -2212,6 +2234,7 @@ fn ed25519_backed_available_address() { outputs.clone(), // Restricted address is provided, but it can also unlock the ed25519 one [restricted_address], + SLOT_INDEX + 1, protocol_parameters, ) .select() diff --git a/sdk/tests/client/input_selection/expiration.rs b/sdk/tests/client/input_selection/expiration.rs index 8dc60c5696..be25fc3e0f 100644 --- a/sdk/tests/client/input_selection/expiration.rs +++ b/sdk/tests/client/input_selection/expiration.rs @@ -17,7 +17,7 @@ use crate::client::{ build_inputs, build_outputs, is_remainder_or_return, unsorted_eq, Build::{Account, Basic, Nft}, ACCOUNT_ID_1, BECH32_ADDRESS_ACCOUNT_1, BECH32_ADDRESS_ED25519_0, BECH32_ADDRESS_ED25519_1, - BECH32_ADDRESS_ED25519_2, NFT_ID_1, + BECH32_ADDRESS_ED25519_2, NFT_ID_1, SLOT_INDEX, }; #[test] @@ -52,9 +52,9 @@ fn one_output_expiration_not_expired() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .select(); assert!(matches!(selected, Err(Error::NoAvailableInputsProvided))); @@ -92,9 +92,9 @@ fn expiration_equal_timestamp() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(200) .select() .unwrap(); @@ -134,9 +134,9 @@ fn one_output_expiration_expired() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .select() .unwrap(); @@ -188,9 +188,9 @@ fn two_outputs_one_expiration_expired() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .select() .unwrap(); @@ -243,9 +243,9 @@ fn two_outputs_one_unexpired_one_missing() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .select() .unwrap(); @@ -308,9 +308,9 @@ fn two_outputs_two_expired() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(200) .select() .unwrap(); @@ -366,9 +366,9 @@ fn two_outputs_two_expired_2() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), ], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(200) .select() .unwrap(); @@ -408,9 +408,9 @@ fn expiration_expired_with_sdr() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .select() .unwrap(); @@ -450,9 +450,9 @@ fn expiration_expired_with_sdr_2() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .select() .unwrap(); @@ -492,9 +492,9 @@ fn expiration_expired_with_sdr_and_timelock() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .select() .unwrap(); @@ -534,9 +534,9 @@ fn expiration_expired_with_sdr_and_timelock_2() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .select() .unwrap(); @@ -621,9 +621,9 @@ fn sender_in_expiration() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), ], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .select() .unwrap(); @@ -667,9 +667,9 @@ fn sender_in_expiration_already_selected() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), ], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .with_required_inputs([*inputs[0].output_id()]) .select() .unwrap(); @@ -713,9 +713,9 @@ fn remainder_in_expiration() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), ], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .select() .unwrap(); @@ -766,9 +766,9 @@ fn expiration_expired_non_ed25519_in_address_unlock_condition() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .select() .unwrap(); @@ -820,9 +820,9 @@ fn expiration_expired_only_account_addresses() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .select() .unwrap(); @@ -863,9 +863,9 @@ fn one_nft_output_expiration_unexpired() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .select() .unwrap(); @@ -906,9 +906,9 @@ fn one_nft_output_expiration_expired() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .select() .unwrap(); diff --git a/sdk/tests/client/input_selection/foundry_outputs.rs b/sdk/tests/client/input_selection/foundry_outputs.rs index bf8fe83707..f7e869dcb6 100644 --- a/sdk/tests/client/input_selection/foundry_outputs.rs +++ b/sdk/tests/client/input_selection/foundry_outputs.rs @@ -23,7 +23,7 @@ use pretty_assertions::assert_eq; use crate::client::{ build_inputs, build_outputs, is_remainder_or_return, unsorted_eq, Build::{Account, Basic, Foundry}, - ACCOUNT_ID_1, ACCOUNT_ID_2, BECH32_ADDRESS_ED25519_0, + ACCOUNT_ID_1, ACCOUNT_ID_2, BECH32_ADDRESS_ED25519_0, SLOT_INDEX, }; #[test] @@ -56,6 +56,7 @@ fn missing_input_account_for_foundry() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -144,6 +145,7 @@ fn minted_native_tokens_in_new_remainder() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -215,6 +217,7 @@ fn minted_native_tokens_in_provided_output() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -282,6 +285,7 @@ fn melt_native_tokens() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -335,6 +339,7 @@ fn destroy_foundry_with_account_state_transition() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .with_burn(Burn::new().add_foundry(inputs[1].output.as_foundry().id())) @@ -386,6 +391,7 @@ fn destroy_foundry_with_account_burn() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .with_burn( @@ -461,6 +467,7 @@ fn prefer_basic_to_foundry() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -523,6 +530,7 @@ fn simple_foundry_transition_basic_not_needed() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -600,6 +608,7 @@ fn simple_foundry_transition_basic_not_needed_with_remainder() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -745,6 +754,7 @@ fn mint_and_burn_at_the_same_time() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .with_burn(Burn::new().add_native_token(token_id, 10)) @@ -812,6 +822,7 @@ fn take_amount_from_account_and_foundry_to_fund_basic() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -867,6 +878,7 @@ fn create_native_token_but_burn_account() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_1)) @@ -928,6 +940,7 @@ fn melted_tokens_not_provided() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -980,6 +993,7 @@ fn burned_tokens_not_provided() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .with_burn(Burn::new().add_native_token(token_id_1, 100)) @@ -1033,6 +1047,7 @@ fn foundry_in_outputs_and_required() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .with_required_inputs([*inputs[1].output_id()]) @@ -1103,6 +1118,7 @@ fn melt_and_burn_native_tokens() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) // Burn 456 native tokens diff --git a/sdk/tests/client/input_selection/nft_outputs.rs b/sdk/tests/client/input_selection/nft_outputs.rs index ad3d40db1e..d4aaf1c4c9 100644 --- a/sdk/tests/client/input_selection/nft_outputs.rs +++ b/sdk/tests/client/input_selection/nft_outputs.rs @@ -21,7 +21,7 @@ use crate::client::{ build_inputs, build_outputs, is_remainder_or_return, unsorted_eq, Build::{Basic, Nft}, BECH32_ADDRESS_ACCOUNT_1, BECH32_ADDRESS_ED25519_0, BECH32_ADDRESS_ED25519_1, BECH32_ADDRESS_NFT_1, NFT_ID_0, - NFT_ID_1, NFT_ID_2, + NFT_ID_1, NFT_ID_2, SLOT_INDEX, }; #[test] @@ -57,6 +57,7 @@ fn input_nft_eq_output_nft() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -100,6 +101,7 @@ fn transition_nft_id_zero() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -230,6 +232,7 @@ fn mint_nft() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -281,6 +284,7 @@ fn burn_nft() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id_2)) @@ -369,6 +373,7 @@ fn missing_input_for_nft_output() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -412,6 +417,7 @@ fn missing_input_for_nft_output_but_created() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -476,6 +482,7 @@ fn nft_in_output_and_sender() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -526,6 +533,7 @@ fn missing_ed25519_sender() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -569,6 +577,7 @@ fn missing_ed25519_issuer_created() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -612,6 +621,7 @@ fn missing_ed25519_issuer_transition() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -652,6 +662,7 @@ fn missing_account_sender() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -695,6 +706,7 @@ fn missing_account_issuer_created() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -738,6 +750,7 @@ fn missing_account_issuer_transition() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -778,6 +791,7 @@ fn missing_nft_sender() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -821,6 +835,7 @@ fn missing_nft_issuer_created() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -864,6 +879,7 @@ fn missing_nft_issuer_transition() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -916,6 +932,7 @@ fn increase_nft_amount() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -970,6 +987,7 @@ fn decrease_nft_amount() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1036,6 +1054,7 @@ fn prefer_basic_to_nft() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1091,6 +1110,7 @@ fn take_amount_from_nft_to_fund_basic() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1158,6 +1178,7 @@ fn nft_burn_should_validate_nft_sender() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id_1)) @@ -1213,6 +1234,7 @@ fn nft_burn_should_validate_nft_address() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id_1)) @@ -1256,6 +1278,7 @@ fn transitioned_zero_nft_id_no_longer_is_zero() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -1332,6 +1355,7 @@ fn changed_immutable_metadata() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); diff --git a/sdk/tests/client/input_selection/outputs.rs b/sdk/tests/client/input_selection/outputs.rs index 98551690e9..81a9ae7f9b 100644 --- a/sdk/tests/client/input_selection/outputs.rs +++ b/sdk/tests/client/input_selection/outputs.rs @@ -12,7 +12,7 @@ use pretty_assertions::assert_eq; use crate::client::{ build_inputs, build_outputs, is_remainder_or_return, unsorted_eq, Build::{Account, Basic}, - ACCOUNT_ID_2, BECH32_ADDRESS_ED25519_0, BECH32_ADDRESS_ED25519_1, + ACCOUNT_ID_2, BECH32_ADDRESS_ED25519_0, BECH32_ADDRESS_ED25519_1, SLOT_INDEX, }; #[test] @@ -35,6 +35,7 @@ fn no_inputs() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -65,6 +66,7 @@ fn no_outputs() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -94,6 +96,7 @@ fn no_outputs_but_burn() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_2)) @@ -138,7 +141,7 @@ fn no_address_provided() { None, )]); - let selected = InputSelection::new(inputs, outputs, [], protocol_parameters).select(); + let selected = InputSelection::new(inputs, outputs, [], SLOT_INDEX + 1, protocol_parameters).select(); assert!(matches!(selected, Err(Error::NoAvailableInputsProvided))); } @@ -175,6 +178,7 @@ fn no_matching_address_provided() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -226,6 +230,7 @@ fn two_addresses_one_missing() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -286,6 +291,7 @@ fn two_addresses() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), ], + SLOT_INDEX + 1, protocol_parameters, ) .select() diff --git a/sdk/tests/client/input_selection/storage_deposit_return.rs b/sdk/tests/client/input_selection/storage_deposit_return.rs index 1ccec61b40..3cdd8bdc9e 100644 --- a/sdk/tests/client/input_selection/storage_deposit_return.rs +++ b/sdk/tests/client/input_selection/storage_deposit_return.rs @@ -13,7 +13,7 @@ use crate::client::{ build_inputs, build_outputs, is_remainder_or_return, unsorted_eq, Build::{Account, Basic}, ACCOUNT_ID_1, BECH32_ADDRESS_ACCOUNT_1, BECH32_ADDRESS_ED25519_0, BECH32_ADDRESS_ED25519_1, - BECH32_ADDRESS_ED25519_2, + BECH32_ADDRESS_ED25519_2, SLOT_INDEX, }; #[test] @@ -48,6 +48,7 @@ fn sdruc_output_not_provided_no_remainder() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -112,6 +113,7 @@ fn sdruc_output_provided_no_remainder() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -153,6 +155,7 @@ fn sdruc_output_provided_remainder() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -217,6 +220,7 @@ fn two_sdrucs_to_the_same_address_both_needed() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -281,6 +285,7 @@ fn two_sdrucs_to_the_same_address_one_needed() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -346,6 +351,7 @@ fn two_sdrucs_to_different_addresses_both_needed() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -416,6 +422,7 @@ fn two_sdrucs_to_different_addresses_one_needed() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -469,6 +476,7 @@ fn insufficient_amount_because_of_sdruc() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select(); @@ -529,6 +537,7 @@ fn useless_sdruc_required_for_sender_feature() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), ], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -592,6 +601,7 @@ fn sdruc_required_non_ed25519_in_address_unlock() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() @@ -665,6 +675,7 @@ fn useless_sdruc_non_ed25519_in_address_unlock() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) .select() diff --git a/sdk/tests/client/input_selection/timelock.rs b/sdk/tests/client/input_selection/timelock.rs index d5a100cf6d..907d9c4c93 100644 --- a/sdk/tests/client/input_selection/timelock.rs +++ b/sdk/tests/client/input_selection/timelock.rs @@ -9,6 +9,7 @@ use pretty_assertions::assert_eq; use crate::client::{ build_inputs, build_outputs, unsorted_eq, Build::Basic, BECH32_ADDRESS_ED25519_0, BECH32_ADDRESS_ED25519_1, + SLOT_INDEX, }; #[test] @@ -43,9 +44,9 @@ fn one_output_timelock_not_expired() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .select(); assert!(matches!(selected, Err(Error::NoAvailableInputsProvided))); @@ -83,9 +84,9 @@ fn timelock_equal_timestamp() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(200) .select() .unwrap(); @@ -137,9 +138,9 @@ fn two_outputs_one_timelock_expired() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .select() .unwrap(); @@ -192,9 +193,9 @@ fn two_outputs_one_timelocked_one_missing() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .select() .unwrap(); @@ -235,9 +236,9 @@ fn one_output_timelock_expired() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX + 1, protocol_parameters, ) - .with_slot_index(100) .select() .unwrap(); diff --git a/sdk/tests/client/mod.rs b/sdk/tests/client/mod.rs index e65ca490d2..db6209fcbb 100644 --- a/sdk/tests/client/mod.rs +++ b/sdk/tests/client/mod.rs @@ -57,6 +57,7 @@ const BECH32_ADDRESS_ACCOUNT_1: &str = "rms1pqg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3 const BECH32_ADDRESS_ACCOUNT_2: &str = "rms1pq3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zymxrh9z"; // Corresponds to ACCOUNT_ID_2 const BECH32_ADDRESS_NFT_1: &str = "rms1zqg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zxddmy7"; // Corresponds to NFT_ID_1 const _BECH32_ADDRESS_NFT_2: &str = "rms1zq3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zynm6ctf"; // Corresponds to NFT_ID_2 +const SLOT_INDEX: SlotIndex = SlotIndex(10); #[derive(Debug, Clone)] enum Build<'a> { diff --git a/sdk/tests/client/signing/mod.rs b/sdk/tests/client/signing/mod.rs index dc38b1fd3d..761f7ff555 100644 --- a/sdk/tests/client/signing/mod.rs +++ b/sdk/tests/client/signing/mod.rs @@ -210,9 +210,9 @@ async fn all_combined() -> Result<()> { inputs.clone(), outputs.clone(), [ed25519_0, ed25519_1, ed25519_2], + slot_index, protocol_parameters.clone(), ) - .with_slot_index(slot_index) .select() .unwrap(); From 76dade34ce895f1c8e3ab5e8ce8aa79adeaddea4 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Fri, 12 Jan 2024 12:50:18 +0100 Subject: [PATCH 14/45] More fixes --- .../client/input_selection/account_outputs.rs | 36 ++--- .../client/input_selection/basic_outputs.rs | 128 ++++++++++-------- .../client/input_selection/foundry_outputs.rs | 32 ++--- .../client/input_selection/nft_outputs.rs | 32 ++--- .../input_selection/storage_deposit_return.rs | 8 +- 5 files changed, 126 insertions(+), 110 deletions(-) diff --git a/sdk/tests/client/input_selection/account_outputs.rs b/sdk/tests/client/input_selection/account_outputs.rs index a67389ed04..f83da7e778 100644 --- a/sdk/tests/client/input_selection/account_outputs.rs +++ b/sdk/tests/client/input_selection/account_outputs.rs @@ -1393,22 +1393,26 @@ fn two_accounts_required() { assert!(unsorted_eq(&selected.inputs, &inputs)); assert_eq!(selected.outputs.len(), 3); assert!(selected.outputs.contains(&outputs[0])); - assert!(selected - .outputs - .iter() - .any(|output| if let Output::Account(output) = output { - output.account_id() == &account_id_1 - } else { - false - })); - assert!(selected - .outputs - .iter() - .any(|output| if let Output::Account(output) = output { - output.account_id() == &account_id_2 - } else { - false - })) + assert!( + selected + .outputs + .iter() + .any(|output| if let Output::Account(output) = output { + output.account_id() == &account_id_1 + } else { + false + }) + ); + assert!( + selected + .outputs + .iter() + .any(|output| if let Output::Account(output) = output { + output.account_id() == &account_id_2 + } else { + false + }) + ) } #[test] diff --git a/sdk/tests/client/input_selection/basic_outputs.rs b/sdk/tests/client/input_selection/basic_outputs.rs index 88b5e2a1f3..666316c094 100644 --- a/sdk/tests/client/input_selection/basic_outputs.rs +++ b/sdk/tests/client/input_selection/basic_outputs.rs @@ -35,7 +35,7 @@ fn input_amount_equal_output_amount() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -77,7 +77,7 @@ fn input_amount_lower_than_output_amount() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 2_000_000, @@ -135,7 +135,7 @@ fn input_amount_lower_than_output_amount_2() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 3_500_000, @@ -181,7 +181,7 @@ fn input_amount_greater_than_output_amount() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 500_000, @@ -236,7 +236,7 @@ fn input_amount_greater_than_output_amount_with_remainder_address() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 500_000, @@ -303,7 +303,7 @@ fn two_same_inputs_one_needed() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 500_000, @@ -370,7 +370,7 @@ fn two_inputs_one_needed() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -424,7 +424,7 @@ fn two_inputs_one_needed_reversed() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -478,7 +478,7 @@ fn two_inputs_both_needed() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 3_000_000, @@ -532,7 +532,7 @@ fn two_inputs_remainder() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 2_500_000, @@ -671,7 +671,7 @@ fn ed25519_sender() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 2_000_000, @@ -699,10 +699,12 @@ fn ed25519_sender() { // Sender + another for amount assert_eq!(selected.inputs.len(), 2); - assert!(selected - .inputs - .iter() - .any(|input| *input.output.as_basic().address() == sender)); + assert!( + selected + .inputs + .iter() + .any(|input| *input.output.as_basic().address() == sender) + ); // Provided output + remainder assert_eq!(selected.outputs.len(), 2); } @@ -722,7 +724,7 @@ fn missing_ed25519_sender() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -806,7 +808,7 @@ fn account_sender() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 2_000_000, @@ -831,10 +833,12 @@ fn account_sender() { // Sender + another for amount assert_eq!(selected.inputs.len(), 2); - assert!(selected - .inputs - .iter() - .any(|input| input.output.is_account() && *input.output.as_account().account_id() == account_id_1)); + assert!( + selected + .inputs + .iter() + .any(|input| input.output.is_account() && *input.output.as_account().account_id() == account_id_1) + ); // Provided output + account assert_eq!(selected.outputs.len(), 2); assert!(selected.outputs.contains(&outputs[0])); @@ -866,7 +870,7 @@ fn account_sender_zero_id() { None, ), ], - None, + Some(SLOT_INDEX), ); let account_id = AccountId::from(inputs[1].output_id()); let outputs = build_outputs([Basic( @@ -892,10 +896,12 @@ fn account_sender_zero_id() { assert!(unsorted_eq(&selected.inputs, &inputs)); assert_eq!(selected.outputs.len(), 2); - assert!(selected - .outputs - .iter() - .any(|output| output.is_account() && *output.as_account().account_id() == account_id)); + assert!( + selected + .outputs + .iter() + .any(|output| output.is_account() && *output.as_account().account_id() == account_id) + ); } #[test] @@ -913,7 +919,7 @@ fn missing_account_sender() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -999,7 +1005,7 @@ fn nft_sender() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 2_000_000, @@ -1024,10 +1030,12 @@ fn nft_sender() { // Sender + another for amount assert_eq!(selected.inputs.len(), 2); - assert!(selected - .inputs - .iter() - .any(|input| input.output.is_nft() && *input.output.as_nft().nft_id() == nft_id_1)); + assert!( + selected + .inputs + .iter() + .any(|input| input.output.is_nft() && *input.output.as_nft().nft_id() == nft_id_1) + ); // Provided output + nft assert_eq!(selected.outputs.len(), 2); assert!(selected.outputs.contains(&inputs[2].output)); @@ -1062,7 +1070,7 @@ fn nft_sender_zero_id() { None, ), ], - None, + Some(SLOT_INDEX), ); let nft_id = NftId::from(inputs[1].output_id()); let outputs = build_outputs([Basic( @@ -1088,10 +1096,12 @@ fn nft_sender_zero_id() { assert!(unsorted_eq(&selected.inputs, &inputs)); assert_eq!(selected.outputs.len(), 2); - assert!(selected - .outputs - .iter() - .any(|output| output.is_nft() && *output.as_nft().nft_id() == nft_id)); + assert!( + selected + .outputs + .iter() + .any(|output| output.is_nft() && *output.as_nft().nft_id() == nft_id) + ); } #[test] @@ -1109,7 +1119,7 @@ fn missing_nft_sender() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -1152,7 +1162,7 @@ fn simple_remainder() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 500_000, @@ -1285,7 +1295,7 @@ fn one_provided_one_needed() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -1327,7 +1337,7 @@ fn insufficient_amount() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_250_000, @@ -1385,7 +1395,7 @@ fn two_inputs_remainder_2() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 500_000, @@ -1451,7 +1461,7 @@ fn two_inputs_remainder_3() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_750_000, @@ -1544,7 +1554,7 @@ fn sender_already_selected() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -1590,7 +1600,7 @@ fn single_mandatory_input() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -1701,7 +1711,7 @@ fn more_than_max_inputs_only_one_needed() { None, None, )], - None, + Some(SLOT_INDEX), ); inputs.push(needed_input[0].clone()); @@ -1745,7 +1755,7 @@ fn too_many_outputs() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs( std::iter::repeat_with(|| { @@ -1793,7 +1803,7 @@ fn too_many_outputs_with_remainder() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs( @@ -1878,7 +1888,7 @@ fn restricted_ed25519() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -1927,7 +1937,7 @@ fn restricted_nft() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 3_000_000, @@ -1974,7 +1984,7 @@ fn restricted_account() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 3_000_000, @@ -2061,7 +2071,7 @@ fn restricted_ed25519_sender() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 2_000_000, @@ -2089,10 +2099,12 @@ fn restricted_ed25519_sender() { // Sender + another for amount assert_eq!(selected.inputs.len(), 2); - assert!(selected - .inputs - .iter() - .any(|input| *input.output.as_basic().address() == sender)); + assert!( + selected + .inputs + .iter() + .any(|input| *input.output.as_basic().address() == sender) + ); // Provided output + remainder assert_eq!(selected.outputs.len(), 2); } @@ -2148,7 +2160,7 @@ fn multi_address_sender_already_fulfilled() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 3_000_000, @@ -2204,7 +2216,7 @@ fn ed25519_backed_available_address() { ), Basic(1_000_000, ed25519.clone(), None, None, None, None, None, None), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([ Basic( diff --git a/sdk/tests/client/input_selection/foundry_outputs.rs b/sdk/tests/client/input_selection/foundry_outputs.rs index f7e869dcb6..a3e62ec19f 100644 --- a/sdk/tests/client/input_selection/foundry_outputs.rs +++ b/sdk/tests/client/input_selection/foundry_outputs.rs @@ -42,7 +42,7 @@ fn missing_input_account_for_foundry() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Foundry( 1_000_000, @@ -131,7 +131,7 @@ fn minted_native_tokens_in_new_remainder() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Foundry( 1_000_000, @@ -191,7 +191,7 @@ fn minted_native_tokens_in_provided_output() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([ Foundry( @@ -258,7 +258,7 @@ fn melt_native_tokens() { )), ), ], - None, + Some(SLOT_INDEX), ); let account_output = AccountOutputBuilder::new_with_amount(1_000_000, account_id_1) .add_unlock_condition(AddressUnlockCondition::new( @@ -326,7 +326,7 @@ fn destroy_foundry_with_account_state_transition() { None, ), ], - None, + Some(SLOT_INDEX), ); let account_output = AccountOutputBuilder::from(inputs[0].output.as_account()) .with_amount(103_100) @@ -374,7 +374,7 @@ fn destroy_foundry_with_account_burn() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -450,7 +450,7 @@ fn prefer_basic_to_foundry() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -503,7 +503,7 @@ fn simple_foundry_transition_basic_not_needed() { None, ), ], - None, + Some(SLOT_INDEX), ); let account_output = AccountOutputBuilder::new_with_amount(2_000_000, account_id_1) .add_unlock_condition(AddressUnlockCondition::new( @@ -582,7 +582,7 @@ fn simple_foundry_transition_basic_not_needed_with_remainder() { None, ), ], - None, + Some(SLOT_INDEX), ); let account_output = AccountOutputBuilder::new_with_amount(2_000_000, account_id_1) .add_unlock_condition(AddressUnlockCondition::new( @@ -727,7 +727,7 @@ fn mint_and_burn_at_the_same_time() { SimpleTokenScheme::new(100, 0, 200).unwrap(), Some((&token_id.to_string(), 100)), )], - None, + Some(SLOT_INDEX), ); let account_output = AccountOutputBuilder::new_with_amount(2_000_000, account_id_1) .add_unlock_condition(AddressUnlockCondition::new( @@ -793,7 +793,7 @@ fn take_amount_from_account_and_foundry_to_fund_basic() { Some((&token_id.to_string(), 100)), ), ], - None, + Some(SLOT_INDEX), ); let account_output = AccountOutputBuilder::new_with_amount(2_000_000, account_id_1) .add_unlock_condition(AddressUnlockCondition::new( @@ -864,7 +864,7 @@ fn create_native_token_but_burn_account() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Foundry( 1_000_000, @@ -926,7 +926,7 @@ fn melted_tokens_not_provided() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Foundry( 1_000_000, @@ -979,7 +979,7 @@ fn burned_tokens_not_provided() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Foundry( 1_000_000, @@ -1021,7 +1021,7 @@ fn foundry_in_outputs_and_required() { SimpleTokenScheme::new(0, 0, 10).unwrap(), None, )], - None, + Some(SLOT_INDEX), ); let account_output = AccountOutputBuilder::new_with_amount(1_251_500, account_id_2) .add_unlock_condition(AddressUnlockCondition::new( @@ -1091,7 +1091,7 @@ fn melt_and_burn_native_tokens() { Some((&token_id.to_string(), 1000)), ), ], - None, + Some(SLOT_INDEX), ); let account_output = AccountOutputBuilder::new_with_amount(1_000_000, account_id) .add_unlock_condition(AddressUnlockCondition::new( diff --git a/sdk/tests/client/input_selection/nft_outputs.rs b/sdk/tests/client/input_selection/nft_outputs.rs index d4aaf1c4c9..c5c72a4a1a 100644 --- a/sdk/tests/client/input_selection/nft_outputs.rs +++ b/sdk/tests/client/input_selection/nft_outputs.rs @@ -40,7 +40,7 @@ fn input_nft_eq_output_nft() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Nft( 1_000_000, @@ -83,7 +83,7 @@ fn transition_nft_id_zero() { None, None, )], - None, + Some(SLOT_INDEX), ); let nft_id = NftId::from(inputs[0].output_id()); let outputs = build_outputs([Nft( @@ -215,7 +215,7 @@ fn mint_nft() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Nft( 1_000_000, @@ -267,7 +267,7 @@ fn burn_nft() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 2_000_000, @@ -356,7 +356,7 @@ fn missing_input_for_nft_output() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Nft( 1_000_000, @@ -400,7 +400,7 @@ fn missing_input_for_nft_output_but_created() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Nft( 1_000_000, @@ -516,7 +516,7 @@ fn missing_ed25519_sender() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Nft( 1_000_000, @@ -560,7 +560,7 @@ fn missing_ed25519_issuer_created() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Nft( 1_000_000, @@ -604,7 +604,7 @@ fn missing_ed25519_issuer_transition() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Nft( 1_000_000, @@ -645,7 +645,7 @@ fn missing_account_sender() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Nft( 1_000_000, @@ -689,7 +689,7 @@ fn missing_account_issuer_created() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Nft( 1_000_000, @@ -733,7 +733,7 @@ fn missing_account_issuer_transition() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Nft( 1_000_000, @@ -774,7 +774,7 @@ fn missing_nft_sender() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Nft( 1_000_000, @@ -818,7 +818,7 @@ fn missing_nft_issuer_created() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Nft( 1_000_000, @@ -862,7 +862,7 @@ fn missing_nft_issuer_transition() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Nft( 1_000_000, @@ -1261,7 +1261,7 @@ fn transitioned_zero_nft_id_no_longer_is_zero() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, diff --git a/sdk/tests/client/input_selection/storage_deposit_return.rs b/sdk/tests/client/input_selection/storage_deposit_return.rs index 3cdd8bdc9e..3f47afb6b5 100644 --- a/sdk/tests/client/input_selection/storage_deposit_return.rs +++ b/sdk/tests/client/input_selection/storage_deposit_return.rs @@ -31,7 +31,7 @@ fn sdruc_output_not_provided_no_remainder() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -84,7 +84,7 @@ fn sdruc_output_provided_no_remainder() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([ Basic( @@ -138,7 +138,7 @@ fn sdruc_output_provided_remainder() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -459,7 +459,7 @@ fn insufficient_amount_because_of_sdruc() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 2_000_000, From 877996fcfeb5b62beb05fc50f545b48f8521b153 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Fri, 12 Jan 2024 14:52:05 +0100 Subject: [PATCH 15/45] Put mana remainder to automatically transitioned chain if possible --- cli/src/cli.rs | 2 +- .../input_selection/remainder.rs | 44 ++++++++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index f074dd77eb..44e1cbacad 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -64,7 +64,7 @@ pub struct InitParameters { #[arg(short, long, value_name = "URL", env = "NODE_URL", default_value = DEFAULT_NODE_URL)] pub node_url: String, /// Set the BIP path, `4219/0/0/0` if not provided. - #[arg(short, long, value_parser = parse_bip_path)] + #[arg(short, long, value_parser = parse_bip_path, default_value = "4219/0/0/0")] pub bip_path: Option, /// Set the Bech32-encoded wallet address. #[arg(short, long)] diff --git a/sdk/src/client/api/block_builder/input_selection/remainder.rs b/sdk/src/client/api/block_builder/input_selection/remainder.rs index 1dcf2cd337..195aba3160 100644 --- a/sdk/src/client/api/block_builder/input_selection/remainder.rs +++ b/sdk/src/client/api/block_builder/input_selection/remainder.rs @@ -15,8 +15,8 @@ use crate::{ types::block::{ address::{Address, Ed25519Address}, output::{ - unlock_condition::AddressUnlockCondition, BasicOutputBuilder, MinimumOutputAmount, NativeTokensBuilder, - Output, + unlock_condition::AddressUnlockCondition, AccountOutputBuilder, BasicOutputBuilder, FoundryOutputBuilder, + MinimumOutputAmount, NativeTokensBuilder, NftOutputBuilder, Output, }, }, }; @@ -84,7 +84,7 @@ impl InputSelection { } pub(crate) fn remainder_and_storage_deposit_return_outputs( - &self, + &mut self, ) -> Result<(Option, Vec), Error> { let (inputs_sum, outputs_sum, inputs_sdr, outputs_sdr) = amount_sums(&self.selected_inputs, &self.outputs, self.slot_index); @@ -152,7 +152,7 @@ impl InputSelection { // TODO rewards } - let output_mana = self.outputs.iter().map(|o| o.mana()).sum::(); + let output_mana = self.outputs.iter().map(|o| o.mana()).sum::() + self.mana_allotments; // TODO allotment println!("ISA input_mana {input_mana}, output_mana {output_mana}"); @@ -162,12 +162,42 @@ impl InputSelection { return Ok((None, storage_deposit_returns)); } + // TODO underflows? + let amount_diff = inputs_sum - outputs_sum; + let mana_diff = input_mana - output_mana; + + if inputs_sum == outputs_sum && input_mana != output_mana && native_tokens_diff.is_none() { + let output = self + .outputs + .iter_mut() + .filter(|output| { + output + .chain_id() + .as_ref() + .map(|chain_id| self.automatically_transitioned.contains(chain_id)) + .unwrap_or(false) + }) + .next(); + if let Some(output) = output { + *output = match output { + Output::Account(output) => AccountOutputBuilder::from(&*output) + .with_mana(output.mana() + mana_diff) + .finish_output()?, + Output::Foundry(_) => panic!(), + Output::Nft(output) => NftOutputBuilder::from(&*output) + .with_mana(output.mana() + mana_diff) + .finish_output()?, + _ => panic!("only account, nft and foundry can be automatically created"), + }; + } + + return Ok((None, storage_deposit_returns)); + } + let Some((remainder_address, chain)) = self.get_remainder_address()? else { return Err(Error::MissingInputWithEd25519Address); }; - let amount_diff = inputs_sum - outputs_sum; - let mana_diff = input_mana - output_mana; let mut remainder_builder = BasicOutputBuilder::new_with_amount(amount_diff).with_mana(mana_diff); remainder_builder = @@ -183,6 +213,8 @@ impl InputSelection { println!("remainder {remainder:?}"); + println!("{:?}", self); + // TODO add log log::debug!("Created remainder output of {amount_diff} for {remainder_address:?}"); From 7d65eac205d73b0bbb94ce2eb6439b29a6021695 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Fri, 12 Jan 2024 16:31:33 +0100 Subject: [PATCH 16/45] Fix expiration tests --- .../client/input_selection/expiration.rs | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/sdk/tests/client/input_selection/expiration.rs b/sdk/tests/client/input_selection/expiration.rs index be25fc3e0f..0ec08d4bd3 100644 --- a/sdk/tests/client/input_selection/expiration.rs +++ b/sdk/tests/client/input_selection/expiration.rs @@ -9,6 +9,7 @@ use iota_sdk::{ address::Address, output::{AccountId, NftId}, protocol::protocol_parameters, + slot::SlotIndex, }, }; use pretty_assertions::assert_eq; @@ -35,7 +36,7 @@ fn one_output_expiration_not_expired() { Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 200)), None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 2_000_000, @@ -75,7 +76,7 @@ fn expiration_equal_timestamp() { Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 200)), None, )], - None, + Some(SlotIndex::from(200)), ); let outputs = build_outputs([Basic( 2_000_000, @@ -92,7 +93,7 @@ fn expiration_equal_timestamp() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + 200, protocol_parameters, ) .select() @@ -117,7 +118,7 @@ fn one_output_expiration_expired() { Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), None, )], - None, + Some(SlotIndex::from(100)), ); let outputs = build_outputs([Basic( 2_000_000, @@ -134,7 +135,7 @@ fn one_output_expiration_expired() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + 100, protocol_parameters, ) .select() @@ -171,7 +172,7 @@ fn two_outputs_one_expiration_expired() { None, ), ], - None, + Some(SlotIndex::from(100)), ); let outputs = build_outputs([Basic( 2_000_000, @@ -188,7 +189,7 @@ fn two_outputs_one_expiration_expired() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + 100, protocol_parameters, ) .select() @@ -226,7 +227,7 @@ fn two_outputs_one_unexpired_one_missing() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 2_000_000, @@ -291,7 +292,7 @@ fn two_outputs_two_expired() { None, ), ], - None, + Some(SlotIndex::from(200)), ); let outputs = build_outputs([Basic( 2_000_000, @@ -308,7 +309,7 @@ fn two_outputs_two_expired() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap()], - SLOT_INDEX + 1, + 200, protocol_parameters, ) .select() @@ -346,7 +347,7 @@ fn two_outputs_two_expired_2() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 4_000_000, @@ -391,7 +392,7 @@ fn expiration_expired_with_sdr() { Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), None, )], - None, + Some(SlotIndex::from(100)), ); let outputs = build_outputs([Basic( 2_000_000, @@ -408,7 +409,7 @@ fn expiration_expired_with_sdr() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + 100, protocol_parameters, ) .select() @@ -433,7 +434,7 @@ fn expiration_expired_with_sdr_2() { Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), None, )], - None, + Some(SlotIndex::from(100)), ); let outputs = build_outputs([Basic( 2_000_000, @@ -450,7 +451,7 @@ fn expiration_expired_with_sdr_2() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + 100, protocol_parameters, ) .select() @@ -475,7 +476,7 @@ fn expiration_expired_with_sdr_and_timelock() { Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), None, )], - None, + Some(SlotIndex::from(100)), ); let outputs = build_outputs([Basic( 2_000_000, @@ -492,7 +493,7 @@ fn expiration_expired_with_sdr_and_timelock() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + 100, protocol_parameters, ) .select() @@ -517,7 +518,7 @@ fn expiration_expired_with_sdr_and_timelock_2() { Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), None, )], - None, + Some(SlotIndex::from(100)), ); let outputs = build_outputs([Basic( 2_000_000, @@ -534,7 +535,7 @@ fn expiration_expired_with_sdr_and_timelock_2() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + 100, protocol_parameters, ) .select() @@ -601,7 +602,7 @@ fn sender_in_expiration() { None, ), ], - None, + Some(SlotIndex::from(100)), ); let outputs = build_outputs([Basic( 1_000_000, @@ -621,7 +622,7 @@ fn sender_in_expiration() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), ], - SLOT_INDEX + 1, + 100, protocol_parameters, ) .select() @@ -647,7 +648,7 @@ fn sender_in_expiration_already_selected() { Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 50)), None, )], - None, + Some(SlotIndex::from(100)), ); let outputs = build_outputs([Basic( 1_000_000, @@ -667,7 +668,7 @@ fn sender_in_expiration_already_selected() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), ], - SLOT_INDEX + 1, + 100, protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) @@ -693,7 +694,7 @@ fn remainder_in_expiration() { Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), 50)), None, )], - None, + Some(SlotIndex::from(100)), ); let outputs = build_outputs([Basic( 1_000_000, @@ -713,7 +714,7 @@ fn remainder_in_expiration() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), ], - SLOT_INDEX + 1, + 100, protocol_parameters, ) .select() @@ -749,7 +750,7 @@ fn expiration_expired_non_ed25519_in_address_unlock_condition() { Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), None, )], - None, + Some(SlotIndex::from(100)), ); let outputs = build_outputs([Basic( 2_000_000, @@ -766,7 +767,7 @@ fn expiration_expired_non_ed25519_in_address_unlock_condition() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + 100, protocol_parameters, ) .select() @@ -802,7 +803,7 @@ fn expiration_expired_only_account_addresses() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( @@ -846,7 +847,7 @@ fn one_nft_output_expiration_unexpired() { Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 150)), None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Nft( 2_000_000, @@ -889,7 +890,7 @@ fn one_nft_output_expiration_expired() { Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 50)), None, )], - None, + Some(SlotIndex::from(100)), ); let outputs = build_outputs([Nft( 2_000_000, @@ -906,7 +907,7 @@ fn one_nft_output_expiration_expired() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + 100, protocol_parameters, ) .select() From f9d455ae461973a9af22373af7a601ee0c156a2a Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Fri, 12 Jan 2024 16:42:33 +0100 Subject: [PATCH 17/45] No need for +1 --- .../client/input_selection/account_outputs.rs | 58 +++++++-------- .../client/input_selection/basic_outputs.rs | 70 +++++++++---------- .../client/input_selection/expiration.rs | 10 +-- .../client/input_selection/foundry_outputs.rs | 32 ++++----- .../client/input_selection/nft_outputs.rs | 48 ++++++------- sdk/tests/client/input_selection/outputs.rs | 14 ++-- .../input_selection/storage_deposit_return.rs | 22 +++--- sdk/tests/client/input_selection/timelock.rs | 10 +-- 8 files changed, 132 insertions(+), 132 deletions(-) diff --git a/sdk/tests/client/input_selection/account_outputs.rs b/sdk/tests/client/input_selection/account_outputs.rs index f83da7e778..d798619e03 100644 --- a/sdk/tests/client/input_selection/account_outputs.rs +++ b/sdk/tests/client/input_selection/account_outputs.rs @@ -49,7 +49,7 @@ fn input_account_eq_output_account() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -89,7 +89,7 @@ fn transition_account_id_zero() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -264,7 +264,7 @@ fn create_account() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -314,7 +314,7 @@ fn burn_account() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_2)) @@ -401,7 +401,7 @@ fn missing_input_for_account_output() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -454,7 +454,7 @@ fn missing_input_for_account_output_2() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -496,7 +496,7 @@ fn missing_input_for_account_output_but_created() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -551,7 +551,7 @@ fn account_in_output_and_sender() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -590,7 +590,7 @@ fn missing_ed25519_sender() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -632,7 +632,7 @@ fn missing_ed25519_issuer_created() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -672,7 +672,7 @@ fn missing_ed25519_issuer_transition() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -709,7 +709,7 @@ fn missing_account_sender() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -751,7 +751,7 @@ fn missing_account_issuer_created() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -791,7 +791,7 @@ fn missing_account_issuer_transition() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -828,7 +828,7 @@ fn missing_nft_sender() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -870,7 +870,7 @@ fn missing_nft_issuer_created() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -910,7 +910,7 @@ fn missing_nft_issuer_transition() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -959,7 +959,7 @@ fn increase_account_amount() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1010,7 +1010,7 @@ fn decrease_account_amount() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1075,7 +1075,7 @@ fn prefer_basic_to_account() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1129,7 +1129,7 @@ fn take_amount_from_account_to_fund_basic() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1197,7 +1197,7 @@ fn account_burn_should_validate_account_sender() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_1)) @@ -1263,7 +1263,7 @@ fn account_burn_should_validate_account_address() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_1)) @@ -1317,7 +1317,7 @@ fn transitioned_zero_account_id_no_longer_is_zero() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1384,7 +1384,7 @@ fn two_accounts_required() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1446,7 +1446,7 @@ fn state_controller_sender_required() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1498,7 +1498,7 @@ fn state_controller_sender_required_already_selected() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) @@ -1538,7 +1538,7 @@ fn state_transition_and_required() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) @@ -1578,7 +1578,7 @@ fn remainder_address_in_state_controller() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() diff --git a/sdk/tests/client/input_selection/basic_outputs.rs b/sdk/tests/client/input_selection/basic_outputs.rs index 666316c094..5689848353 100644 --- a/sdk/tests/client/input_selection/basic_outputs.rs +++ b/sdk/tests/client/input_selection/basic_outputs.rs @@ -52,7 +52,7 @@ fn input_amount_equal_output_amount() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -94,7 +94,7 @@ fn input_amount_lower_than_output_amount() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -152,7 +152,7 @@ fn input_amount_lower_than_output_amount_2() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -198,7 +198,7 @@ fn input_amount_greater_than_output_amount() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -253,7 +253,7 @@ fn input_amount_greater_than_output_amount_with_remainder_address() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_remainder_address(remainder_address) @@ -320,7 +320,7 @@ fn two_same_inputs_one_needed() { inputs, outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -387,7 +387,7 @@ fn two_inputs_one_needed() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -441,7 +441,7 @@ fn two_inputs_one_needed_reversed() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -495,7 +495,7 @@ fn two_inputs_both_needed() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -549,7 +549,7 @@ fn two_inputs_remainder() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -691,7 +691,7 @@ fn ed25519_sender() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), ], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -741,7 +741,7 @@ fn missing_ed25519_sender() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -825,7 +825,7 @@ fn account_sender() { inputs, outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -888,7 +888,7 @@ fn account_sender_zero_id() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -936,7 +936,7 @@ fn missing_account_sender() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -1022,7 +1022,7 @@ fn nft_sender() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1088,7 +1088,7 @@ fn nft_sender_zero_id() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1136,7 +1136,7 @@ fn missing_nft_sender() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -1179,7 +1179,7 @@ fn simple_remainder() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1312,7 +1312,7 @@ fn one_provided_one_needed() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1354,7 +1354,7 @@ fn insufficient_amount() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -1412,7 +1412,7 @@ fn two_inputs_remainder_2() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1478,7 +1478,7 @@ fn two_inputs_remainder_3() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1574,7 +1574,7 @@ fn sender_already_selected() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), ], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) @@ -1620,7 +1620,7 @@ fn single_mandatory_input() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), ], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) @@ -1667,7 +1667,7 @@ fn too_many_inputs() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -1730,7 +1730,7 @@ fn more_than_max_inputs_only_one_needed() { inputs, outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1777,7 +1777,7 @@ fn too_many_outputs() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -1826,7 +1826,7 @@ fn too_many_outputs_with_remainder() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -1905,7 +1905,7 @@ fn restricted_ed25519() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1954,7 +1954,7 @@ fn restricted_nft() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -2001,7 +2001,7 @@ fn restricted_account() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -2091,7 +2091,7 @@ fn restricted_ed25519_sender() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), ], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -2181,7 +2181,7 @@ fn multi_address_sender_already_fulfilled() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), ], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_required_inputs([*inputs[0].output_id(), *inputs[1].output_id(), *inputs[2].output_id()]) @@ -2246,7 +2246,7 @@ fn ed25519_backed_available_address() { outputs.clone(), // Restricted address is provided, but it can also unlock the ed25519 one [restricted_address], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() diff --git a/sdk/tests/client/input_selection/expiration.rs b/sdk/tests/client/input_selection/expiration.rs index 0ec08d4bd3..7703fc68e2 100644 --- a/sdk/tests/client/input_selection/expiration.rs +++ b/sdk/tests/client/input_selection/expiration.rs @@ -53,7 +53,7 @@ fn one_output_expiration_not_expired() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -244,7 +244,7 @@ fn two_outputs_one_unexpired_one_missing() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -367,7 +367,7 @@ fn two_outputs_two_expired_2() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), ], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -821,7 +821,7 @@ fn expiration_expired_only_account_addresses() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -864,7 +864,7 @@ fn one_nft_output_expiration_unexpired() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() diff --git a/sdk/tests/client/input_selection/foundry_outputs.rs b/sdk/tests/client/input_selection/foundry_outputs.rs index a3e62ec19f..6f8bef4027 100644 --- a/sdk/tests/client/input_selection/foundry_outputs.rs +++ b/sdk/tests/client/input_selection/foundry_outputs.rs @@ -56,7 +56,7 @@ fn missing_input_account_for_foundry() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -145,7 +145,7 @@ fn minted_native_tokens_in_new_remainder() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -217,7 +217,7 @@ fn minted_native_tokens_in_provided_output() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -285,7 +285,7 @@ fn melt_native_tokens() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -339,7 +339,7 @@ fn destroy_foundry_with_account_state_transition() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_burn(Burn::new().add_foundry(inputs[1].output.as_foundry().id())) @@ -391,7 +391,7 @@ fn destroy_foundry_with_account_burn() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_burn( @@ -467,7 +467,7 @@ fn prefer_basic_to_foundry() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -530,7 +530,7 @@ fn simple_foundry_transition_basic_not_needed() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -608,7 +608,7 @@ fn simple_foundry_transition_basic_not_needed_with_remainder() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -754,7 +754,7 @@ fn mint_and_burn_at_the_same_time() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_burn(Burn::new().add_native_token(token_id, 10)) @@ -822,7 +822,7 @@ fn take_amount_from_account_and_foundry_to_fund_basic() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -878,7 +878,7 @@ fn create_native_token_but_burn_account() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_1)) @@ -940,7 +940,7 @@ fn melted_tokens_not_provided() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -993,7 +993,7 @@ fn burned_tokens_not_provided() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_burn(Burn::new().add_native_token(token_id_1, 100)) @@ -1047,7 +1047,7 @@ fn foundry_in_outputs_and_required() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_required_inputs([*inputs[1].output_id()]) @@ -1118,7 +1118,7 @@ fn melt_and_burn_native_tokens() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) // Burn 456 native tokens diff --git a/sdk/tests/client/input_selection/nft_outputs.rs b/sdk/tests/client/input_selection/nft_outputs.rs index c5c72a4a1a..9bb6b91a91 100644 --- a/sdk/tests/client/input_selection/nft_outputs.rs +++ b/sdk/tests/client/input_selection/nft_outputs.rs @@ -57,7 +57,7 @@ fn input_nft_eq_output_nft() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -101,7 +101,7 @@ fn transition_nft_id_zero() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -232,7 +232,7 @@ fn mint_nft() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -284,7 +284,7 @@ fn burn_nft() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id_2)) @@ -373,7 +373,7 @@ fn missing_input_for_nft_output() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -417,7 +417,7 @@ fn missing_input_for_nft_output_but_created() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -482,7 +482,7 @@ fn nft_in_output_and_sender() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -533,7 +533,7 @@ fn missing_ed25519_sender() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -577,7 +577,7 @@ fn missing_ed25519_issuer_created() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -621,7 +621,7 @@ fn missing_ed25519_issuer_transition() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -662,7 +662,7 @@ fn missing_account_sender() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -706,7 +706,7 @@ fn missing_account_issuer_created() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -750,7 +750,7 @@ fn missing_account_issuer_transition() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -791,7 +791,7 @@ fn missing_nft_sender() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -835,7 +835,7 @@ fn missing_nft_issuer_created() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -879,7 +879,7 @@ fn missing_nft_issuer_transition() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -932,7 +932,7 @@ fn increase_nft_amount() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -987,7 +987,7 @@ fn decrease_nft_amount() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1054,7 +1054,7 @@ fn prefer_basic_to_nft() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1110,7 +1110,7 @@ fn take_amount_from_nft_to_fund_basic() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1178,7 +1178,7 @@ fn nft_burn_should_validate_nft_sender() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id_1)) @@ -1234,7 +1234,7 @@ fn nft_burn_should_validate_nft_address() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id_1)) @@ -1278,7 +1278,7 @@ fn transitioned_zero_nft_id_no_longer_is_zero() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -1355,7 +1355,7 @@ fn changed_immutable_metadata() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); diff --git a/sdk/tests/client/input_selection/outputs.rs b/sdk/tests/client/input_selection/outputs.rs index 81a9ae7f9b..7ea737409b 100644 --- a/sdk/tests/client/input_selection/outputs.rs +++ b/sdk/tests/client/input_selection/outputs.rs @@ -35,7 +35,7 @@ fn no_inputs() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -66,7 +66,7 @@ fn no_outputs() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -96,7 +96,7 @@ fn no_outputs_but_burn() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_2)) @@ -141,7 +141,7 @@ fn no_address_provided() { None, )]); - let selected = InputSelection::new(inputs, outputs, [], SLOT_INDEX + 1, protocol_parameters).select(); + let selected = InputSelection::new(inputs, outputs, [], SLOT_INDEX, protocol_parameters).select(); assert!(matches!(selected, Err(Error::NoAvailableInputsProvided))); } @@ -178,7 +178,7 @@ fn no_matching_address_provided() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -230,7 +230,7 @@ fn two_addresses_one_missing() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -291,7 +291,7 @@ fn two_addresses() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), ], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() diff --git a/sdk/tests/client/input_selection/storage_deposit_return.rs b/sdk/tests/client/input_selection/storage_deposit_return.rs index 3f47afb6b5..2a2756b6fd 100644 --- a/sdk/tests/client/input_selection/storage_deposit_return.rs +++ b/sdk/tests/client/input_selection/storage_deposit_return.rs @@ -48,7 +48,7 @@ fn sdruc_output_not_provided_no_remainder() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -113,7 +113,7 @@ fn sdruc_output_provided_no_remainder() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -155,7 +155,7 @@ fn sdruc_output_provided_remainder() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -220,7 +220,7 @@ fn two_sdrucs_to_the_same_address_both_needed() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -285,7 +285,7 @@ fn two_sdrucs_to_the_same_address_one_needed() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -351,7 +351,7 @@ fn two_sdrucs_to_different_addresses_both_needed() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -422,7 +422,7 @@ fn two_sdrucs_to_different_addresses_one_needed() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -476,7 +476,7 @@ fn insufficient_amount_because_of_sdruc() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -537,7 +537,7 @@ fn useless_sdruc_required_for_sender_feature() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), ], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -601,7 +601,7 @@ fn sdruc_required_non_ed25519_in_address_unlock() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -675,7 +675,7 @@ fn useless_sdruc_non_ed25519_in_address_unlock() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() diff --git a/sdk/tests/client/input_selection/timelock.rs b/sdk/tests/client/input_selection/timelock.rs index 907d9c4c93..09d7d11fd3 100644 --- a/sdk/tests/client/input_selection/timelock.rs +++ b/sdk/tests/client/input_selection/timelock.rs @@ -44,7 +44,7 @@ fn one_output_timelock_not_expired() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select(); @@ -84,7 +84,7 @@ fn timelock_equal_timestamp() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -138,7 +138,7 @@ fn two_outputs_one_timelock_expired() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -193,7 +193,7 @@ fn two_outputs_one_timelocked_one_missing() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() @@ -236,7 +236,7 @@ fn one_output_timelock_expired() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX + 1, + SLOT_INDEX, protocol_parameters, ) .select() From b38e29df41b68b31c37746e3ea5badca57c25ace Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Fri, 12 Jan 2024 16:59:50 +0100 Subject: [PATCH 18/45] Fix timelock tests --- sdk/tests/client/input_selection/timelock.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sdk/tests/client/input_selection/timelock.rs b/sdk/tests/client/input_selection/timelock.rs index 09d7d11fd3..06e4227f10 100644 --- a/sdk/tests/client/input_selection/timelock.rs +++ b/sdk/tests/client/input_selection/timelock.rs @@ -3,7 +3,7 @@ use iota_sdk::{ client::api::input_selection::{Error, InputSelection}, - types::block::{address::Address, protocol::protocol_parameters}, + types::block::{address::Address, protocol::protocol_parameters, slot::SlotIndex}, }; use pretty_assertions::assert_eq; @@ -67,7 +67,7 @@ fn timelock_equal_timestamp() { None, None, )], - None, + Some(SlotIndex::from(200)), ); let outputs = build_outputs([Basic( 2_000_000, @@ -84,7 +84,7 @@ fn timelock_equal_timestamp() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX, + 200, protocol_parameters, ) .select() @@ -121,7 +121,7 @@ fn two_outputs_one_timelock_expired() { None, ), ], - None, + Some(SlotIndex::from(100)), ); let outputs = build_outputs([Basic( 2_000_000, @@ -138,7 +138,7 @@ fn two_outputs_one_timelock_expired() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX, + 100, protocol_parameters, ) .select() @@ -176,7 +176,7 @@ fn two_outputs_one_timelocked_one_missing() { None, ), ], - None, + Some(SlotIndex::from(100)), ); let outputs = build_outputs([Basic( 2_000_000, @@ -193,7 +193,7 @@ fn two_outputs_one_timelocked_one_missing() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX, + 100, protocol_parameters, ) .select() @@ -219,7 +219,7 @@ fn one_output_timelock_expired() { None, None, )], - None, + Some(SlotIndex::from(100)), ); let outputs = build_outputs([Basic( 2_000_000, @@ -236,7 +236,7 @@ fn one_output_timelock_expired() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX, + 100, protocol_parameters, ) .select() From 172821a4f547197f1f15cfea2e4d2438a123aef9 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Fri, 12 Jan 2024 17:06:42 +0100 Subject: [PATCH 19/45] Fix NFT tests --- sdk/src/types/block/rand/output/mod.rs | 13 +++++++++++-- .../client/input_selection/nft_outputs.rs | 18 +++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/sdk/src/types/block/rand/output/mod.rs b/sdk/src/types/block/rand/output/mod.rs index 8dc8ad3231..604eec7e5f 100644 --- a/sdk/src/types/block/rand/output/mod.rs +++ b/sdk/src/types/block/rand/output/mod.rs @@ -35,13 +35,22 @@ use crate::types::block::{ rand_state_controller_address_unlock_condition_different_from, }, }, - transaction::rand_transaction_id, + transaction::rand_transaction_id_with_slot_index, }, + slot::SlotIndex, }; +/// Generates a random output id with a given slot index. +pub fn rand_output_id_with_slot_index(slot_index: impl Into) -> OutputId { + OutputId::new( + rand_transaction_id_with_slot_index(slot_index), + rand_number_range(OUTPUT_INDEX_RANGE), + ) +} + /// Generates a random [`OutputId`]. pub fn rand_output_id() -> OutputId { - OutputId::new(rand_transaction_id(), rand_number_range(OUTPUT_INDEX_RANGE)) + rand_output_id_with_slot_index(rand_number::()) } /// Generates a random [`BasicOutput`]. diff --git a/sdk/tests/client/input_selection/nft_outputs.rs b/sdk/tests/client/input_selection/nft_outputs.rs index 9bb6b91a91..96ae5c18b9 100644 --- a/sdk/tests/client/input_selection/nft_outputs.rs +++ b/sdk/tests/client/input_selection/nft_outputs.rs @@ -12,7 +12,7 @@ use iota_sdk::{ address::Address, output::{feature::MetadataFeature, unlock_condition::AddressUnlockCondition, NftId, NftOutputBuilder, Output}, protocol::protocol_parameters, - rand::output::rand_output_metadata, + rand::output::{rand_output_id_with_slot_index, rand_output_metadata_with_id}, }, }; use pretty_assertions::{assert_eq, assert_ne}; @@ -453,7 +453,7 @@ fn nft_in_output_and_sender() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([ Nft( @@ -915,7 +915,7 @@ fn increase_nft_amount() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Nft( 3_000_000, @@ -970,7 +970,7 @@ fn decrease_nft_amount() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Nft( 1_000_000, @@ -1037,7 +1037,7 @@ fn prefer_basic_to_nft() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -1093,7 +1093,7 @@ fn take_amount_from_nft_to_fund_basic() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_200_000, @@ -1161,7 +1161,7 @@ fn nft_burn_should_validate_nft_sender() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 3_000_000, @@ -1217,7 +1217,7 @@ fn nft_burn_should_validate_nft_address() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 3_000_000, @@ -1328,7 +1328,7 @@ fn changed_immutable_metadata() { let inputs = [InputSigningData { output: nft_output.clone(), - output_metadata: rand_output_metadata(), + output_metadata: rand_output_metadata_with_id(rand_output_id_with_slot_index(SLOT_INDEX)), chain: None, }]; From 5ae3bdd3dc4504d24a6e0c1dbd3defb49746728f Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Fri, 12 Jan 2024 17:11:39 +0100 Subject: [PATCH 20/45] Fix foundry tests --- .../client/input_selection/foundry_outputs.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sdk/tests/client/input_selection/foundry_outputs.rs b/sdk/tests/client/input_selection/foundry_outputs.rs index 6f8bef4027..7ec2d88494 100644 --- a/sdk/tests/client/input_selection/foundry_outputs.rs +++ b/sdk/tests/client/input_selection/foundry_outputs.rs @@ -15,7 +15,7 @@ use iota_sdk::{ SimpleTokenScheme, TokenId, }, protocol::protocol_parameters, - rand::output::rand_output_metadata, + rand::output::{rand_output_id_with_slot_index, rand_output_metadata_with_id}, }, }; use pretty_assertions::assert_eq; @@ -269,7 +269,7 @@ fn melt_native_tokens() { .unwrap(); inputs.push(InputSigningData { output: account_output, - output_metadata: rand_output_metadata(), + output_metadata: rand_output_metadata_with_id(rand_output_id_with_slot_index(SLOT_INDEX)), chain: None, }); let outputs = build_outputs([Foundry( @@ -514,7 +514,7 @@ fn simple_foundry_transition_basic_not_needed() { .unwrap(); inputs.push(InputSigningData { output: account_output, - output_metadata: rand_output_metadata(), + output_metadata: rand_output_metadata_with_id(rand_output_id_with_slot_index(SLOT_INDEX)), chain: None, }); @@ -593,7 +593,7 @@ fn simple_foundry_transition_basic_not_needed_with_remainder() { .unwrap(); inputs.push(InputSigningData { output: account_output, - output_metadata: rand_output_metadata(), + output_metadata: rand_output_metadata_with_id(rand_output_id_with_slot_index(SLOT_INDEX)), chain: None, }); let outputs = build_outputs([Foundry( @@ -738,7 +738,7 @@ fn mint_and_burn_at_the_same_time() { .unwrap(); inputs.push(InputSigningData { output: account_output, - output_metadata: rand_output_metadata(), + output_metadata: rand_output_metadata_with_id(rand_output_id_with_slot_index(SLOT_INDEX)), chain: None, }); @@ -804,7 +804,7 @@ fn take_amount_from_account_and_foundry_to_fund_basic() { .unwrap(); inputs.push(InputSigningData { output: account_output, - output_metadata: rand_output_metadata(), + output_metadata: rand_output_metadata_with_id(rand_output_id_with_slot_index(SLOT_INDEX)), chain: None, }); let outputs = build_outputs([Basic( @@ -1032,7 +1032,7 @@ fn foundry_in_outputs_and_required() { .unwrap(); inputs.push(InputSigningData { output: account_output, - output_metadata: rand_output_metadata(), + output_metadata: rand_output_metadata_with_id(rand_output_id_with_slot_index(SLOT_INDEX)), chain: None, }); let outputs = build_outputs([Foundry( @@ -1102,7 +1102,7 @@ fn melt_and_burn_native_tokens() { .unwrap(); inputs.push(InputSigningData { output: account_output, - output_metadata: rand_output_metadata(), + output_metadata: rand_output_metadata_with_id(rand_output_id_with_slot_index(SLOT_INDEX)), chain: None, }); let outputs = build_outputs([Foundry( From 9147c985c822ca9bdfd0b7d3482481982a4ed9cc Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Fri, 12 Jan 2024 17:12:53 +0100 Subject: [PATCH 21/45] Fix storage deposit tests --- .../input_selection/storage_deposit_return.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sdk/tests/client/input_selection/storage_deposit_return.rs b/sdk/tests/client/input_selection/storage_deposit_return.rs index 2a2756b6fd..3b451de41a 100644 --- a/sdk/tests/client/input_selection/storage_deposit_return.rs +++ b/sdk/tests/client/input_selection/storage_deposit_return.rs @@ -203,7 +203,7 @@ fn two_sdrucs_to_the_same_address_both_needed() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 2_000_000, @@ -268,7 +268,7 @@ fn two_sdrucs_to_the_same_address_one_needed() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -334,7 +334,7 @@ fn two_sdrucs_to_different_addresses_both_needed() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 2_000_000, @@ -405,7 +405,7 @@ fn two_sdrucs_to_different_addresses_one_needed() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -517,7 +517,7 @@ fn useless_sdruc_required_for_sender_feature() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -584,7 +584,7 @@ fn sdruc_required_non_ed25519_in_address_unlock() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -658,7 +658,7 @@ fn useless_sdruc_non_ed25519_in_address_unlock() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, From 675d775d2ce12e9c8f456b8c6c45751cc187e32c Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Fri, 12 Jan 2024 17:23:36 +0100 Subject: [PATCH 22/45] Fix last tests --- sdk/tests/client/input_selection/outputs.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/tests/client/input_selection/outputs.rs b/sdk/tests/client/input_selection/outputs.rs index 7ea737409b..bdce5ea3cd 100644 --- a/sdk/tests/client/input_selection/outputs.rs +++ b/sdk/tests/client/input_selection/outputs.rs @@ -88,7 +88,7 @@ fn no_outputs_but_burn() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = Vec::new(); @@ -128,7 +128,7 @@ fn no_address_provided() { None, None, )], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 1_000_000, @@ -213,7 +213,7 @@ fn two_addresses_one_missing() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 2_000_000, @@ -271,7 +271,7 @@ fn two_addresses() { None, ), ], - None, + Some(SLOT_INDEX), ); let outputs = build_outputs([Basic( 2_000_000, From d80577958b4db1a4488d892dbbc6cfac2bf06e0b Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Fri, 12 Jan 2024 17:25:22 +0100 Subject: [PATCH 23/45] Nit --- sdk/tests/client/input_selection/timelock.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sdk/tests/client/input_selection/timelock.rs b/sdk/tests/client/input_selection/timelock.rs index 06e4227f10..a57655846c 100644 --- a/sdk/tests/client/input_selection/timelock.rs +++ b/sdk/tests/client/input_selection/timelock.rs @@ -9,7 +9,6 @@ use pretty_assertions::assert_eq; use crate::client::{ build_inputs, build_outputs, unsorted_eq, Build::Basic, BECH32_ADDRESS_ED25519_0, BECH32_ADDRESS_ED25519_1, - SLOT_INDEX, }; #[test] @@ -44,7 +43,7 @@ fn one_output_timelock_not_expired() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX, + 100, protocol_parameters, ) .select(); From d86634c36e32c91d89e9b97e303f5ffc3aeb5f36 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Fri, 12 Jan 2024 17:29:03 +0100 Subject: [PATCH 24/45] More nits --- .../client/input_selection/expiration.rs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/sdk/tests/client/input_selection/expiration.rs b/sdk/tests/client/input_selection/expiration.rs index 7703fc68e2..82c56051c5 100644 --- a/sdk/tests/client/input_selection/expiration.rs +++ b/sdk/tests/client/input_selection/expiration.rs @@ -18,7 +18,7 @@ use crate::client::{ build_inputs, build_outputs, is_remainder_or_return, unsorted_eq, Build::{Account, Basic, Nft}, ACCOUNT_ID_1, BECH32_ADDRESS_ACCOUNT_1, BECH32_ADDRESS_ED25519_0, BECH32_ADDRESS_ED25519_1, - BECH32_ADDRESS_ED25519_2, NFT_ID_1, SLOT_INDEX, + BECH32_ADDRESS_ED25519_2, NFT_ID_1, }; #[test] @@ -36,7 +36,7 @@ fn one_output_expiration_not_expired() { Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 200)), None, )], - Some(SLOT_INDEX), + Some(SlotIndex::from(100)), ); let outputs = build_outputs([Basic( 2_000_000, @@ -53,7 +53,7 @@ fn one_output_expiration_not_expired() { inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX, + 100, protocol_parameters, ) .select(); @@ -227,7 +227,7 @@ fn two_outputs_one_unexpired_one_missing() { None, ), ], - Some(SLOT_INDEX), + Some(SlotIndex::from(100)), ); let outputs = build_outputs([Basic( 2_000_000, @@ -244,7 +244,7 @@ fn two_outputs_one_unexpired_one_missing() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX, + 100, protocol_parameters, ) .select() @@ -347,7 +347,7 @@ fn two_outputs_two_expired_2() { None, ), ], - Some(SLOT_INDEX), + Some(SlotIndex::from(200)), ); let outputs = build_outputs([Basic( 4_000_000, @@ -367,7 +367,7 @@ fn two_outputs_two_expired_2() { Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap(), Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap(), ], - SLOT_INDEX, + 200, protocol_parameters, ) .select() @@ -803,7 +803,7 @@ fn expiration_expired_only_account_addresses() { None, ), ], - Some(SLOT_INDEX), + Some(SlotIndex::from(100)), ); let outputs = build_outputs([Basic( @@ -821,7 +821,7 @@ fn expiration_expired_only_account_addresses() { inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], - SLOT_INDEX, + 100, protocol_parameters, ) .select() @@ -847,7 +847,7 @@ fn one_nft_output_expiration_unexpired() { Some((Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), 150)), None, )], - Some(SLOT_INDEX), + Some(SlotIndex::from(100)), ); let outputs = build_outputs([Nft( 2_000_000, @@ -864,7 +864,7 @@ fn one_nft_output_expiration_unexpired() { inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap()], - SLOT_INDEX, + 100, protocol_parameters, ) .select() From 078fa62e219b639796ba900929309b8f873708bd Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Fri, 12 Jan 2024 17:35:02 +0100 Subject: [PATCH 25/45] Remove commented code --- .../operations/transaction/build_transaction.rs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/sdk/src/wallet/operations/transaction/build_transaction.rs b/sdk/src/wallet/operations/transaction/build_transaction.rs index c2dcda6d87..7b2da15e96 100644 --- a/sdk/src/wallet/operations/transaction/build_transaction.rs +++ b/sdk/src/wallet/operations/transaction/build_transaction.rs @@ -10,7 +10,7 @@ use crate::{ }, types::block::{ input::{Input, UtxoInput}, - payload::signed_transaction::{Transaction, TransactionCapabilities, TransactionCapabilityFlag}, + payload::signed_transaction::Transaction, }, wallet::{operations::transaction::TransactionOptions, Wallet}, }; @@ -46,7 +46,7 @@ where .with_inputs(inputs) .with_outputs(selected_transaction_data.outputs); - if let Some(mut options) = options.into() { + if let Some(options) = options.into() { // Optional add a tagged payload builder = builder.with_payload(options.tagged_data_payload); @@ -54,18 +54,6 @@ where builder = builder.with_context_inputs(context_inputs); } - // // TODO remove when https://github.com/iotaledger/iota-sdk/issues/1744 is done - // match options.capabilities.as_mut() { - // Some(capabilities) => { - // capabilities.add_capability(TransactionCapabilityFlag::BurnMana); - // } - // None => { - // let mut capabilities = TransactionCapabilities::default(); - // capabilities.add_capability(TransactionCapabilityFlag::BurnMana); - // options.capabilities = Some(capabilities); - // } - // } - if let Some(capabilities) = options.capabilities { builder = builder.add_capabilities(capabilities.capabilities_iter()); } From 63740797e73a6524a4b8780190ab35952e4c7bb9 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Sun, 14 Jan 2024 18:58:21 +0100 Subject: [PATCH 26/45] Set BIC input if account is transitioned --- .../transaction/build_transaction.rs | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/sdk/src/wallet/operations/transaction/build_transaction.rs b/sdk/src/wallet/operations/transaction/build_transaction.rs index 7b2da15e96..dd0ca00de7 100644 --- a/sdk/src/wallet/operations/transaction/build_transaction.rs +++ b/sdk/src/wallet/operations/transaction/build_transaction.rs @@ -9,7 +9,9 @@ use crate::{ secret::{types::InputSigningData, SecretManage}, }, types::block::{ + context_input::{BlockIssuanceCreditContextInput, ContextInput}, input::{Input, UtxoInput}, + output::Output, payload::signed_transaction::Transaction, }, wallet::{operations::transaction::TransactionOptions, Wallet}, @@ -32,11 +34,20 @@ where let mut inputs: Vec = Vec::new(); let mut inputs_for_signing: Vec = Vec::new(); + let mut context_inputs = Vec::new(); + + for input in &selected_transaction_data.inputs { + if let Output::Account(account) = &input.output { + if account.features().block_issuer().is_some() { + context_inputs.push(ContextInput::from(BlockIssuanceCreditContextInput::from( + account.account_id_non_null(input.output_id()), + ))); + } + println!("account -- {account:?}"); + } - for utxo in &selected_transaction_data.inputs { - let input = Input::Utxo(UtxoInput::from(*utxo.output_id())); - inputs.push(input.clone()); - inputs_for_signing.push(utxo.clone()); + inputs.push(Input::Utxo(UtxoInput::from(*input.output_id()))); + inputs_for_signing.push(input.clone()); } // Build transaction @@ -50,8 +61,9 @@ where // Optional add a tagged payload builder = builder.with_payload(options.tagged_data_payload); - if let Some(context_inputs) = options.context_inputs { - builder = builder.with_context_inputs(context_inputs); + if let Some(context_inputs_opt) = options.context_inputs { + // TODO uniqueness ? + context_inputs.extend(context_inputs_opt); } if let Some(capabilities) = options.capabilities { @@ -63,7 +75,11 @@ where } } - let transaction = builder.finish_with_params(&protocol_parameters)?; + let transaction = builder + .with_context_inputs(context_inputs) + .finish_with_params(&protocol_parameters)?; + + println!("{transaction:?}"); validate_transaction_length(&transaction)?; From 46701656bd8d9861243f79802f6e607b47a9f02f Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 15 Jan 2024 12:27:08 +0100 Subject: [PATCH 27/45] Allow one NT remainder --- .../api/block_builder/input_selection/mod.rs | 2 -- .../input_selection/remainder.rs | 29 ++++++------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/sdk/src/client/api/block_builder/input_selection/mod.rs b/sdk/src/client/api/block_builder/input_selection/mod.rs index 4267a6e15e..df3b6eefa8 100644 --- a/sdk/src/client/api/block_builder/input_selection/mod.rs +++ b/sdk/src/client/api/block_builder/input_selection/mod.rs @@ -433,8 +433,6 @@ impl InputSelection { remainder, }; - println!("{selected:?}"); - Ok(selected) } diff --git a/sdk/src/client/api/block_builder/input_selection/remainder.rs b/sdk/src/client/api/block_builder/input_selection/remainder.rs index 195aba3160..ae5450ba70 100644 --- a/sdk/src/client/api/block_builder/input_selection/remainder.rs +++ b/sdk/src/client/api/block_builder/input_selection/remainder.rs @@ -76,9 +76,10 @@ impl InputSelection { )))); // TODO https://github.com/iotaledger/iota-sdk/issues/1631 - // if let Some(native_tokens) = native_tokens_diff { - // remainder_builder = remainder_builder.with_native_tokens(native_tokens); - // } + // TODO Only putting one in remainder atm so we can at least create foundries + if let Some(native_tokens) = native_tokens_diff { + remainder_builder = remainder_builder.with_native_token(*native_tokens.first().unwrap()); + } Ok((remainder_builder.finish_output()?.amount(), native_tokens_remainder)) } @@ -142,20 +143,11 @@ impl InputSelection { self.slot_index, )?; - println!( - "ISA created {}, target {}", - input.output_id().transaction_id().slot_index(), - self.slot_index, - ); - input_mana += potential_mana + stored_mana; // TODO rewards } let output_mana = self.outputs.iter().map(|o| o.mana()).sum::() + self.mana_allotments; - // TODO allotment - - println!("ISA input_mana {input_mana}, output_mana {output_mana}"); if inputs_sum == outputs_sum && input_mana == output_mana && native_tokens_diff.is_none() { log::debug!("No remainder required"); @@ -204,17 +196,14 @@ impl InputSelection { remainder_builder.add_unlock_condition(AddressUnlockCondition::new(remainder_address.clone())); // TODO https://github.com/iotaledger/iota-sdk/issues/1631 - // if let Some(native_tokens) = native_tokens_diff { - // log::debug!("Adding {native_tokens:?} to remainder output for {remainder_address:?}"); - // remainder_builder = remainder_builder.with_native_tokens(native_tokens); - // } + // TODO Only putting one in remainder atm so we can at least create foundries + if let Some(native_tokens) = native_tokens_diff { + log::debug!("Adding {native_tokens:?} to remainder output for {remainder_address:?}"); + remainder_builder = remainder_builder.with_native_token(*native_tokens.first().unwrap()); + } let remainder = remainder_builder.finish_output()?; - println!("remainder {remainder:?}"); - - println!("{:?}", self); - // TODO add log log::debug!("Created remainder output of {amount_diff} for {remainder_address:?}"); From fb68a8a97af7e1ae19c265527183f8af60697332 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 15 Jan 2024 12:30:44 +0100 Subject: [PATCH 28/45] Remove prints --- sdk/src/types/block/semantic/mod.rs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/sdk/src/types/block/semantic/mod.rs b/sdk/src/types/block/semantic/mod.rs index 7e14592e73..0c7a7e8c11 100644 --- a/sdk/src/types/block/semantic/mod.rs +++ b/sdk/src/types/block/semantic/mod.rs @@ -174,14 +174,6 @@ impl<'a> SemanticValidationContext<'a> { ) }?; - println!( - "semantic created {}, target {}", - output_id.transaction_id().slot_index(), - self.transaction.creation_slot() - ); - - println!("potential_mana {potential_mana}"); - // Add potential mana self.input_mana = self .input_mana @@ -194,8 +186,6 @@ impl<'a> SemanticValidationContext<'a> { self.transaction.creation_slot(), )?; - println!("stored_mana {stored_mana}"); - // Add stored mana self.input_mana = self .input_mana @@ -302,11 +292,6 @@ impl<'a> SemanticValidationContext<'a> { return Ok(Some(TransactionFailureReason::SumInputsOutputsAmountMismatch)); } - println!( - "Semantic input_mana {} output_mana {}", - self.input_mana, self.output_mana - ); - if self.input_mana != self.output_mana { if self.input_mana > self.output_mana { if !self.transaction.has_capability(TransactionCapabilityFlag::BurnMana) { From a88b269d61d13765b5b4733f7cd0fe5982c91498 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 15 Jan 2024 13:40:34 +0100 Subject: [PATCH 29/45] Cleanup context inputs --- .../block/payload/signed_transaction/transaction.rs | 6 ++++-- .../operations/transaction/build_transaction.rs | 11 +++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/sdk/src/types/block/payload/signed_transaction/transaction.rs b/sdk/src/types/block/payload/signed_transaction/transaction.rs index b97e42c954..d0ca90259e 100644 --- a/sdk/src/types/block/payload/signed_transaction/transaction.rs +++ b/sdk/src/types/block/payload/signed_transaction/transaction.rs @@ -61,8 +61,8 @@ impl TransactionBuilder { } /// Sets the context inputs of a [`TransactionBuilder`]. - pub fn with_context_inputs(mut self, context_inputs: impl Into>) -> Self { - self.context_inputs = context_inputs.into(); + pub fn with_context_inputs(mut self, context_inputs: impl IntoIterator) -> Self { + self.context_inputs = context_inputs.into_iter().collect(); self } @@ -164,6 +164,8 @@ impl TransactionBuilder { .try_into() .map_err(Error::InvalidContextInputCount)?; + verify_context_inputs(&context_inputs)?; + let inputs: BoxedSlicePrefix = self .inputs .into_boxed_slice() diff --git a/sdk/src/wallet/operations/transaction/build_transaction.rs b/sdk/src/wallet/operations/transaction/build_transaction.rs index dd0ca00de7..cff7dcd261 100644 --- a/sdk/src/wallet/operations/transaction/build_transaction.rs +++ b/sdk/src/wallet/operations/transaction/build_transaction.rs @@ -1,6 +1,8 @@ // Copyright 2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +use std::collections::HashSet; + use instant::Instant; use crate::{ @@ -34,16 +36,16 @@ where let mut inputs: Vec = Vec::new(); let mut inputs_for_signing: Vec = Vec::new(); - let mut context_inputs = Vec::new(); + let mut context_inputs = HashSet::new(); for input in &selected_transaction_data.inputs { + // Transitioning an issuer account requires a BlockIssuanceCreditContextInput. if let Output::Account(account) = &input.output { if account.features().block_issuer().is_some() { - context_inputs.push(ContextInput::from(BlockIssuanceCreditContextInput::from( + context_inputs.insert(ContextInput::from(BlockIssuanceCreditContextInput::from( account.account_id_non_null(input.output_id()), ))); } - println!("account -- {account:?}"); } inputs.push(Input::Utxo(UtxoInput::from(*input.output_id()))); @@ -62,7 +64,6 @@ where builder = builder.with_payload(options.tagged_data_payload); if let Some(context_inputs_opt) = options.context_inputs { - // TODO uniqueness ? context_inputs.extend(context_inputs_opt); } @@ -79,8 +80,6 @@ where .with_context_inputs(context_inputs) .finish_with_params(&protocol_parameters)?; - println!("{transaction:?}"); - validate_transaction_length(&transaction)?; let prepared_transaction_data = PreparedTransactionData { From 1ce140b210b27ae9d1b24d56f35fd55eba54bd8c Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 15 Jan 2024 13:44:54 +0100 Subject: [PATCH 30/45] Add comment --- sdk/src/types/block/output/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/types/block/output/mod.rs b/sdk/src/types/block/output/mod.rs index 4df71efb28..2d5a9178f5 100644 --- a/sdk/src/types/block/output/mod.rs +++ b/sdk/src/types/block/output/mod.rs @@ -217,7 +217,7 @@ impl Output { } } - /// + /// Returns all the mana held by the output, which is potential + stored, all decayed. pub fn all_mana( &self, protocol_parameters: &ProtocolParameters, From 6d627bd606754b39381440ea2d1cb41fb032fa17 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 15 Jan 2024 13:49:35 +0100 Subject: [PATCH 31/45] Remove clones --- .../wallet/operations/transaction/account.rs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/sdk/src/wallet/operations/transaction/account.rs b/sdk/src/wallet/operations/transaction/account.rs index ee14f62fe9..c0d406a25c 100644 --- a/sdk/src/wallet/operations/transaction/account.rs +++ b/sdk/src/wallet/operations/transaction/account.rs @@ -51,14 +51,15 @@ where where crate::wallet::Error: From, { - let implicit_account_data = self.data().await.unspent_outputs.get(output_id).cloned(); - - let implicit_account = if let Some(implicit_account_data) = implicit_account_data.clone() { - if implicit_account_data.output.is_implicit_account() { - implicit_account_data.output.as_basic().clone() - } else { - return Err(Error::ImplicitAccountNotFound); - } + let implicit_account_data = self + .data() + .await + .unspent_outputs + .get(output_id) + .cloned() + .ok_or(Error::ImplicitAccountNotFound)?; + let implicit_account = if implicit_account_data.output.is_implicit_account() { + implicit_account_data.output.as_basic() } else { return Err(Error::ImplicitAccountNotFound); }; @@ -86,9 +87,9 @@ where let account_id = AccountId::from(output_id); let account = AccountOutput::build_with_amount(implicit_account.amount(), account_id) - .with_mana(implicit_account_data.clone().unwrap().output.all_mana( + .with_mana(implicit_account_data.output.all_mana( &self.client().get_protocol_parameters().await?, - implicit_account_data.unwrap().output_id.transaction_id().slot_index(), + implicit_account_data.output_id.transaction_id().slot_index(), self.client().get_slot_index().await?, )?) .with_unlock_conditions([AddressUnlockCondition::from(Address::from( From 1a9f820ab66836a6e7c662a260a3dbfd267f7667 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 15 Jan 2024 13:56:42 +0100 Subject: [PATCH 32/45] Nits --- .../api/block_builder/input_selection/remainder.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sdk/src/client/api/block_builder/input_selection/remainder.rs b/sdk/src/client/api/block_builder/input_selection/remainder.rs index ae5450ba70..849d1359ef 100644 --- a/sdk/src/client/api/block_builder/input_selection/remainder.rs +++ b/sdk/src/client/api/block_builder/input_selection/remainder.rs @@ -15,8 +15,8 @@ use crate::{ types::block::{ address::{Address, Ed25519Address}, output::{ - unlock_condition::AddressUnlockCondition, AccountOutputBuilder, BasicOutputBuilder, FoundryOutputBuilder, - MinimumOutputAmount, NativeTokensBuilder, NftOutputBuilder, Output, + unlock_condition::AddressUnlockCondition, AccountOutputBuilder, BasicOutputBuilder, MinimumOutputAmount, + NativeTokensBuilder, NftOutputBuilder, Output, }, }, }; @@ -87,7 +87,7 @@ impl InputSelection { pub(crate) fn remainder_and_storage_deposit_return_outputs( &mut self, ) -> Result<(Option, Vec), Error> { - let (inputs_sum, outputs_sum, inputs_sdr, outputs_sdr) = + let (input_amount, output_amount, inputs_sdr, outputs_sdr) = amount_sums(&self.selected_inputs, &self.outputs, self.slot_index); let mut storage_deposit_returns = Vec::new(); @@ -149,16 +149,16 @@ impl InputSelection { let output_mana = self.outputs.iter().map(|o| o.mana()).sum::() + self.mana_allotments; - if inputs_sum == outputs_sum && input_mana == output_mana && native_tokens_diff.is_none() { + if input_amount == output_amount && input_mana == output_mana && native_tokens_diff.is_none() { log::debug!("No remainder required"); return Ok((None, storage_deposit_returns)); } // TODO underflows? - let amount_diff = inputs_sum - outputs_sum; + let amount_diff = input_amount - output_amount; let mana_diff = input_mana - output_mana; - if inputs_sum == outputs_sum && input_mana != output_mana && native_tokens_diff.is_none() { + if input_amount == output_amount && input_mana != output_mana && native_tokens_diff.is_none() { let output = self .outputs .iter_mut() From e0fc11f7230fb67c15f2a2942e0545c760eb270f Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 15 Jan 2024 14:03:12 +0100 Subject: [PATCH 33/45] Remove panic --- .../client/api/block_builder/input_selection/remainder.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk/src/client/api/block_builder/input_selection/remainder.rs b/sdk/src/client/api/block_builder/input_selection/remainder.rs index 849d1359ef..13a3b2d0aa 100644 --- a/sdk/src/client/api/block_builder/input_selection/remainder.rs +++ b/sdk/src/client/api/block_builder/input_selection/remainder.rs @@ -168,6 +168,8 @@ impl InputSelection { .as_ref() .map(|chain_id| self.automatically_transitioned.contains(chain_id)) .unwrap_or(false) + // Foundries can'ty hold mana so they are not considered here. + && !output.is_foundry() }) .next(); if let Some(output) = output { @@ -175,11 +177,10 @@ impl InputSelection { Output::Account(output) => AccountOutputBuilder::from(&*output) .with_mana(output.mana() + mana_diff) .finish_output()?, - Output::Foundry(_) => panic!(), Output::Nft(output) => NftOutputBuilder::from(&*output) .with_mana(output.mana() + mana_diff) .finish_output()?, - _ => panic!("only account, nft and foundry can be automatically created"), + _ => panic!("only account, nft can be automatically created and can hold mana"), }; } From bdc59751c75ca0bfa94e707da5565edd8783106f Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 15 Jan 2024 14:16:13 +0100 Subject: [PATCH 34/45] Use all_mana --- .../block_builder/input_selection/remainder.rs | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/sdk/src/client/api/block_builder/input_selection/remainder.rs b/sdk/src/client/api/block_builder/input_selection/remainder.rs index 13a3b2d0aa..e9dc415c5b 100644 --- a/sdk/src/client/api/block_builder/input_selection/remainder.rs +++ b/sdk/src/client/api/block_builder/input_selection/remainder.rs @@ -125,25 +125,11 @@ impl InputSelection { let mut input_mana = 0; for input in &self.selected_inputs { - let potential_mana = { - let min_deposit = input - .output - .minimum_amount(self.protocol_parameters.storage_score_parameters()); - let generation_amount = input.output.amount().saturating_sub(min_deposit); - - self.protocol_parameters.generate_mana_with_decay( - generation_amount, - input.output_id().transaction_id().slot_index(), - self.slot_index, - ) - }?; - let stored_mana = self.protocol_parameters.mana_with_decay( - input.output.mana(), + input_mana += input.output.all_mana( + &self.protocol_parameters, input.output_id().transaction_id().slot_index(), self.slot_index, )?; - - input_mana += potential_mana + stored_mana; // TODO rewards } From 3eaffb10df8096c044e059c70ad19471b9d53e31 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 15 Jan 2024 14:21:36 +0100 Subject: [PATCH 35/45] Add link to TODO --- .../client/api/block_builder/input_selection/remainder.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/src/client/api/block_builder/input_selection/remainder.rs b/sdk/src/client/api/block_builder/input_selection/remainder.rs index e9dc415c5b..f3df7027c6 100644 --- a/sdk/src/client/api/block_builder/input_selection/remainder.rs +++ b/sdk/src/client/api/block_builder/input_selection/remainder.rs @@ -15,8 +15,8 @@ use crate::{ types::block::{ address::{Address, Ed25519Address}, output::{ - unlock_condition::AddressUnlockCondition, AccountOutputBuilder, BasicOutputBuilder, MinimumOutputAmount, - NativeTokensBuilder, NftOutputBuilder, Output, + unlock_condition::AddressUnlockCondition, AccountOutputBuilder, BasicOutputBuilder, NativeTokensBuilder, + NftOutputBuilder, Output, }, }, }; @@ -130,7 +130,7 @@ impl InputSelection { input.output_id().transaction_id().slot_index(), self.slot_index, )?; - // TODO rewards + // TODO rewards https://github.com/iotaledger/iota-sdk/issues/1310 } let output_mana = self.outputs.iter().map(|o| o.mana()).sum::() + self.mana_allotments; From 1f57689f88832d40f9e2f8a9b9a782143b2dc4f4 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 15 Jan 2024 14:29:48 +0100 Subject: [PATCH 36/45] Cleanup --- .../client/api/block_builder/input_selection/remainder.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sdk/src/client/api/block_builder/input_selection/remainder.rs b/sdk/src/client/api/block_builder/input_selection/remainder.rs index f3df7027c6..5e6486554e 100644 --- a/sdk/src/client/api/block_builder/input_selection/remainder.rs +++ b/sdk/src/client/api/block_builder/input_selection/remainder.rs @@ -144,6 +144,7 @@ impl InputSelection { let amount_diff = input_amount - output_amount; let mana_diff = input_mana - output_mana; + // If there is only a mana remainder, try to fit it in an automatically transitioned output. if input_amount == output_amount && input_mana != output_mana && native_tokens_diff.is_none() { let output = self .outputs @@ -154,10 +155,11 @@ impl InputSelection { .as_ref() .map(|chain_id| self.automatically_transitioned.contains(chain_id)) .unwrap_or(false) - // Foundries can'ty hold mana so they are not considered here. + // Foundries can't hold mana so they are not considered here. && !output.is_foundry() }) .next(); + if let Some(output) = output { *output = match output { Output::Account(output) => AccountOutputBuilder::from(&*output) @@ -168,9 +170,9 @@ impl InputSelection { .finish_output()?, _ => panic!("only account, nft can be automatically created and can hold mana"), }; - } - return Ok((None, storage_deposit_returns)); + return Ok((None, storage_deposit_returns)); + } } let Some((remainder_address, chain)) = self.get_remainder_address()? else { From 8f6024826843d635d0278b38026d3ef7e9777114 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 15 Jan 2024 14:35:51 +0100 Subject: [PATCH 37/45] Remove TODO --- sdk/src/client/api/block_builder/input_selection/remainder.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/src/client/api/block_builder/input_selection/remainder.rs b/sdk/src/client/api/block_builder/input_selection/remainder.rs index 5e6486554e..651fcfbd00 100644 --- a/sdk/src/client/api/block_builder/input_selection/remainder.rs +++ b/sdk/src/client/api/block_builder/input_selection/remainder.rs @@ -140,7 +140,6 @@ impl InputSelection { return Ok((None, storage_deposit_returns)); } - // TODO underflows? let amount_diff = input_amount - output_amount; let mana_diff = input_mana - output_mana; From bcb04e2deaf816dc6b223be47de53e37fb1c0218 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 15 Jan 2024 14:37:41 +0100 Subject: [PATCH 38/45] add log --- sdk/src/client/api/block_builder/input_selection/remainder.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sdk/src/client/api/block_builder/input_selection/remainder.rs b/sdk/src/client/api/block_builder/input_selection/remainder.rs index 651fcfbd00..efcfa38fed 100644 --- a/sdk/src/client/api/block_builder/input_selection/remainder.rs +++ b/sdk/src/client/api/block_builder/input_selection/remainder.rs @@ -192,8 +192,7 @@ impl InputSelection { let remainder = remainder_builder.finish_output()?; - // TODO add log - log::debug!("Created remainder output of {amount_diff} for {remainder_address:?}"); + log::debug!("Created remainder output of amount {amount_diff} and mana {mana_diff} for {remainder_address:?}"); remainder.verify_storage_deposit(self.protocol_parameters.storage_score_parameters())?; From 4697561e78b7a53dc6d7ff3149fb34b771a77e4a Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 15 Jan 2024 16:49:40 +0100 Subject: [PATCH 39/45] Ok(Selected --- sdk/src/client/api/block_builder/input_selection/mod.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sdk/src/client/api/block_builder/input_selection/mod.rs b/sdk/src/client/api/block_builder/input_selection/mod.rs index df3b6eefa8..dc5b8f27b1 100644 --- a/sdk/src/client/api/block_builder/input_selection/mod.rs +++ b/sdk/src/client/api/block_builder/input_selection/mod.rs @@ -423,7 +423,7 @@ impl InputSelection { self.validate_transitions()?; - let selected = Selected { + Ok(Selected { inputs: Self::sort_input_signing_data( self.selected_inputs, self.slot_index, @@ -431,9 +431,7 @@ impl InputSelection { )?, outputs: self.outputs, remainder, - }; - - Ok(selected) + }) } fn validate_transitions(&self) -> Result<(), Error> { From 877183ebff1c80e873ecbebbe8b89e1b8c8af2e7 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 15 Jan 2024 16:56:34 +0100 Subject: [PATCH 40/45] mana cleanup --- sdk/src/types/block/output/mod.rs | 4 +++- sdk/src/types/block/semantic/mod.rs | 35 +++++------------------------ 2 files changed, 9 insertions(+), 30 deletions(-) diff --git a/sdk/src/types/block/output/mod.rs b/sdk/src/types/block/output/mod.rs index 2d5a9178f5..5c8329af23 100644 --- a/sdk/src/types/block/output/mod.rs +++ b/sdk/src/types/block/output/mod.rs @@ -239,7 +239,9 @@ impl Output { protocol_parameters.generate_mana_with_decay(generation_amount, creation_index, target_index)?; let stored_mana = protocol_parameters.mana_with_decay(mana, creation_index, target_index)?; - Ok(potential_mana + stored_mana) + Ok(potential_mana + .checked_add(stored_mana) + .ok_or(Error::ConsumedManaOverflow)?) } /// Returns the unlock conditions of an [`Output`], if any. diff --git a/sdk/src/types/block/semantic/mod.rs b/sdk/src/types/block/semantic/mod.rs index 0c7a7e8c11..ec8314a402 100644 --- a/sdk/src/types/block/semantic/mod.rs +++ b/sdk/src/types/block/semantic/mod.rs @@ -16,9 +16,7 @@ pub use self::{ }; use crate::types::block::{ address::Address, - output::{ - AccountId, AnchorOutput, ChainId, FoundryId, MinimumOutputAmount, NativeTokens, Output, OutputId, TokenId, - }, + output::{AccountId, AnchorOutput, ChainId, FoundryId, NativeTokens, Output, OutputId, TokenId}, payload::signed_transaction::{Transaction, TransactionCapabilityFlag, TransactionSigningHash}, protocol::ProtocolParameters, unlock::Unlock, @@ -162,34 +160,13 @@ impl<'a> SemanticValidationContext<'a> { .checked_add(amount) .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); - - self.protocol_parameters.generate_mana_with_decay( - 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) + .checked_add(consumed_output.all_mana( + &self.protocol_parameters, + output_id.transaction_id().slot_index(), + self.transaction.creation_slot(), + )?) .ok_or(Error::ConsumedManaOverflow)?; // TODO: Add reward mana https://github.com/iotaledger/iota-sdk/issues/1310 From 5b5d199b5b18f41abac0aeeac9b0f40c83282ccc Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 16 Jan 2024 11:40:47 +0100 Subject: [PATCH 41/45] checked_sub --- .../api/block_builder/input_selection/remainder.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sdk/src/client/api/block_builder/input_selection/remainder.rs b/sdk/src/client/api/block_builder/input_selection/remainder.rs index efcfa38fed..cf59cb044b 100644 --- a/sdk/src/client/api/block_builder/input_selection/remainder.rs +++ b/sdk/src/client/api/block_builder/input_selection/remainder.rs @@ -18,6 +18,7 @@ use crate::{ unlock_condition::AddressUnlockCondition, AccountOutputBuilder, BasicOutputBuilder, NativeTokensBuilder, NftOutputBuilder, Output, }, + Error as BlockError, }, }; @@ -140,8 +141,12 @@ impl InputSelection { return Ok((None, storage_deposit_returns)); } - let amount_diff = input_amount - output_amount; - let mana_diff = input_mana - output_mana; + let amount_diff = input_amount + .checked_sub(output_amount) + .ok_or(BlockError::ConsumedAmountOverflow)?; + let mana_diff = input_mana + .checked_sub(output_mana) + .ok_or(BlockError::ConsumedManaOverflow)?; // If there is only a mana remainder, try to fit it in an automatically transitioned output. if input_amount == output_amount && input_mana != output_mana && native_tokens_diff.is_none() { From 215922565f2701472d8ee73b44607e5c127879c9 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 16 Jan 2024 11:45:20 +0100 Subject: [PATCH 42/45] available_mana --- .../input_selection/remainder.rs | 2 +- sdk/src/types/block/output/mod.rs | 2 +- sdk/src/types/block/semantic/mod.rs | 19 +++++++------------ .../wallet/operations/transaction/account.rs | 2 +- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/sdk/src/client/api/block_builder/input_selection/remainder.rs b/sdk/src/client/api/block_builder/input_selection/remainder.rs index cf59cb044b..af6655f06d 100644 --- a/sdk/src/client/api/block_builder/input_selection/remainder.rs +++ b/sdk/src/client/api/block_builder/input_selection/remainder.rs @@ -126,7 +126,7 @@ impl InputSelection { let mut input_mana = 0; for input in &self.selected_inputs { - input_mana += input.output.all_mana( + input_mana += input.output.available_mana( &self.protocol_parameters, input.output_id().transaction_id().slot_index(), self.slot_index, diff --git a/sdk/src/types/block/output/mod.rs b/sdk/src/types/block/output/mod.rs index 5c8329af23..3faf18b62a 100644 --- a/sdk/src/types/block/output/mod.rs +++ b/sdk/src/types/block/output/mod.rs @@ -218,7 +218,7 @@ impl Output { } /// Returns all the mana held by the output, which is potential + stored, all decayed. - pub fn all_mana( + pub fn available_mana( &self, protocol_parameters: &ProtocolParameters, creation_index: SlotIndex, diff --git a/sdk/src/types/block/semantic/mod.rs b/sdk/src/types/block/semantic/mod.rs index ec8314a402..c6ce5aea43 100644 --- a/sdk/src/types/block/semantic/mod.rs +++ b/sdk/src/types/block/semantic/mod.rs @@ -102,18 +102,13 @@ impl<'a> SemanticValidationContext<'a> { pub fn validate(mut self) -> Result, Error> { // Validation of inputs. for (index, (output_id, consumed_output)) in self.inputs.iter().enumerate() { - let (amount, mana, consumed_native_token, unlock_conditions) = match consumed_output { - Output::Basic(output) => ( - output.amount(), - output.mana(), - output.native_token(), - output.unlock_conditions(), - ), - Output::Account(output) => (output.amount(), output.mana(), None, output.unlock_conditions()), + let (amount, consumed_native_token, unlock_conditions) = match consumed_output { + Output::Basic(output) => (output.amount(), output.native_token(), output.unlock_conditions()), + Output::Account(output) => (output.amount(), None, output.unlock_conditions()), Output::Anchor(_) => return Err(Error::UnsupportedOutputKind(AnchorOutput::KIND)), - Output::Foundry(output) => (output.amount(), 0, output.native_token(), output.unlock_conditions()), - Output::Nft(output) => (output.amount(), output.mana(), None, output.unlock_conditions()), - Output::Delegation(output) => (output.amount(), 0, None, output.unlock_conditions()), + Output::Foundry(output) => (output.amount(), output.native_token(), output.unlock_conditions()), + Output::Nft(output) => (output.amount(), None, output.unlock_conditions()), + Output::Delegation(output) => (output.amount(), None, output.unlock_conditions()), }; let commitment_slot_index = self @@ -162,7 +157,7 @@ impl<'a> SemanticValidationContext<'a> { self.input_mana = self .input_mana - .checked_add(consumed_output.all_mana( + .checked_add(consumed_output.available_mana( &self.protocol_parameters, output_id.transaction_id().slot_index(), self.transaction.creation_slot(), diff --git a/sdk/src/wallet/operations/transaction/account.rs b/sdk/src/wallet/operations/transaction/account.rs index c0d406a25c..86fe03bfbb 100644 --- a/sdk/src/wallet/operations/transaction/account.rs +++ b/sdk/src/wallet/operations/transaction/account.rs @@ -87,7 +87,7 @@ where let account_id = AccountId::from(output_id); let account = AccountOutput::build_with_amount(implicit_account.amount(), account_id) - .with_mana(implicit_account_data.output.all_mana( + .with_mana(implicit_account_data.output.available_mana( &self.client().get_protocol_parameters().await?, implicit_account_data.output_id.transaction_id().slot_index(), self.client().get_slot_index().await?, From 25370d780ec653698b0cae744f73d9529c84aa4d Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 16 Jan 2024 14:47:56 +0100 Subject: [PATCH 43/45] Prefer accounts --- .../input_selection/remainder.rs | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/sdk/src/client/api/block_builder/input_selection/remainder.rs b/sdk/src/client/api/block_builder/input_selection/remainder.rs index af6655f06d..e572fc1ad8 100644 --- a/sdk/src/client/api/block_builder/input_selection/remainder.rs +++ b/sdk/src/client/api/block_builder/input_selection/remainder.rs @@ -150,22 +150,23 @@ impl InputSelection { // If there is only a mana remainder, try to fit it in an automatically transitioned output. if input_amount == output_amount && input_mana != output_mana && native_tokens_diff.is_none() { - let output = self + let filter = |output: &Output| { + output + .chain_id() + .as_ref() + .map(|chain_id| self.automatically_transitioned.contains(chain_id)) + .unwrap_or(false) + // Foundries can't hold mana so they are not considered here. + && !output.is_foundry() + }; + let index = self .outputs - .iter_mut() - .filter(|output| { - output - .chain_id() - .as_ref() - .map(|chain_id| self.automatically_transitioned.contains(chain_id)) - .unwrap_or(false) - // Foundries can't hold mana so they are not considered here. - && !output.is_foundry() - }) - .next(); - - if let Some(output) = output { - *output = match output { + .iter() + .position(|output| filter(output) && output.is_account()) + .or_else(|| self.outputs.iter().position(filter)); + + if let Some(index) = index { + self.outputs[index] = match &self.outputs[index] { Output::Account(output) => AccountOutputBuilder::from(&*output) .with_mana(output.mana() + mana_diff) .finish_output()?, From 8479a5cda36f44719ce7b9fd2ea2767f2e58312f Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 16 Jan 2024 15:31:52 +0100 Subject: [PATCH 44/45] Remove cloned --- sdk/src/wallet/operations/transaction/account.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/src/wallet/operations/transaction/account.rs b/sdk/src/wallet/operations/transaction/account.rs index 86fe03bfbb..72d6ec29c2 100644 --- a/sdk/src/wallet/operations/transaction/account.rs +++ b/sdk/src/wallet/operations/transaction/account.rs @@ -51,12 +51,10 @@ where where crate::wallet::Error: From, { - let implicit_account_data = self - .data() - .await + let wallet_data = self.data().await; + let implicit_account_data = wallet_data .unspent_outputs .get(output_id) - .cloned() .ok_or(Error::ImplicitAccountNotFound)?; let implicit_account = if implicit_account_data.output.is_implicit_account() { implicit_account_data.output.as_basic() @@ -104,6 +102,8 @@ where )?]) .finish_output()?; + drop(wallet_data); + // TODO https://github.com/iotaledger/iota-sdk/issues/1740 let issuance = self.client().get_issuance().await?; From 0cee21d7bd035575c907f22c400f0aab3b512684 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 16 Jan 2024 16:15:28 +0100 Subject: [PATCH 45/45] move up --- .../wallet/operations/transaction/account.rs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/sdk/src/wallet/operations/transaction/account.rs b/sdk/src/wallet/operations/transaction/account.rs index 72d6ec29c2..c95a826b17 100644 --- a/sdk/src/wallet/operations/transaction/account.rs +++ b/sdk/src/wallet/operations/transaction/account.rs @@ -51,17 +51,6 @@ where where crate::wallet::Error: From, { - let wallet_data = self.data().await; - let implicit_account_data = wallet_data - .unspent_outputs - .get(output_id) - .ok_or(Error::ImplicitAccountNotFound)?; - let implicit_account = if implicit_account_data.output.is_implicit_account() { - implicit_account_data.output.as_basic() - } else { - return Err(Error::ImplicitAccountNotFound); - }; - let key_source = match key_source.map(Into::into) { Some(key_source) => key_source, None => self.bip_path().await.ok_or(Error::MissingBipPath)?.into(), @@ -83,6 +72,17 @@ where } }; + let wallet_data = self.data().await; + let implicit_account_data = wallet_data + .unspent_outputs + .get(output_id) + .ok_or(Error::ImplicitAccountNotFound)?; + let implicit_account = if implicit_account_data.output.is_implicit_account() { + implicit_account_data.output.as_basic() + } else { + return Err(Error::ImplicitAccountNotFound); + }; + let account_id = AccountId::from(output_id); let account = AccountOutput::build_with_amount(implicit_account.amount(), account_id) .with_mana(implicit_account_data.output.available_mana(