From 019d3487d3002f1bdb9bbcaf19a237d482d5058d Mon Sep 17 00:00:00 2001 From: DaughterOfMars Date: Thu, 11 Jan 2024 12:36:54 -0500 Subject: [PATCH 1/2] Add mana semantic validation (#1700) * validate some mana semantics * Cleanup * delta->diff * Nit * Allow passing an index for test inputs IDs * Fix tests * rand nit * Simplify tests * Add link to issue * Update sdk/src/types/block/semantic/mod.rs Co-authored-by: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> * Format --------- Co-authored-by: Thibault Martinez Co-authored-by: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> Co-authored-by: /alex/ --- bindings/core/src/method/secret_manager.rs | 2 +- sdk/src/types/block/error.rs | 6 +- sdk/src/types/block/mana/parameters.rs | 36 +- sdk/src/types/block/rand/transaction.rs | 13 +- sdk/src/types/block/semantic/mod.rs | 61 +- .../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 | 56 +- sdk/tests/client/signing/basic.rs | 152 +- sdk/tests/client/signing/mod.rs | 249 +-- sdk/tests/client/signing/nft.rs | 38 +- 18 files changed, 2987 insertions(+), 2468 deletions(-) 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)] diff --git a/sdk/src/types/block/error.rs b/sdk/src/types/block/error.rs index 6e293465ad..672be985dc 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, }, @@ -429,8 +429,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"), Self::RestrictedAddressCapability(cap) => write!(f, "restricted address capability: {cap:?}"), diff --git a/sdk/src/types/block/mana/parameters.rs b/sdk/src/types/block/mana/parameters.rs index e6d68aa698..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,13 +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(), ) } @@ -116,17 +117,18 @@ 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, }); } + Ok(self .mana_parameters() .decay(mana, epoch_index_target.0 - epoch_index_created.0)) @@ -140,12 +142,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 { + return Err(Error::InvalidEpochDiff { created: reward_epoch, target: claimed_epoch, }); } + Ok(self.mana_parameters().decay(reward, claimed_epoch.0 - reward_epoch.0)) } @@ -162,8 +166,9 @@ 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 { + return Err(Error::InvalidEpochDiff { created: epoch_index_created, target: epoch_index_target, }); @@ -171,6 +176,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 { @@ -189,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 @@ -290,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() }) @@ -349,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() }) diff --git a/sdk/src/types/block/rand/transaction.rs b/sdk/src/types/block/rand/transaction.rs index 20036d143b..5a12cdcac1 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, number::rand_number}, + slot::SlotIndex, +}; + +/// 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 { - TransactionId::new(rand_bytes_array()) + rand_transaction_id_with_slot_index(rand_number::()) } diff --git a/sdk/src/types/block/semantic/mod.rs b/sdk/src/types/block/semantic/mod.rs index 109915b869..e9bf091ef3 100644 --- a/sdk/src/types/block/semantic/mod.rs +++ b/sdk/src/types/block/semantic/mod.rs @@ -16,7 +16,9 @@ pub use self::{ }; use crate::types::block::{ address::Address, - output::{AccountId, AnchorOutput, ChainId, FoundryId, NativeTokens, Output, OutputId, TokenId}, + output::{ + AccountId, AnchorOutput, ChainId, FoundryId, MinimumOutputAmount, NativeTokens, Output, OutputId, TokenId, + }, payload::signed_transaction::{Transaction, TransactionCapabilityFlag, TransactionSigningHash}, protocol::ProtocolParameters, unlock::Unlock, @@ -160,7 +162,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 = { + // 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.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 https://github.com/iotaledger/iota-sdk/issues/1310 if let Some(consumed_native_token) = consumed_native_token { let native_token_amount = self @@ -221,8 +253,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 @@ -251,11 +292,17 @@ 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 && - // !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 { + if !self.transaction.has_capability(TransactionCapabilityFlag::BurnMana) { + return Ok(Some( + TransactionFailureReason::TransactionCapabilityManaBurningNotAllowed, + )); + } + } else { + return Ok(Some(TransactionFailureReason::InvalidManaAmount)); + } + } // Validation of input native tokens. let mut native_token_ids = self.input_native_tokens.keys().collect::>(); 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..a97ed6d29e 100644 --- a/sdk/tests/client/signing/account.rs +++ b/sdk/tests/client/signing/account.rs @@ -20,7 +20,7 @@ use iota_sdk::{ output::AccountId, payload::{signed_transaction::Transaction, SignedTransactionPayload}, protocol::protocol_parameters, - rand::mana::rand_mana_allotment, + slot::SlotIndex, unlock::{SignatureUnlock, Unlock}, }, }; @@ -48,15 +48,19 @@ 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( - 1_000_000, - account_id, - address.clone(), - None, - None, - Some(Bip44::new(SHIMMER_COIN_TYPE)), - )]); + let inputs = build_inputs( + [Account( + 1_000_000, + account_id, + address.clone(), + None, + None, + Some(Bip44::new(SHIMMER_COIN_TYPE)), + )], + Some(slot_index), + ); let outputs = build_outputs([Account(1_000_000, account_id, address.clone(), None, None, None)]); @@ -68,7 +72,7 @@ async fn sign_account_state_transition() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) + .with_creation_slot(slot_index + 1) .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { @@ -114,19 +118,23 @@ 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 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 slot_index = SlotIndex::from(10); + + 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), + ], + Some(slot_index), + ); let outputs = build_outputs([ Account(1_000_000, account_id, address, None, None, None), @@ -141,7 +149,7 @@ async fn account_reference_unlocks() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) + .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 ba9a2eb5b0..07b7a4144d 100644 --- a/sdk/tests/client/signing/basic.rs +++ b/sdk/tests/client/signing/basic.rs @@ -16,7 +16,7 @@ use iota_sdk::{ input::{Input, UtxoInput}, payload::{signed_transaction::Transaction, SignedTransactionPayload}, protocol::protocol_parameters, - rand::mana::rand_mana_allotment, + slot::SlotIndex, unlock::{SignatureUnlock, Unlock}, }, }; @@ -39,17 +39,21 @@ async fn single_ed25519_unlock() -> Result<()> { .into_inner(); let protocol_parameters = protocol_parameters(); + let slot_index = SlotIndex::from(10); - let inputs = build_inputs([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)), + )], + Some(slot_index), + ); let outputs = build_outputs([Basic( 1_000_000, @@ -70,7 +74,7 @@ async fn single_ed25519_unlock() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) + .with_creation_slot(slot_index + 1) .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { @@ -114,39 +118,43 @@ async fn ed25519_reference_unlocks() -> Result<()> { .into_inner(); 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 slot_index = SlotIndex::from(10); + + 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)), + ), + ], + Some(slot_index), + ); let outputs = build_outputs([Basic( 3_000_000, @@ -167,7 +175,7 @@ async fn ed25519_reference_unlocks() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) + .with_creation_slot(slot_index + 1) .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { @@ -232,29 +240,33 @@ async fn two_signature_unlocks() -> Result<()> { .into_inner(); 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 slot_index = SlotIndex::from(10); + + 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)), + ), + ], + Some(slot_index), + ); let outputs = build_outputs([Basic( 2_000_000, @@ -275,7 +287,7 @@ async fn two_signature_unlocks() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) + .with_creation_slot(slot_index + 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..dc38b1fd3d 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,130 @@ 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 slot_index = SlotIndex::from(90); + + 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, + ), + ], + Some(slot_index), + ); let outputs = build_outputs([ Account(1_000_000, account_id_1, nft_1, None, None, None), @@ -202,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(), @@ -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..72b4c4d374 100644 --- a/sdk/tests/client/signing/nft.rs +++ b/sdk/tests/client/signing/nft.rs @@ -20,7 +20,7 @@ use iota_sdk::{ output::NftId, payload::{signed_transaction::Transaction, SignedTransactionPayload}, protocol::protocol_parameters, - rand::mana::rand_mana_allotment, + slot::SlotIndex, unlock::{SignatureUnlock, Unlock}, }, }; @@ -49,21 +49,25 @@ 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 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 slot_index = SlotIndex::from(10); + + 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), + ], + Some(slot_index), + ); let outputs = build_outputs([ Nft(1_000_000, nft_id, address_0, None, None, None, None, None), @@ -78,7 +82,7 @@ async fn nft_reference_unlocks() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) + .with_creation_slot(slot_index + 1) .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { From fe776bdf92df231d1bd139cf3a0b20317db44b62 Mon Sep 17 00:00:00 2001 From: DaughterOfMars Date: Fri, 12 Jan 2024 04:19:10 -0500 Subject: [PATCH 2/2] Update mana calculations from iota.go (#1833) * Update mana calculations from iota.go * fix calculation * feature gate powf * new lines --------- Co-authored-by: Thibault Martinez --- sdk/src/types/block/mana/parameters.rs | 433 ++++++++++++++++--------- sdk/src/types/block/protocol/mod.rs | 40 +++ sdk/src/types/block/semantic/mod.rs | 2 +- 3 files changed, 323 insertions(+), 152 deletions(-) diff --git a/sdk/src/types/block/mana/parameters.rs b/sdk/src/types/block/mana/parameters.rs index 127e0b2320..e9e8469489 100644 --- a/sdk/src/types/block/mana/parameters.rs +++ b/sdk/src/types/block/mana/parameters.rs @@ -53,6 +53,11 @@ impl ManaParameters { self.decay_factors.get(*epoch_index.into() as usize).copied() } + /// Returns the annual decay factor. + pub fn annual_decay_factor(&self) -> f64 { + self.annual_decay_factor_percentage() as f64 / 100.0 + } + /// Returns the max mana that can exist with the mana bits defined. pub fn max_mana(&self) -> u64 { (1 << self.bits_count) - 1 @@ -155,7 +160,7 @@ impl ProtocolParameters { /// Calculates the potential mana that is generated by holding `amount` tokens from `slot_index_created` to /// `slot_index_target` and applies the decay to the result - pub fn potential_mana( + pub fn generate_mana_with_decay( &self, amount: u64, slot_index_created: impl Into, @@ -182,30 +187,29 @@ impl ProtocolParameters { Ok(if epoch_index_created == epoch_index_target { mana_parameters.generate_mana(amount, slot_index_target.0 - slot_index_created.0) } else if epoch_index_target == epoch_index_created + 1 { - 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 mana_decayed = - mana_parameters.decay(mana_parameters.generate_mana(amount, slots_before_next_epoch.0), 1); - let mana_generated = mana_parameters.generate_mana(amount, slots_since_epoch_start.0); - mana_decayed + mana_generated + let mana_generated_first_epoch = + mana_parameters.generate_mana(amount, self.slots_before_next_epoch(slot_index_created)); + let mana_decayed_first_epoch = mana_parameters.decay(mana_generated_first_epoch, 1); + let mana_generated_second_epoch = + mana_parameters.generate_mana(amount, self.slots_since_epoch_start(slot_index_target)); + mana_decayed_first_epoch + mana_generated_second_epoch } else { + let mana_generated_first_epoch = + mana_parameters.generate_mana(amount, self.slots_before_next_epoch(slot_index_created)); + let mana_decayed_first_epoch = + mana_parameters.decay(mana_generated_first_epoch, epoch_index_target.0 - epoch_index_created.0); let c = fixed_point_multiply( amount, mana_parameters.decay_factor_epochs_sum() * mana_parameters.generation_rate() as u32, mana_parameters.decay_factor_epochs_sum_exponent() + mana_parameters.generation_rate_exponent() - self.slots_per_epoch_exponent(), ); - 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_diff, - ); - 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 + let mana_decayed_intermediate_epochs = + c - mana_parameters.decay(c, epoch_index_target.0 - epoch_index_created.0 - 1); + let mana_generated_last_epoch = + mana_parameters.generate_mana(amount, self.slots_since_epoch_start(slot_index_target)); + mana_decayed_intermediate_epochs + mana_generated_last_epoch + mana_decayed_first_epoch + - (c >> mana_parameters.decay_factors_exponent()) }) } } @@ -223,32 +227,33 @@ mod test { // Tests from https://github.com/iotaledger/iota.go/blob/develop/mana_decay_provider_test.go - const BETA_PER_YEAR: f64 = 1. / 3.; - fn params() -> &'static ProtocolParameters { use once_cell::sync::Lazy; static PARAMS: Lazy = Lazy::new(|| { let mut params = ProtocolParameters { + genesis_slot: 0, + genesis_unix_timestamp: time::OffsetDateTime::now_utc().unix_timestamp() as _, slots_per_epoch_exponent: 13, slot_duration_in_seconds: 10, + token_supply: 1813620509061365, mana_parameters: ManaParameters { bits_count: 63, generation_rate: 1, - generation_rate_exponent: 27, + generation_rate_exponent: 17, decay_factors_exponent: 32, - decay_factor_epochs_sum_exponent: 20, + decay_factor_epochs_sum_exponent: 21, + annual_decay_factor_percentage: 70, ..Default::default() }, ..Default::default() }; params.mana_parameters.decay_factors = { - let epochs_per_year = ((365_u64 * 24 * 60 * 60) as f64 / params.slot_duration_in_seconds() as f64) - / params.slots_per_epoch() as f64; - let beta_per_epoch_index = BETA_PER_YEAR / epochs_per_year; - (1..=epochs_per_year.floor() as usize) + let epochs_in_table = (u16::MAX as usize).min(params.epochs_per_year().floor() as usize); + let decay_per_epoch = params.decay_per_epoch(); + (1..=epochs_in_table) .map(|epoch| { - ((-beta_per_epoch_index * epoch as f64).exp() - * (params.mana_parameters().decay_factors_exponent() as f64).exp2()) + (decay_per_epoch.powi(epoch as _) + * 2f64.powi(params.mana_parameters().decay_factors_exponent() as _)) .floor() as u32 }) .collect::>() @@ -256,11 +261,11 @@ mod test { .try_into() .unwrap(); params.mana_parameters.decay_factor_epochs_sum = { - let delta = params.slots_per_epoch() as f64 * params.slot_duration_in_seconds() as f64 - / (365_u64 * 24 * 60 * 60) as f64; - (((-BETA_PER_YEAR * delta).exp() / (1. - (-BETA_PER_YEAR * delta).exp())) - * (params.mana_parameters().decay_factor_epochs_sum_exponent() as f64).exp2()) - .floor() as u32 + let delta = params.epochs_per_year().recip(); + let annual_decay_factor = params.mana_parameters().annual_decay_factor(); + (annual_decay_factor.powf(delta) / (1.0 - annual_decay_factor.powf(delta)) + * (2f64.powi(params.mana_parameters().decay_factor_epochs_sum_exponent() as _))) + .floor() as _ }; params }); @@ -276,145 +281,271 @@ mod test { assert_eq!(mana_parameters.decay(100, 100), 100); } - #[test] - fn mana_decay_no_delta() { - assert_eq!( - params().mana_with_decay(100, params().first_slot_of(1), params().first_slot_of(1)), - Ok(100) - ); - } - - #[test] - fn mana_decay_no_mana() { - assert_eq!( - params().mana_with_decay(0, params().first_slot_of(1), params().first_slot_of(400)), - Ok(0) - ); - } - - #[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::InvalidEpochDiff { - created: 2.into(), - target: 1.into() - }) - ); - } - - #[test] - fn mana_decay_lookup_len_delta() { - assert_eq!( - params().mana_with_decay( - u64::MAX, - params().first_slot_of(1), - params().first_slot_of(params().mana_parameters().decay_factors().len() as u32 + 1) - ), - Ok(13228672242897911807) - ); - } - - #[test] - fn mana_decay_lookup_len_delta_multiple() { - assert_eq!( - params().mana_with_decay( - u64::MAX, - params().first_slot_of(1), - params().first_slot_of(3 * params().mana_parameters().decay_factors().len() as u32 + 1) - ), - Ok(6803138682699798504) - ); - } - - #[test] - fn mana_decay_max_mana() { - assert_eq!( - params().mana_with_decay(u64::MAX, params().first_slot_of(1), params().first_slot_of(401)), - Ok(13046663022640287317) - ); + struct ManaDecayTest { + name: &'static str, + stored_mana: u64, + created_slot: SlotIndex, + target_slot: SlotIndex, + err: Option, } #[test] - fn potential_mana_no_delta() { - assert_eq!( - params().potential_mana(100, params().first_slot_of(1), params().first_slot_of(1)), - Ok(0) - ); + fn mana_decay() { + let tests = [ + ManaDecayTest { + name: "check if mana decay works for 0 mana values", + stored_mana: 0, + created_slot: params().first_slot_of(1), + target_slot: params().first_slot_of(400), + err: None, + }, + ManaDecayTest { + name: "check if mana decay works for 0 slot index diffs", + stored_mana: u64::MAX, + created_slot: params().first_slot_of(1), + target_slot: params().first_slot_of(1), + err: None, + }, + ManaDecayTest { + name: "check for error if target index is lower than created index", + stored_mana: 0, + created_slot: params().first_slot_of(2), + target_slot: params().first_slot_of(1), + err: Some(Error::InvalidEpochDiff { + created: 2.into(), + target: 1.into(), + }), + }, + ManaDecayTest { + name: "check if mana decay works for exactly the amount of epochs in the lookup table", + stored_mana: u64::MAX, + created_slot: params().first_slot_of(1), + target_slot: params().first_slot_of(params().mana_parameters().decay_factors().len() as u32 + 1), + err: None, + }, + ManaDecayTest { + name: "check if mana decay works for multiples of the available epochs in the lookup table", + stored_mana: u64::MAX, + created_slot: params().first_slot_of(1), + target_slot: params().first_slot_of(3 * params().mana_parameters().decay_factors().len() as u32 + 1), + err: None, + }, + ManaDecayTest { + name: "even with the highest possible uint64 number, the calculation should not overflow", + stored_mana: u64::MAX, + created_slot: params().first_slot_of(1), + target_slot: params().first_slot_of(401), + err: None, + }, + ]; + + for ManaDecayTest { + name, + stored_mana, + created_slot, + target_slot, + err, + } in tests + { + let result = params().mana_with_decay(stored_mana, created_slot, target_slot); + if let Some(err) = err { + assert_eq!(result, Err(err), "{name}"); + } else { + let result = result.map_err(|e| format!("{name}: {e}")).unwrap(); + let upper_bound = upper_bound_mana_decay(stored_mana, created_slot, target_slot); + let lower_bound = lower_bound_mana_decay(stored_mana, created_slot, target_slot); + + assert!( + result as f64 <= upper_bound, + "{name}: result {result} above upper bound {upper_bound}", + ); + assert!( + result as f64 >= lower_bound, + "{name}: result {result} below lower bound {upper_bound}", + ); + } + } } - #[test] - fn potential_mana_no_mana() { - assert_eq!( - params().potential_mana(0, params().first_slot_of(1), params().first_slot_of(400)), - Ok(0) - ); + struct ManaGenerationTest { + name: &'static str, + amount: u64, + created_slot: SlotIndex, + target_slot: SlotIndex, + err: Option, } #[test] - fn potential_mana_negative_delta() { - assert_eq!( - params().potential_mana(100, params().first_slot_of(2), params().first_slot_of(1)), - Err(Error::InvalidEpochDiff { - created: 2.into(), - target: 1.into() - }) - ); + fn mana_generation() { + let tests = [ + ManaGenerationTest { + name: "check if mana generation works for 0 mana values", + amount: 0, + created_slot: params().first_slot_of(1), + target_slot: params().first_slot_of(400), + err: None, + }, + ManaGenerationTest { + name: "check if mana generation works for 0 slot index diffs", + amount: i64::MAX as _, + created_slot: params().first_slot_of(1), + target_slot: params().first_slot_of(1), + err: None, + }, + ManaGenerationTest { + name: "check for error if target index is lower than created index", + amount: 0, + created_slot: params().first_slot_of(2), + target_slot: params().first_slot_of(1), + err: Some(Error::InvalidEpochDiff { + created: 2.into(), + target: 1.into(), + }), + }, + ManaGenerationTest { + name: "check if mana generation works for exactly the amount of epochs in the lookup table", + amount: params().token_supply(), + created_slot: params().first_slot_of(1), + target_slot: params().first_slot_of(params().mana_parameters().decay_factors().len() as u32 + 1), + err: None, + }, + ManaGenerationTest { + name: "check if mana generation works for multiples of the available epochs in the lookup table", + amount: params().token_supply(), + created_slot: params().first_slot_of(1), + target_slot: params().first_slot_of(3 * params().mana_parameters().decay_factors().len() as u32 + 1), + err: None, + }, + ManaGenerationTest { + name: "check if mana generation works for 0 epoch diffs", + amount: params().token_supply(), + created_slot: params().first_slot_of(1), + target_slot: params().last_slot_of(1), + err: None, + }, + ManaGenerationTest { + name: "check if mana generation works for 1 epoch diffs", + amount: params().token_supply(), + created_slot: params().first_slot_of(1), + target_slot: params().last_slot_of(2), + err: None, + }, + ManaGenerationTest { + name: "check if mana generation works for >=2 epoch diffs", + amount: params().token_supply(), + created_slot: params().first_slot_of(1), + target_slot: params().last_slot_of(3), + err: None, + }, + ]; + + for ManaGenerationTest { + name, + amount, + created_slot, + target_slot, + err, + } in tests + { + let result = params().generate_mana_with_decay(amount, created_slot, target_slot); + if let Some(err) = err { + assert_eq!(result, Err(err), "{name}"); + } else { + let result = result.map_err(|e| format!("{name}: {e}")).unwrap(); + let upper_bound = upper_bound_mana_generation(amount, created_slot, target_slot); + let lower_bound = lower_bound_mana_generation(amount, created_slot, target_slot); + + assert!( + result as f64 <= upper_bound, + "{name}: result {result} above upper bound {upper_bound}", + ); + assert!( + result as f64 >= lower_bound, + "{name}: result {result} below lower bound {upper_bound}", + ); + + if result != 0 { + let float_res = mana_generation_with_decay_float(amount as _, created_slot, target_slot); + let epsilon = 0.001; + let allowed_delta = float_res.abs().min(result as f64) * epsilon; + let dt = float_res - result as f64; + assert!( + dt >= -allowed_delta && dt <= allowed_delta, + "{name}: fixed point result varies too greatly from float result" + ); + } + } + } } - #[test] - fn potential_mana_lookup_len_delta() { - assert_eq!( - params().potential_mana( - i64::MAX as u64, - params().first_slot_of(1), - params().first_slot_of(params().mana_parameters().decay_factors().len() as u32 + 1) - ), - Ok(183827295065703076) + fn mana_decay_float(mana: f64, creation_slot: SlotIndex, target_slot: SlotIndex) -> f64 { + let (creation_epoch, target_epoch) = ( + params().epoch_index_of(creation_slot), + params().epoch_index_of(target_slot), ); + mana * params() + .decay_per_epoch() + .powi((target_epoch.0 - creation_epoch.0) as _) } - #[test] - fn potential_mana_lookup_len_delta_multiple() { - assert_eq!( - params().potential_mana( - i64::MAX as u64, - params().first_slot_of(1), - params().first_slot_of(3 * params().mana_parameters().decay_factors().len() as u32 + 1) - ), - Ok(410192223115924783) + fn mana_generation_with_decay_float(amount: f64, creation_slot: SlotIndex, target_slot: SlotIndex) -> f64 { + let (creation_epoch, target_epoch) = ( + params().epoch_index_of(creation_slot), + params().epoch_index_of(target_slot), ); + let decay_per_epoch = params().decay_per_epoch(); + let generation_rate = params().mana_parameters().generation_rate() as f64 + * 2f64.powi(-(params().mana_parameters().generation_rate_exponent() as i32)); + + if creation_epoch == target_epoch { + (target_slot.0 - creation_slot.0) as f64 * amount * generation_rate + } else if target_epoch == creation_epoch + 1 { + let slots_before_next_epoch = params().slots_before_next_epoch(creation_slot); + let slots_since_epoch_start = params().slots_since_epoch_start(target_slot); + let mana_decayed = slots_before_next_epoch as f64 * amount * generation_rate * decay_per_epoch; + let mana_generated = slots_since_epoch_start as f64 * amount * generation_rate; + mana_decayed + mana_generated + } else { + let slots_before_next_epoch = params().slots_before_next_epoch(creation_slot); + let slots_since_epoch_start = params().slots_since_epoch_start(target_slot); + let c = decay_per_epoch * (1.0 - decay_per_epoch.powi((target_epoch.0 - creation_epoch.0) as i32 - 1)) + / (1.0 - decay_per_epoch); + let potential_mana_n = slots_before_next_epoch as f64 + * amount + * generation_rate + * decay_per_epoch.powi((target_epoch.0 - creation_epoch.0) as i32); + let potential_mana_n_1 = c * amount * generation_rate * params().slots_per_epoch() as f64; + let potential_mana_0 = slots_since_epoch_start as f64 * amount * generation_rate; + potential_mana_n + potential_mana_n_1 + potential_mana_0 + } } - #[test] - fn potential_mana_same_epoch() { - assert_eq!( - params().potential_mana(i64::MAX as u64, params().first_slot_of(1), params().last_slot_of(1)), - Ok(562881233944575) - ); + fn upper_bound_mana_decay(mana: u64, creation_slot: SlotIndex, target_slot: SlotIndex) -> f64 { + mana_decay_float(mana as _, creation_slot, target_slot) } - #[test] - fn potential_mana_one_epoch() { - assert_eq!( - params().potential_mana(i64::MAX as u64, params().first_slot_of(1), params().last_slot_of(2)), - Ok(1125343946211326) - ); + fn lower_bound_mana_decay(mana: u64, creation_slot: SlotIndex, target_slot: SlotIndex) -> f64 { + mana_decay_float(mana as _, creation_slot, target_slot) + - (mana as f64 * 2f64.powi(-(params().mana_parameters().decay_factors_exponent() as i32)) + 1.0) } - #[test] - fn potential_mana_several_epochs() { - assert_eq!( - params().potential_mana(i64::MAX as u64, params().first_slot_of(1), params().last_slot_of(3)), - Ok(1687319824887185) - ); + fn upper_bound_mana_generation(amount: u64, creation_slot: SlotIndex, target_slot: SlotIndex) -> f64 { + mana_generation_with_decay_float(amount as _, creation_slot, target_slot) + 2.0 + - 2f64.powi(-(params().mana_parameters().decay_factors_exponent() as i32) - 1) } - #[test] - fn potential_mana_max_mana() { - assert_eq!( - params().potential_mana(i64::MAX as u64, params().first_slot_of(1), params().first_slot_of(401)), - Ok(190239292388858706) - ); + fn lower_bound_mana_generation(amount: u64, creation_slot: SlotIndex, target_slot: SlotIndex) -> f64 { + let decay_per_epoch = params().decay_per_epoch(); + let c = decay_per_epoch / (1.0 - decay_per_epoch); + + mana_generation_with_decay_float(amount as _, creation_slot, target_slot) + - (4.0 + + amount as f64 + * params().mana_parameters().generation_rate() as f64 + * 2f64.powi( + params().slots_per_epoch_exponent() as i32 + - params().mana_parameters().generation_rate_exponent() as i32, + ) + * (1.0 + c * 2f64.powi(-(params().mana_parameters().decay_factors_exponent() as i32)))) } } diff --git a/sdk/src/types/block/protocol/mod.rs b/sdk/src/types/block/protocol/mod.rs index adc9b1e9c7..d2ee4ca4b5 100644 --- a/sdk/src/types/block/protocol/mod.rs +++ b/sdk/src/types/block/protocol/mod.rs @@ -202,11 +202,51 @@ impl ProtocolParameters { epoch_index.into().last_slot_index(self.slots_per_epoch_exponent()) } + /// Calculates the number of slots before the next epoch. + pub fn slots_before_next_epoch(&self, slot_index: impl Into) -> u32 { + let slot_index = slot_index.into(); + + if slot_index.0 < self.genesis_slot() { + 0 + } else { + self.genesis_slot() + self.first_slot_of(self.epoch_index_of(slot_index) + 1).0 - slot_index.0 + } + } + + /// Calculates the number of slots since the start of the epoch. + pub fn slots_since_epoch_start(&self, slot_index: impl Into) -> u32 { + let slot_index = slot_index.into(); + + if slot_index.0 < self.genesis_slot() { + 0 + } else { + self.genesis_slot() + slot_index.0 - self.first_slot_of(self.epoch_index_of(slot_index)).0 + } + } + /// Gets the [`EpochIndex`] of a given [`SlotIndex`]. pub fn epoch_index_of(&self, slot_index: impl Into) -> EpochIndex { EpochIndex::from_slot_index(slot_index.into(), self.slots_per_epoch_exponent()) } + /// Calculates the duration of an epoch in seconds. + pub fn epoch_duration_in_seconds(&self) -> u64 { + self.slot_duration_in_seconds() as u64 * self.slots_per_epoch() as u64 + } + + /// Calculates the number of epochs per year. + pub fn epochs_per_year(&self) -> f64 { + (365_u64 * 24 * 60 * 60) as f64 / self.epoch_duration_in_seconds() as f64 + } + + /// Calculates the decay per epoch based on the annual decay factor and number of epochs in a year. + #[cfg(feature = "std")] + pub fn decay_per_epoch(&self) -> f64 { + self.mana_parameters() + .annual_decay_factor() + .powf(self.epochs_per_year().recip()) + } + /// Returns the hash of the [`ProtocolParameters`]. pub fn hash(&self) -> ProtocolParametersHash { ProtocolParametersHash::new(Blake2b256::digest(self.pack_to_vec()).into()) diff --git a/sdk/src/types/block/semantic/mod.rs b/sdk/src/types/block/semantic/mod.rs index e9bf091ef3..0c7a7e8c11 100644 --- a/sdk/src/types/block/semantic/mod.rs +++ b/sdk/src/types/block/semantic/mod.rs @@ -167,7 +167,7 @@ impl<'a> SemanticValidationContext<'a> { 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( + self.protocol_parameters.generate_mana_with_decay( generation_amount, output_id.transaction_id().slot_index(), self.transaction.creation_slot(),