From 01e0286165e44ddbd8d8b32d2f5bb316697558d1 Mon Sep 17 00:00:00 2001 From: Alexandcoats Date: Fri, 8 Sep 2023 11:54:31 -0400 Subject: [PATCH] Add mana structure and fix max mana checks (#1145) * add mana structure and fix max mana checks * fix block ID test * suggestions * feature gate * renames --------- Co-authored-by: Thibault Martinez --- sdk/src/types/block/error.rs | 9 +- sdk/src/types/block/mana/allotment.rs | 76 +++++++++-------- sdk/src/types/block/mana/mod.rs | 85 +++++++++++-------- sdk/src/types/block/mana/protocol.rs | 67 +++++++++++++++ .../payload/transaction/essence/regular.rs | 21 +++-- sdk/src/types/block/protocol.rs | 43 ++-------- sdk/src/types/block/rand/mana.rs | 12 ++- sdk/src/wallet/account/mod.rs | 2 +- sdk/tests/client/signing/account.rs | 6 +- sdk/tests/client/signing/basic.rs | 6 +- sdk/tests/client/signing/mod.rs | 2 +- sdk/tests/client/signing/nft.rs | 2 +- sdk/tests/types/block_id.rs | 4 +- sdk/tests/types/payload.rs | 2 +- sdk/tests/types/transaction_essence.rs | 2 +- sdk/tests/types/transaction_payload.rs | 8 +- .../types/transaction_regular_essence.rs | 32 +++---- sdk/tests/wallet/events.rs | 2 +- 18 files changed, 232 insertions(+), 149 deletions(-) create mode 100644 sdk/src/types/block/mana/protocol.rs diff --git a/sdk/src/types/block/error.rs b/sdk/src/types/block/error.rs index 1a58681fc8..60b6311c40 100644 --- a/sdk/src/types/block/error.rs +++ b/sdk/src/types/block/error.rs @@ -118,7 +118,10 @@ pub enum Error { InvalidTokenSchemeKind(u8), InvalidTransactionAmountSum(u128), InvalidTransactionNativeTokensCount(u16), - InvalidManaAllotmentSum(u128), + InvalidManaAllotmentSum { + max: u64, + sum: u128, + }, InvalidUnlockCount(>::Error), InvalidUnlockKind(u8), InvalidUnlockReference(u16), @@ -293,7 +296,9 @@ impl fmt::Display for Error { Self::InvalidTransactionNativeTokensCount(count) => { write!(f, "invalid transaction native tokens count: {count}") } - Self::InvalidManaAllotmentSum(value) => write!(f, "invalid mana allotment sum: {value}"), + Self::InvalidManaAllotmentSum { max, sum } => { + write!(f, "invalid mana allotment sum: {sum} greater than max of {max}") + } Self::InvalidUnlockCount(count) => write!(f, "invalid unlock count: {count}"), Self::InvalidUnlockKind(k) => write!(f, "invalid unlock kind: {k}"), Self::InvalidUnlockReference(index) => { diff --git a/sdk/src/types/block/mana/allotment.rs b/sdk/src/types/block/mana/allotment.rs index 01444aef37..aea2c875cb 100644 --- a/sdk/src/types/block/mana/allotment.rs +++ b/sdk/src/types/block/mana/allotment.rs @@ -8,16 +8,13 @@ use packable::{ Packable, }; -use super::THEORETICAL_MANA_MAX; -use crate::types::block::{output::AccountId, Error}; +use crate::types::block::{output::AccountId, protocol::ProtocolParameters, Error}; /// An allotment of Mana which will be added upon commitment of the slot in which the containing transaction was issued, /// in the form of Block Issuance Credits to the account. #[derive(Copy, Clone, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(rename_all = "camelCase"))] pub struct ManaAllotment { pub(crate) account_id: AccountId, - #[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))] pub(crate) mana: u64, } @@ -34,8 +31,8 @@ impl Ord for ManaAllotment { } impl ManaAllotment { - pub fn new(account_id: AccountId, mana: u64) -> Result { - if mana > THEORETICAL_MANA_MAX { + pub fn new(account_id: AccountId, mana: u64, protocol_params: &ProtocolParameters) -> Result { + if mana > protocol_params.mana_structure().max_mana() { return Err(Error::InvalidManaValue(mana)); } Ok(Self { account_id, mana }) @@ -52,7 +49,7 @@ impl ManaAllotment { impl Packable for ManaAllotment { type UnpackError = Error; - type UnpackVisitor = (); + type UnpackVisitor = ProtocolParameters; fn pack(&self, packer: &mut P) -> Result<(), P::Error> { self.account_id.pack(packer)?; @@ -65,44 +62,53 @@ impl Packable for ManaAllotment { unpacker: &mut U, visitor: &Self::UnpackVisitor, ) -> Result> { - let account_id = AccountId::unpack::<_, VERIFY>(unpacker, visitor).coerce()?; - let mana = u64::unpack::<_, VERIFY>(unpacker, visitor).coerce()?; + let account_id = AccountId::unpack::<_, VERIFY>(unpacker, &()).coerce()?; + let mana = u64::unpack::<_, VERIFY>(unpacker, &()).coerce()?; - Self::new(account_id, mana).map_err(UnpackError::Packable) + Self::new(account_id, mana, visitor).map_err(UnpackError::Packable) } } #[cfg(feature = "serde")] -mod dto { - use serde::Deserialize; +pub(super) mod dto { + use serde::{Deserialize, Serialize}; use super::*; - use crate::utils::serde::string; - - impl<'de> Deserialize<'de> for ManaAllotment { - fn deserialize(d: D) -> Result - where - D: serde::Deserializer<'de>, - { - #[derive(Deserialize)] - #[serde(rename_all = "camelCase")] - struct AllotmentDto { - account_id: AccountId, - #[serde(with = "string")] - mana: u64, - } - - impl TryFrom for ManaAllotment { - type Error = Error; + use crate::{types::TryFromDto, utils::serde::string}; + + #[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] + #[serde(rename_all = "camelCase")] + pub struct ManaAllotmentDto { + pub account_id: AccountId, + #[serde(with = "string")] + pub mana: u64, + } - fn try_from(value: AllotmentDto) -> Result { - Self::new(value.account_id, value.mana) - } + impl From<&ManaAllotment> for ManaAllotmentDto { + fn from(value: &ManaAllotment) -> Self { + Self { + account_id: value.account_id, + mana: value.mana, } + } + } - AllotmentDto::deserialize(d)? - .try_into() - .map_err(serde::de::Error::custom) + impl TryFromDto for ManaAllotment { + type Dto = ManaAllotmentDto; + type Error = Error; + + fn try_from_dto_with_params_inner( + dto: Self::Dto, + params: crate::types::ValidationParams<'_>, + ) -> Result { + Ok(if let Some(params) = params.protocol_parameters() { + Self::new(dto.account_id, dto.mana, params)? + } else { + Self { + account_id: dto.account_id, + mana: dto.mana, + } + }) } } } diff --git a/sdk/src/types/block/mana/mod.rs b/sdk/src/types/block/mana/mod.rs index e55f95f4aa..42ed6b035b 100644 --- a/sdk/src/types/block/mana/mod.rs +++ b/sdk/src/types/block/mana/mod.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 mod allotment; +mod protocol; use alloc::{boxed::Box, collections::BTreeSet, vec::Vec}; use core::ops::RangeInclusive; @@ -10,13 +11,10 @@ use derive_more::Deref; use iterator_sorted::is_unique_sorted; use packable::{bounded::BoundedU16, prefix::BoxedSlicePrefix, Packable}; -pub use self::allotment::ManaAllotment; -use super::{output::AccountId, Error}; - -/// The number of bits that a given mana value can use, excluding the sign bit. -pub const MANA_BITS: u64 = 63; -/// Equivalent to `2^MANA_BITS - 1` -pub const THEORETICAL_MANA_MAX: u64 = u64::MAX >> 1; +#[cfg(feature = "serde")] +pub use self::allotment::dto::ManaAllotmentDto; +pub use self::{allotment::ManaAllotment, protocol::ManaStructure}; +use super::{output::AccountId, protocol::ProtocolParameters, Error}; pub(crate) type ManaAllotmentCount = BoundedU16<{ *ManaAllotments::COUNT_RANGE.start() }, { *ManaAllotments::COUNT_RANGE.end() }>; @@ -25,7 +23,7 @@ pub(crate) type ManaAllotmentCount = #[derive(Clone, Debug, Eq, PartialEq, Deref, Packable)] #[packable(unpack_error = Error, with = |e| e.unwrap_item_err_or_else(|p| Error::InvalidManaAllotmentCount(p.into())))] pub struct ManaAllotments( - #[packable(verify_with = verify_allotments)] BoxedSlicePrefix, + #[packable(verify_with = verify_mana_allotments)] BoxedSlicePrefix, ); impl ManaAllotments { @@ -38,24 +36,25 @@ impl ManaAllotments { /// Creates a new [`ManaAllotments`] from a vec. pub fn from_vec(allotments: Vec) -> Result { - let allotments = BoxedSlicePrefix::::try_from(allotments.into_boxed_slice()) - .map_err(Error::InvalidManaAllotmentCount)?; - - verify_allotments::(&allotments, &())?; - - Ok(Self(allotments)) + verify_mana_allotments_unique_sorted(&allotments)?; + + Ok(Self( + allotments + .into_boxed_slice() + .try_into() + .map_err(Error::InvalidManaAllotmentCount)?, + )) } /// Creates a new [`ManaAllotments`] from an ordered set. pub fn from_set(allotments: BTreeSet) -> Result { - let allotments = BoxedSlicePrefix::::try_from( - allotments.into_iter().collect::>(), - ) - .map_err(Error::InvalidManaAllotmentCount)?; - - verify_allotments_sum(allotments.as_ref())?; - - Ok(Self(allotments)) + Ok(Self( + allotments + .into_iter() + .collect::>() + .try_into() + .map_err(Error::InvalidManaAllotmentCount)?, + )) } /// Gets a reference to an [`ManaAllotment`], if one exists, using an [`AccountId`]. @@ -65,27 +64,45 @@ impl ManaAllotments { } } -fn verify_allotments(allotments: &[ManaAllotment], _visitor: &()) -> Result<(), Error> { +fn verify_mana_allotments( + allotments: &[ManaAllotment], + protocol_params: &ProtocolParameters, +) -> Result<(), Error> { if VERIFY { - if !is_unique_sorted(allotments.iter()) { - return Err(Error::ManaAllotmentsNotUniqueSorted); - } - verify_allotments_sum(allotments)?; + verify_mana_allotments_unique_sorted(allotments)?; + verify_mana_allotments_sum(allotments, protocol_params)?; } Ok(()) } -fn verify_allotments_sum<'a>(allotments: impl IntoIterator) -> Result<(), Error> { +fn verify_mana_allotments_unique_sorted<'a>( + allotments: impl IntoIterator, +) -> Result<(), Error> { + if !is_unique_sorted(allotments.into_iter()) { + return Err(Error::ManaAllotmentsNotUniqueSorted); + } + Ok(()) +} + +pub(crate) fn verify_mana_allotments_sum<'a>( + allotments: impl IntoIterator, + protocol_params: &ProtocolParameters, +) -> Result<(), Error> { let mut mana_sum: u64 = 0; + let max_mana = protocol_params.mana_structure().max_mana(); for ManaAllotment { mana, .. } in allotments { - mana_sum = mana_sum - .checked_add(*mana) - .ok_or(Error::InvalidManaAllotmentSum(mana_sum as u128 + *mana as u128))?; - - if mana_sum > THEORETICAL_MANA_MAX { - return Err(Error::InvalidManaAllotmentSum(mana_sum as u128)); + mana_sum = mana_sum.checked_add(*mana).ok_or(Error::InvalidManaAllotmentSum { + sum: mana_sum as u128 + *mana as u128, + max: max_mana, + })?; + + if mana_sum > max_mana { + return Err(Error::InvalidManaAllotmentSum { + sum: mana_sum as u128, + max: max_mana, + }); } } diff --git a/sdk/src/types/block/mana/protocol.rs b/sdk/src/types/block/mana/protocol.rs new file mode 100644 index 0000000000..8067c1f012 --- /dev/null +++ b/sdk/src/types/block/mana/protocol.rs @@ -0,0 +1,67 @@ +// Copyright 2023 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +use getset::CopyGetters; +use packable::{prefix::BoxedSlicePrefix, Packable}; + +use crate::types::block::{slot::EpochIndex, Error}; + +#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Packable, CopyGetters)] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "camelCase") +)] +#[packable(unpack_error = Error)] +#[getset(get_copy = "pub")] +pub struct ManaStructure { + /// The number of bits used to represent Mana. + pub(crate) mana_bits_count: u8, + /// The amount of potential Mana generated by 1 IOTA in 1 slot. + pub(crate) mana_generation_rate: u8, + /// The scaling of `mana_generation_rate` expressed as an exponent of 2. + pub(crate) mana_generation_rate_exponent: u8, + /// A lookup table of epoch index diff to mana decay factor. + #[packable(unpack_error_with = |_| Error::InvalidManaDecayFactors)] + #[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::boxed_slice_prefix"))] + #[getset(skip)] + pub(crate) mana_decay_factors: BoxedSlicePrefix, + /// The scaling of `mana_decay_factors` expressed as an exponent of 2. + pub(crate) mana_decay_factors_exponent: u8, + /// An integer approximation of the sum of decay over epochs. + pub(crate) mana_decay_factor_epochs_sum: u32, + /// The scaling of `mana_decay_factor_epochs_sum` expressed as an exponent of 2. + pub(crate) mana_decay_factor_epochs_sum_exponent: u8, +} + +impl ManaStructure { + /// Returns the mana decay factors slice. + pub fn mana_decay_factors(&self) -> &[u32] { + &self.mana_decay_factors + } + + /// Returns the mana decay factor for the given epoch index. + pub fn mana_decay_factor_at(&self, epoch_index: EpochIndex) -> Option { + self.mana_decay_factors.get(*epoch_index as usize).copied() + } + + /// Returns the max mana that can exist with the mana bits defined. + pub fn max_mana(&self) -> u64 { + (1 << self.mana_bits_count) - 1 + } +} + +impl Default for ManaStructure { + fn default() -> Self { + // TODO: use actual values + Self { + mana_bits_count: 10, + mana_generation_rate: Default::default(), + mana_generation_rate_exponent: Default::default(), + mana_decay_factors: Default::default(), + mana_decay_factors_exponent: Default::default(), + mana_decay_factor_epochs_sum: Default::default(), + mana_decay_factor_epochs_sum_exponent: Default::default(), + } + } +} diff --git a/sdk/src/types/block/payload/transaction/essence/regular.rs b/sdk/src/types/block/payload/transaction/essence/regular.rs index e54f73b33d..c21dfb0ddd 100644 --- a/sdk/src/types/block/payload/transaction/essence/regular.rs +++ b/sdk/src/types/block/payload/transaction/essence/regular.rs @@ -10,7 +10,7 @@ use crate::types::{ block::{ context_input::{ContextInput, CONTEXT_INPUT_COUNT_RANGE}, input::{Input, INPUT_COUNT_RANGE}, - mana::{ManaAllotment, ManaAllotments}, + mana::{verify_mana_allotments_sum, ManaAllotment, ManaAllotments}, output::{InputsCommitment, NativeTokens, Output, OUTPUT_COUNT_RANGE}, payload::{OptionalPayload, Payload}, protocol::ProtocolParameters, @@ -150,6 +150,10 @@ impl RegularTransactionEssenceBuilder { let allotments = ManaAllotments::from_set(self.allotments)?; + if let Some(protocol_parameters) = params.protocol_parameters() { + verify_mana_allotments_sum(allotments.iter(), protocol_parameters)?; + } + verify_payload(&self.payload)?; let creation_slot = self @@ -424,7 +428,7 @@ pub(crate) mod dto { use super::*; use crate::types::{ - block::{output::dto::OutputDto, payload::dto::PayloadDto, Error}, + block::{mana::ManaAllotmentDto, output::dto::OutputDto, payload::dto::PayloadDto, Error}, TryFromDto, }; @@ -440,7 +444,7 @@ pub(crate) mod dto { pub inputs: Vec, pub inputs_commitment: String, pub outputs: Vec, - pub allotments: Vec, + pub allotments: Vec, #[serde(default, skip_serializing_if = "Option::is_none")] pub payload: Option, } @@ -454,8 +458,8 @@ pub(crate) mod dto { context_inputs: value.context_inputs().to_vec(), inputs: value.inputs().to_vec(), inputs_commitment: value.inputs_commitment().to_string(), - outputs: value.outputs().iter().map(Into::into).collect::>(), - allotments: value.mana_allotments().to_vec(), + outputs: value.outputs().iter().map(Into::into).collect(), + allotments: value.mana_allotments().iter().map(Into::into).collect(), payload: match value.payload() { Some(p @ Payload::TaggedData(_)) => Some(p.into()), Some(_) => unimplemented!(), @@ -479,13 +483,18 @@ pub(crate) mod dto { .into_iter() .map(|o| Output::try_from_dto_with_params(o, ¶ms)) .collect::, Error>>()?; + let mana_allotments = dto + .allotments + .into_iter() + .map(|o| ManaAllotment::try_from_dto_with_params(o, ¶ms)) + .collect::, Error>>()?; let mut builder = Self::builder(network_id, InputsCommitment::from_str(&dto.inputs_commitment)?) .with_creation_slot(dto.creation_slot) .with_context_inputs(dto.context_inputs) .with_inputs(dto.inputs) .with_outputs(outputs) - .with_mana_allotments(dto.allotments); + .with_mana_allotments(mana_allotments); builder = if let Some(p) = dto.payload { if let PayloadDto::TaggedData(i) = p { diff --git a/sdk/src/types/block/protocol.rs b/sdk/src/types/block/protocol.rs index 9931659547..fa16ad6fe7 100644 --- a/sdk/src/types/block/protocol.rs +++ b/sdk/src/types/block/protocol.rs @@ -6,13 +6,11 @@ use core::borrow::Borrow; use crypto::hashes::{blake2b::Blake2b256, Digest}; use getset::{CopyGetters, Getters}; -use packable::{ - prefix::{BoxedSlicePrefix, StringPrefix}, - Packable, PackableExt, -}; +use packable::{prefix::StringPrefix, Packable, PackableExt}; use super::{ address::Hrp, + mana::ManaStructure, slot::{EpochIndex, SlotIndex}, }; use crate::types::block::{helper::network_name_to_id, output::RentStructure, ConvertTo, Error, PROTOCOL_VERSION}; @@ -50,23 +48,9 @@ pub struct ProtocolParameters { pub(crate) slot_duration_in_seconds: u8, /// The number of slots in an epoch expressed as an exponent of 2. pub(crate) slots_per_epoch_exponent: u8, - /// The number of bits used to represent Mana expressed as an exponent of 2. - pub(crate) mana_bits_exponent: u8, - /// The amount of potential Mana generated by 1 IOTA in 1 slot. - pub(crate) mana_generation_rate: u8, - /// The scaling of `mana_generation_rate` expressed as an exponent of 2. - pub(crate) mana_generation_rate_exponent: u8, - #[packable(unpack_error_with = |_| Error::InvalidManaDecayFactors)] - #[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::boxed_slice_prefix"))] + /// The parameters used for mana calculations. #[getset(skip)] - /// A lookup table of epoch index diff to mana decay factor. - pub(crate) mana_decay_factors: BoxedSlicePrefix, - /// The scaling of `mana_decay_factors` expressed as an exponent of 2. - pub(crate) mana_decay_factors_exponent: u8, - /// An integer approximation of the sum of decay over epochs. - pub(crate) mana_decay_factor_epochs_sum: u32, - /// The scaling of `mana_decay_factor_epochs_sum` expressed as an exponent of 2. - pub(crate) mana_decay_factor_epochs_sum_exponent: u8, + pub(crate) mana_structure: ManaStructure, /// The unbonding period in epochs before an account can stop staking. pub(crate) staking_unbonding_period: EpochIndex, /// The slot index used by tip-selection to determine if a block is eligible by evaluating issuing times @@ -107,13 +91,7 @@ impl Default for ProtocolParameters { slot_duration_in_seconds: 10, epoch_nearing_threshold: 20.into(), slots_per_epoch_exponent: Default::default(), - mana_bits_exponent: Default::default(), - mana_generation_rate: Default::default(), - mana_generation_rate_exponent: Default::default(), - mana_decay_factors: Default::default(), - mana_decay_factors_exponent: Default::default(), - mana_decay_factor_epochs_sum: Default::default(), - mana_decay_factor_epochs_sum_exponent: Default::default(), + mana_structure: Default::default(), staking_unbonding_period: 10.into(), liveness_threshold: 5.into(), min_committable_age: 10.into(), @@ -160,14 +138,9 @@ impl ProtocolParameters { network_name_to_id(&self.network_name) } - /// Returns the mana decay factors slice of the [`ProtocolParameters`]. - pub fn mana_decay_factors(&self) -> &[u32] { - &self.mana_decay_factors - } - - /// Returns the mana decay factor for the given epoch index. - pub fn mana_decay_factor_at(&self, epoch_index: EpochIndex) -> Option { - self.mana_decay_factors.get(*epoch_index as usize).copied() + /// Returns the parameters used for mana calculations. + pub fn mana_structure(&self) -> &ManaStructure { + &self.mana_structure } /// Returns the slots per epoch of the [`ProtocolParameters`]. diff --git a/sdk/src/types/block/rand/mana.rs b/sdk/src/types/block/rand/mana.rs index 68b5f20a7f..737144d734 100644 --- a/sdk/src/types/block/rand/mana.rs +++ b/sdk/src/types/block/rand/mana.rs @@ -2,11 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 use crate::types::block::{ - mana::{ManaAllotment, THEORETICAL_MANA_MAX}, + mana::ManaAllotment, + protocol::ProtocolParameters, rand::{number::rand_number_range, output::rand_account_id}, }; /// Generates a random mana allotment. -pub fn rand_mana_allotment() -> ManaAllotment { - ManaAllotment::new(rand_account_id(), rand_number_range(0..THEORETICAL_MANA_MAX)).unwrap() +pub fn rand_mana_allotment(params: &ProtocolParameters) -> ManaAllotment { + ManaAllotment::new( + rand_account_id(), + rand_number_range(0..params.mana_structure().max_mana()), + params, + ) + .unwrap() } diff --git a/sdk/src/wallet/account/mod.rs b/sdk/src/wallet/account/mod.rs index cec2884e33..d6b86d0e81 100644 --- a/sdk/src/wallet/account/mod.rs +++ b/sdk/src/wallet/account/mod.rs @@ -637,7 +637,7 @@ fn serialize() { RegularTransactionEssence::builder(protocol_parameters.network_id(), InputsCommitment::from([0u8; 32])) .with_inputs([input1, input2]) .add_output(output) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(protocol_parameters) .unwrap(); diff --git a/sdk/tests/client/signing/account.rs b/sdk/tests/client/signing/account.rs index 91d0c49aff..5dbc140e31 100644 --- a/sdk/tests/client/signing/account.rs +++ b/sdk/tests/client/signing/account.rs @@ -94,7 +94,7 @@ async fn sign_account_state_transition() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(protocol_parameters)?, ); @@ -184,7 +184,7 @@ async fn sign_account_governance_transition() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(protocol_parameters)?, ); @@ -314,7 +314,7 @@ async fn account_reference_unlocks() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(protocol_parameters)?, ); diff --git a/sdk/tests/client/signing/basic.rs b/sdk/tests/client/signing/basic.rs index bccba46445..908d296179 100644 --- a/sdk/tests/client/signing/basic.rs +++ b/sdk/tests/client/signing/basic.rs @@ -77,7 +77,7 @@ async fn single_ed25519_unlock() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(protocol_parameters)?, ); @@ -178,7 +178,7 @@ async fn ed25519_reference_unlocks() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(protocol_parameters)?, ); @@ -289,7 +289,7 @@ async fn two_signature_unlocks() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(protocol_parameters)?, ); diff --git a/sdk/tests/client/signing/mod.rs b/sdk/tests/client/signing/mod.rs index 6564152eb2..95e1497fbd 100644 --- a/sdk/tests/client/signing/mod.rs +++ b/sdk/tests/client/signing/mod.rs @@ -384,7 +384,7 @@ async fn all_combined() -> Result<()> { ) .with_outputs(outputs) .with_creation_slot(slot_index) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(protocol_parameters)?, ); diff --git a/sdk/tests/client/signing/nft.rs b/sdk/tests/client/signing/nft.rs index bfd579659b..5473d5bed8 100644 --- a/sdk/tests/client/signing/nft.rs +++ b/sdk/tests/client/signing/nft.rs @@ -121,7 +121,7 @@ async fn nft_reference_unlocks() -> Result<()> { .collect::>(), ) .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(protocol_parameters)?, ); diff --git a/sdk/tests/types/block_id.rs b/sdk/tests/types/block_id.rs index 5a87c1770b..5a380bba05 100644 --- a/sdk/tests/types/block_id.rs +++ b/sdk/tests/types/block_id.rs @@ -102,11 +102,11 @@ fn compute() { // TODO: Independently verify this value assert_eq!( block_id.to_string(), - "0x8840fd83fcbc58dfcc6b6e63d3cf8f42694197b77ad7e244c3327af3b6cdd9780b00000000000000" + "0x5e3d8befccbd36860a589cf9427efa108bcc781f630ebfdf6f57cef7eed8b5bb0b00000000000000" ); assert_eq!( block_id.hash().to_string(), - "0x8840fd83fcbc58dfcc6b6e63d3cf8f42694197b77ad7e244c3327af3b6cdd978" + "0x5e3d8befccbd36860a589cf9427efa108bcc781f630ebfdf6f57cef7eed8b5bb" ); assert_eq!(block_id.slot_index(), slot_index); } diff --git a/sdk/tests/types/payload.rs b/sdk/tests/types/payload.rs index 6fbe83ecfe..3896aafd33 100644 --- a/sdk/tests/types/payload.rs +++ b/sdk/tests/types/payload.rs @@ -39,7 +39,7 @@ fn transaction() { let essence = RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .with_inputs(vec![input1, input2]) .add_output(output) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters) .unwrap(); diff --git a/sdk/tests/types/transaction_essence.rs b/sdk/tests/types/transaction_essence.rs index e80f7d0d6f..4f63ffdead 100644 --- a/sdk/tests/types/transaction_essence.rs +++ b/sdk/tests/types/transaction_essence.rs @@ -34,7 +34,7 @@ fn essence_kind() { RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .with_inputs([input1, input2]) .add_output(output) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters) .unwrap(), ); diff --git a/sdk/tests/types/transaction_payload.rs b/sdk/tests/types/transaction_payload.rs index 44b1cd73bc..b7250d91e0 100644 --- a/sdk/tests/types/transaction_payload.rs +++ b/sdk/tests/types/transaction_payload.rs @@ -44,7 +44,7 @@ fn builder_no_essence_too_few_unlocks() { let essence = RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .with_inputs([input1, input2]) .add_output(output) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters) .unwrap(); @@ -80,7 +80,7 @@ fn builder_no_essence_too_many_unlocks() { let essence = RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .add_input(input1) .add_output(output) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters) .unwrap(); @@ -119,7 +119,7 @@ fn pack_unpack_valid() { let essence = RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .with_inputs([input1, input2]) .add_output(output) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters) .unwrap(); @@ -160,7 +160,7 @@ fn getters() { let essence = RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .with_inputs([input1, input2]) .add_output(output) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters) .unwrap(); diff --git a/sdk/tests/types/transaction_regular_essence.rs b/sdk/tests/types/transaction_regular_essence.rs index 5f41daa6bc..d7a9f192c5 100644 --- a/sdk/tests/types/transaction_regular_essence.rs +++ b/sdk/tests/types/transaction_regular_essence.rs @@ -54,7 +54,7 @@ fn build_valid() { let essence = RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .with_inputs([input1, input2]) .add_output(output) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters); assert!(essence.is_ok()); @@ -80,7 +80,7 @@ fn build_valid_with_payload() { .with_inputs([input1, input2]) .add_output(output) .with_payload(rand_tagged_data_payload()) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters); assert!(essence.is_ok()); @@ -105,7 +105,7 @@ fn build_valid_add_inputs_outputs() { let essence = RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .with_inputs([input1, input2]) .add_output(output) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters); assert!(essence.is_ok()); @@ -130,7 +130,7 @@ fn build_invalid_payload_kind() { let essence = RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .with_inputs([input1.clone(), input2.clone()]) .add_output(output.clone()) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters) .unwrap(); @@ -148,7 +148,7 @@ fn build_invalid_payload_kind() { .with_inputs(vec![input1, input2]) .add_output(output) .with_payload(tx_payload) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters); assert!(matches!(essence, Err(Error::InvalidPayloadKind(6)))); @@ -169,7 +169,7 @@ fn build_invalid_input_count_low() { let essence = RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .add_output(output) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters); assert!(matches!( @@ -196,7 +196,7 @@ fn build_invalid_input_count_high() { let essence = RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .with_inputs(vec![input; 129]) .add_output(output) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters); assert!(matches!( @@ -213,7 +213,7 @@ fn build_invalid_output_count_low() { let essence = RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .add_input(input) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters); assert!(matches!( @@ -240,7 +240,7 @@ fn build_invalid_output_count_high() { let essence = RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .add_input(input) .with_outputs(vec![output; 129]) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters); assert!(matches!( @@ -267,7 +267,7 @@ fn build_invalid_duplicate_utxo() { let essence = RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .with_inputs(vec![input; 2]) .add_output(output) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters); assert!(matches!(essence, Err(Error::DuplicateUtxo(_)))); @@ -302,7 +302,7 @@ fn build_invalid_accumulated_output() { let essence = RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .add_input(input) .with_outputs([output1, output2]) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters); assert!(matches!(essence, Err(Error::InvalidTransactionAmountSum(_)))); @@ -329,7 +329,7 @@ fn getters() { .with_inputs([input1, input2]) .with_outputs(outputs.clone()) .with_payload(payload.clone()) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters) .unwrap(); @@ -359,7 +359,7 @@ fn duplicate_output_nft() { let essence = RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .with_inputs([input1, input2]) .with_outputs([basic, nft.clone(), nft]) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters); assert!(matches!( @@ -390,7 +390,7 @@ fn duplicate_output_nft_null() { let essence = RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .with_inputs([input1, input2]) .with_outputs([basic, nft.clone(), nft]) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters); assert!(essence.is_ok()); @@ -419,7 +419,7 @@ fn duplicate_output_account() { let essence = RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .with_inputs([input1, input2]) .with_outputs([basic, account.clone(), account]) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters); assert!(matches!( @@ -456,7 +456,7 @@ fn duplicate_output_foundry() { let essence = RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .with_inputs([input1, input2]) .with_outputs([basic, foundry.clone(), foundry]) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters); assert!(matches!( diff --git a/sdk/tests/wallet/events.rs b/sdk/tests/wallet/events.rs index e12a565905..155061eef3 100644 --- a/sdk/tests/wallet/events.rs +++ b/sdk/tests/wallet/events.rs @@ -98,7 +98,7 @@ fn wallet_events_serde() { RegularTransactionEssence::builder(protocol_parameters.network_id(), rand_inputs_commitment()) .with_inputs(vec![input1, input2]) .add_output(output) - .add_mana_allotment(rand_mana_allotment()) + .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters) .unwrap(), );