mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-19 00:41:03 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -16,26 +16,27 @@
|
||||
// limitations under the License.
|
||||
|
||||
use crate::{limits::BlockWeights, Config, Pallet};
|
||||
use codec::{Encode, Decode};
|
||||
use sp_runtime::{
|
||||
traits::{SignedExtension, DispatchInfoOf, Dispatchable, PostDispatchInfoOf},
|
||||
transaction_validity::{
|
||||
ValidTransaction, TransactionValidityError, InvalidTransaction, TransactionValidity,
|
||||
TransactionPriority,
|
||||
},
|
||||
DispatchResult,
|
||||
};
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::{
|
||||
traits::Get,
|
||||
weights::{PostDispatchInfo, DispatchInfo, DispatchClass, priority::FrameTransactionPriority},
|
||||
weights::{priority::FrameTransactionPriority, DispatchClass, DispatchInfo, PostDispatchInfo},
|
||||
};
|
||||
use sp_runtime::{
|
||||
traits::{DispatchInfoOf, Dispatchable, PostDispatchInfoOf, SignedExtension},
|
||||
transaction_validity::{
|
||||
InvalidTransaction, TransactionPriority, TransactionValidity, TransactionValidityError,
|
||||
ValidTransaction,
|
||||
},
|
||||
DispatchResult,
|
||||
};
|
||||
|
||||
/// Block resource (weight) limit check.
|
||||
#[derive(Encode, Decode, Clone, Eq, PartialEq, Default)]
|
||||
pub struct CheckWeight<T: Config + Send + Sync>(sp_std::marker::PhantomData<T>);
|
||||
|
||||
impl<T: Config + Send + Sync> CheckWeight<T> where
|
||||
T::Call: Dispatchable<Info=DispatchInfo, PostInfo=PostDispatchInfo>,
|
||||
impl<T: Config + Send + Sync> CheckWeight<T>
|
||||
where
|
||||
T::Call: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,
|
||||
{
|
||||
/// Checks if the current extrinsic does not exceed the maximum weight a single extrinsic
|
||||
/// with given `DispatchClass` can have.
|
||||
@@ -44,9 +45,7 @@ impl<T: Config + Send + Sync> CheckWeight<T> where
|
||||
) -> Result<(), TransactionValidityError> {
|
||||
let max = T::BlockWeights::get().get(info.class).max_extrinsic;
|
||||
match max {
|
||||
Some(max) if info.weight > max => {
|
||||
Err(InvalidTransaction::ExhaustsResources.into())
|
||||
},
|
||||
Some(max) if info.weight > max => Err(InvalidTransaction::ExhaustsResources.into()),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
@@ -87,8 +86,7 @@ impl<T: Config + Send + Sync> CheckWeight<T> where
|
||||
fn get_priority(info: &DispatchInfoOf<T::Call>) -> TransactionPriority {
|
||||
match info.class {
|
||||
// Normal transaction.
|
||||
DispatchClass::Normal =>
|
||||
FrameTransactionPriority::Normal(info.weight.into()).into(),
|
||||
DispatchClass::Normal => FrameTransactionPriority::Normal(info.weight.into()).into(),
|
||||
// Don't use up the whole priority space, to allow things like `tip` to be taken into
|
||||
// account as well.
|
||||
DispatchClass::Operational =>
|
||||
@@ -122,10 +120,7 @@ impl<T: Config + Send + Sync> CheckWeight<T> where
|
||||
/// Do the validate checks. This can be applied to both signed and unsigned.
|
||||
///
|
||||
/// It only checks that the block weight and length limit will not exceed.
|
||||
pub fn do_validate(
|
||||
info: &DispatchInfoOf<T::Call>,
|
||||
len: usize,
|
||||
) -> TransactionValidity {
|
||||
pub fn do_validate(info: &DispatchInfoOf<T::Call>, len: usize) -> TransactionValidity {
|
||||
// ignore the next length. If they return `Ok`, then it is below the limit.
|
||||
let _ = Self::check_block_length(info, len)?;
|
||||
// during validation we skip block limit check. Since the `validate_transaction`
|
||||
@@ -141,17 +136,20 @@ pub fn calculate_consumed_weight<Call>(
|
||||
maximum_weight: BlockWeights,
|
||||
mut all_weight: crate::ConsumedWeight,
|
||||
info: &DispatchInfoOf<Call>,
|
||||
) -> Result<crate::ConsumedWeight, TransactionValidityError> where
|
||||
Call: Dispatchable<Info=DispatchInfo, PostInfo=PostDispatchInfo>,
|
||||
) -> Result<crate::ConsumedWeight, TransactionValidityError>
|
||||
where
|
||||
Call: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,
|
||||
{
|
||||
let extrinsic_weight = info.weight.saturating_add(maximum_weight.get(info.class).base_extrinsic);
|
||||
let extrinsic_weight =
|
||||
info.weight.saturating_add(maximum_weight.get(info.class).base_extrinsic);
|
||||
let limit_per_class = maximum_weight.get(info.class);
|
||||
|
||||
// add the weight. If class is unlimited, use saturating add instead of checked one.
|
||||
if limit_per_class.max_total.is_none() && limit_per_class.reserved.is_none() {
|
||||
all_weight.add(extrinsic_weight, info.class)
|
||||
} else {
|
||||
all_weight.checked_add(extrinsic_weight, info.class)
|
||||
all_weight
|
||||
.checked_add(extrinsic_weight, info.class)
|
||||
.map_err(|_| InvalidTransaction::ExhaustsResources)?;
|
||||
}
|
||||
|
||||
@@ -159,9 +157,7 @@ pub fn calculate_consumed_weight<Call>(
|
||||
|
||||
// Check if we don't exceed per-class allowance
|
||||
match limit_per_class.max_total {
|
||||
Some(max) if per_class > max => {
|
||||
return Err(InvalidTransaction::ExhaustsResources.into());
|
||||
},
|
||||
Some(max) if per_class > max => return Err(InvalidTransaction::ExhaustsResources.into()),
|
||||
// There is no `max_total` limit (`None`),
|
||||
// or we are below the limit.
|
||||
_ => {},
|
||||
@@ -172,9 +168,8 @@ pub fn calculate_consumed_weight<Call>(
|
||||
if all_weight.total() > maximum_weight.max_block {
|
||||
match limit_per_class.reserved {
|
||||
// We are over the limit in reserved pool.
|
||||
Some(reserved) if per_class > reserved => {
|
||||
return Err(InvalidTransaction::ExhaustsResources.into());
|
||||
}
|
||||
Some(reserved) if per_class > reserved =>
|
||||
return Err(InvalidTransaction::ExhaustsResources.into()),
|
||||
// There is either no limit in reserved pool (`None`),
|
||||
// or we are below the limit.
|
||||
_ => {},
|
||||
@@ -184,8 +179,9 @@ pub fn calculate_consumed_weight<Call>(
|
||||
Ok(all_weight)
|
||||
}
|
||||
|
||||
impl<T: Config + Send + Sync> SignedExtension for CheckWeight<T> where
|
||||
T::Call: Dispatchable<Info=DispatchInfo, PostInfo=PostDispatchInfo>
|
||||
impl<T: Config + Send + Sync> SignedExtension for CheckWeight<T>
|
||||
where
|
||||
T::Call: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,
|
||||
{
|
||||
type AccountId = T::AccountId;
|
||||
type Call = T::Call;
|
||||
@@ -193,7 +189,9 @@ impl<T: Config + Send + Sync> SignedExtension for CheckWeight<T> where
|
||||
type Pre = ();
|
||||
const IDENTIFIER: &'static str = "CheckWeight";
|
||||
|
||||
fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> { Ok(()) }
|
||||
fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn pre_dispatch(
|
||||
self,
|
||||
@@ -278,17 +276,24 @@ impl<T: Config + Send + Sync> sp_std::fmt::Debug for CheckWeight<T> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{BlockWeight, AllExtrinsicsLen};
|
||||
use crate::mock::{Test, CALL, new_test_ext, System};
|
||||
use crate::{
|
||||
mock::{new_test_ext, System, Test, CALL},
|
||||
AllExtrinsicsLen, BlockWeight,
|
||||
};
|
||||
use frame_support::{
|
||||
assert_err, assert_ok,
|
||||
weights::{Pays, Weight},
|
||||
};
|
||||
use sp_std::marker::PhantomData;
|
||||
use frame_support::{assert_err, assert_ok, weights::{Weight, Pays}};
|
||||
|
||||
fn block_weights() -> crate::limits::BlockWeights {
|
||||
<Test as crate::Config>::BlockWeights::get()
|
||||
}
|
||||
|
||||
fn normal_weight_limit() -> Weight {
|
||||
block_weights().get(DispatchClass::Normal).max_total
|
||||
block_weights()
|
||||
.get(DispatchClass::Normal)
|
||||
.max_total
|
||||
.unwrap_or_else(|| block_weights().max_block)
|
||||
}
|
||||
|
||||
@@ -334,7 +339,10 @@ mod tests {
|
||||
..Default::default()
|
||||
};
|
||||
let len = 0_usize;
|
||||
assert_err!(CheckWeight::<Test>::do_validate(&max, len), InvalidTransaction::ExhaustsResources);
|
||||
assert_err!(
|
||||
CheckWeight::<Test>::do_validate(&max, len),
|
||||
InvalidTransaction::ExhaustsResources
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -342,16 +350,15 @@ mod tests {
|
||||
fn operational_extrinsic_limited_by_operational_space_limit() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let weights = block_weights();
|
||||
let operational_limit = weights.get(DispatchClass::Operational).max_total
|
||||
let operational_limit = weights
|
||||
.get(DispatchClass::Operational)
|
||||
.max_total
|
||||
.unwrap_or_else(|| weights.max_block);
|
||||
let base_weight = weights.get(DispatchClass::Normal).base_extrinsic;
|
||||
|
||||
let weight = operational_limit - base_weight;
|
||||
let okay = DispatchInfo {
|
||||
weight,
|
||||
class: DispatchClass::Operational,
|
||||
..Default::default()
|
||||
};
|
||||
let okay =
|
||||
DispatchInfo { weight, class: DispatchClass::Operational, ..Default::default() };
|
||||
let max = DispatchInfo {
|
||||
weight: weight + 1,
|
||||
class: DispatchClass::Operational,
|
||||
@@ -366,7 +373,10 @@ mod tests {
|
||||
..Default::default()
|
||||
})
|
||||
);
|
||||
assert_err!(CheckWeight::<Test>::do_validate(&max, len), InvalidTransaction::ExhaustsResources);
|
||||
assert_err!(
|
||||
CheckWeight::<Test>::do_validate(&max, len),
|
||||
InvalidTransaction::ExhaustsResources
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -388,7 +398,11 @@ mod tests {
|
||||
// So normal extrinsic can be 758 weight (-5 for base extrinsic weight)
|
||||
// And Operational can be 256 to produce a full block (-5 for base)
|
||||
let max_normal = DispatchInfo { weight: 753, ..Default::default() };
|
||||
let rest_operational = DispatchInfo { weight: 251, class: DispatchClass::Operational, ..Default::default() };
|
||||
let rest_operational = DispatchInfo {
|
||||
weight: 251,
|
||||
class: DispatchClass::Operational,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let len = 0_usize;
|
||||
|
||||
@@ -407,7 +421,11 @@ mod tests {
|
||||
new_test_ext().execute_with(|| {
|
||||
// We switch the order of `full_block_with_normal_and_operational`
|
||||
let max_normal = DispatchInfo { weight: 753, ..Default::default() };
|
||||
let rest_operational = DispatchInfo { weight: 251, class: DispatchClass::Operational, ..Default::default() };
|
||||
let rest_operational = DispatchInfo {
|
||||
weight: 251,
|
||||
class: DispatchClass::Operational,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let len = 0_usize;
|
||||
|
||||
@@ -425,17 +443,24 @@ mod tests {
|
||||
new_test_ext().execute_with(|| {
|
||||
// An on_initialize takes up the whole block! (Every time!)
|
||||
System::register_extra_weight_unchecked(Weight::max_value(), DispatchClass::Mandatory);
|
||||
let dispatch_normal = DispatchInfo { weight: 251, class: DispatchClass::Normal, ..Default::default() };
|
||||
let dispatch_operational = DispatchInfo { weight: 251, class: DispatchClass::Operational, ..Default::default() };
|
||||
let dispatch_normal =
|
||||
DispatchInfo { weight: 251, class: DispatchClass::Normal, ..Default::default() };
|
||||
let dispatch_operational = DispatchInfo {
|
||||
weight: 251,
|
||||
class: DispatchClass::Operational,
|
||||
..Default::default()
|
||||
};
|
||||
let len = 0_usize;
|
||||
|
||||
assert_err!( CheckWeight::<Test>::do_pre_dispatch(&dispatch_normal, len),
|
||||
assert_err!(
|
||||
CheckWeight::<Test>::do_pre_dispatch(&dispatch_normal, len),
|
||||
InvalidTransaction::ExhaustsResources
|
||||
);
|
||||
// Thank goodness we can still do an operational transaction to possibly save the blockchain.
|
||||
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&dispatch_operational, len));
|
||||
// Not too much though
|
||||
assert_err!(CheckWeight::<Test>::do_pre_dispatch(&dispatch_operational, len),
|
||||
assert_err!(
|
||||
CheckWeight::<Test>::do_pre_dispatch(&dispatch_operational, len),
|
||||
InvalidTransaction::ExhaustsResources
|
||||
);
|
||||
// Even with full block, validity of single transaction should be correct.
|
||||
@@ -447,7 +472,11 @@ mod tests {
|
||||
fn signed_ext_check_weight_works_operational_tx() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let normal = DispatchInfo { weight: 100, ..Default::default() };
|
||||
let op = DispatchInfo { weight: 100, class: DispatchClass::Operational, pays_fee: Pays::Yes };
|
||||
let op = DispatchInfo {
|
||||
weight: 100,
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
let len = 0_usize;
|
||||
let normal_limit = normal_weight_limit();
|
||||
|
||||
@@ -456,7 +485,8 @@ mod tests {
|
||||
current_weight.set(normal_limit, DispatchClass::Normal)
|
||||
});
|
||||
// will not fit.
|
||||
assert_err!(CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &normal, len),
|
||||
assert_err!(
|
||||
CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &normal, len),
|
||||
InvalidTransaction::ExhaustsResources
|
||||
);
|
||||
// will fit.
|
||||
@@ -465,7 +495,8 @@ mod tests {
|
||||
// likewise for length limit.
|
||||
let len = 100_usize;
|
||||
AllExtrinsicsLen::<Test>::put(normal_length_limit());
|
||||
assert_err!(CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &normal, len),
|
||||
assert_err!(
|
||||
CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &normal, len),
|
||||
InvalidTransaction::ExhaustsResources
|
||||
);
|
||||
assert_ok!(CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &op, len));
|
||||
@@ -475,8 +506,13 @@ mod tests {
|
||||
#[test]
|
||||
fn signed_ext_check_weight_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let normal = DispatchInfo { weight: 100, class: DispatchClass::Normal, pays_fee: Pays::Yes };
|
||||
let op = DispatchInfo { weight: 100, class: DispatchClass::Operational, pays_fee: Pays::Yes };
|
||||
let normal =
|
||||
DispatchInfo { weight: 100, class: DispatchClass::Normal, pays_fee: Pays::Yes };
|
||||
let op = DispatchInfo {
|
||||
weight: 100,
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
let len = 0_usize;
|
||||
|
||||
let priority = CheckWeight::<Test>(PhantomData)
|
||||
@@ -485,10 +521,8 @@ mod tests {
|
||||
.priority;
|
||||
assert_eq!(priority, 100);
|
||||
|
||||
let priority = CheckWeight::<Test>(PhantomData)
|
||||
.validate(&1, CALL, &op, len)
|
||||
.unwrap()
|
||||
.priority;
|
||||
let priority =
|
||||
CheckWeight::<Test>(PhantomData).validate(&1, CALL, &op, len).unwrap().priority;
|
||||
assert_eq!(priority, frame_support::weights::priority::LIMIT + 100);
|
||||
})
|
||||
}
|
||||
@@ -501,7 +535,11 @@ mod tests {
|
||||
let reset_check_weight = |tx, s, f| {
|
||||
AllExtrinsicsLen::<Test>::put(0);
|
||||
let r = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, tx, s);
|
||||
if f { assert!(r.is_err()) } else { assert!(r.is_ok()) }
|
||||
if f {
|
||||
assert!(r.is_err())
|
||||
} else {
|
||||
assert!(r.is_ok())
|
||||
}
|
||||
};
|
||||
|
||||
reset_check_weight(&normal, normal_limit - 1, false);
|
||||
@@ -509,7 +547,8 @@ mod tests {
|
||||
reset_check_weight(&normal, normal_limit + 1, true);
|
||||
|
||||
// Operational ones don't have this limit.
|
||||
let op = DispatchInfo { weight: 0, class: DispatchClass::Operational, pays_fee: Pays::Yes };
|
||||
let op =
|
||||
DispatchInfo { weight: 0, class: DispatchClass::Operational, pays_fee: Pays::Yes };
|
||||
reset_check_weight(&op, normal_limit, false);
|
||||
reset_check_weight(&op, normal_limit + 100, false);
|
||||
reset_check_weight(&op, 1024, false);
|
||||
@@ -517,21 +556,16 @@ mod tests {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn signed_ext_check_weight_works_normal_tx() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let normal_limit = normal_weight_limit();
|
||||
let small = DispatchInfo { weight: 100, ..Default::default() };
|
||||
let base_extrinsic = block_weights().get(DispatchClass::Normal).base_extrinsic;
|
||||
let medium = DispatchInfo {
|
||||
weight: normal_limit - base_extrinsic,
|
||||
..Default::default()
|
||||
};
|
||||
let big = DispatchInfo {
|
||||
weight: normal_limit - base_extrinsic + 1,
|
||||
..Default::default()
|
||||
};
|
||||
let medium =
|
||||
DispatchInfo { weight: normal_limit - base_extrinsic, ..Default::default() };
|
||||
let big =
|
||||
DispatchInfo { weight: normal_limit - base_extrinsic + 1, ..Default::default() };
|
||||
let len = 0_usize;
|
||||
|
||||
let reset_check_weight = |i, f, s| {
|
||||
@@ -539,7 +573,11 @@ mod tests {
|
||||
current_weight.set(s, DispatchClass::Normal)
|
||||
});
|
||||
let r = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, i, len);
|
||||
if f { assert!(r.is_err()) } else { assert!(r.is_ok()) }
|
||||
if f {
|
||||
assert!(r.is_err())
|
||||
} else {
|
||||
assert!(r.is_ok())
|
||||
}
|
||||
};
|
||||
|
||||
reset_check_weight(&small, false, 0);
|
||||
@@ -553,10 +591,8 @@ mod tests {
|
||||
new_test_ext().execute_with(|| {
|
||||
// This is half of the max block weight
|
||||
let info = DispatchInfo { weight: 512, ..Default::default() };
|
||||
let post_info = PostDispatchInfo {
|
||||
actual_weight: Some(128),
|
||||
pays_fee: Default::default(),
|
||||
};
|
||||
let post_info =
|
||||
PostDispatchInfo { actual_weight: Some(128), pays_fee: Default::default() };
|
||||
let len = 0_usize;
|
||||
let base_extrinsic = block_weights().get(DispatchClass::Normal).base_extrinsic;
|
||||
|
||||
@@ -569,11 +605,8 @@ mod tests {
|
||||
let pre = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &info, len).unwrap();
|
||||
assert_eq!(BlockWeight::<Test>::get().total(), info.weight + 256);
|
||||
|
||||
assert_ok!( CheckWeight::<Test>::post_dispatch(pre, &info, &post_info, len, &Ok(())));
|
||||
assert_eq!(
|
||||
BlockWeight::<Test>::get().total(),
|
||||
post_info.actual_weight.unwrap() + 256,
|
||||
);
|
||||
assert_ok!(CheckWeight::<Test>::post_dispatch(pre, &info, &post_info, len, &Ok(())));
|
||||
assert_eq!(BlockWeight::<Test>::get().total(), post_info.actual_weight.unwrap() + 256,);
|
||||
})
|
||||
}
|
||||
|
||||
@@ -581,10 +614,8 @@ mod tests {
|
||||
fn signed_ext_check_weight_actual_weight_higher_than_max_is_capped() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let info = DispatchInfo { weight: 512, ..Default::default() };
|
||||
let post_info = PostDispatchInfo {
|
||||
actual_weight: Some(700),
|
||||
pays_fee: Default::default(),
|
||||
};
|
||||
let post_info =
|
||||
PostDispatchInfo { actual_weight: Some(700), pays_fee: Default::default() };
|
||||
let len = 0_usize;
|
||||
|
||||
BlockWeight::<Test>::mutate(|current_weight| {
|
||||
@@ -614,10 +645,7 @@ mod tests {
|
||||
let len = 0_usize;
|
||||
|
||||
// Initial weight from `weights.base_block`
|
||||
assert_eq!(
|
||||
System::block_weight().total(),
|
||||
weights.base_block
|
||||
);
|
||||
assert_eq!(System::block_weight().total(), weights.base_block);
|
||||
assert_ok!(CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &free, len));
|
||||
assert_eq!(
|
||||
System::block_weight().total(),
|
||||
@@ -633,7 +661,11 @@ mod tests {
|
||||
// Max normal is 768 (75%)
|
||||
// Max mandatory is unlimited
|
||||
let max_normal = DispatchInfo { weight: 753, ..Default::default() };
|
||||
let mandatory = DispatchInfo { weight: 1019, class: DispatchClass::Mandatory, ..Default::default() };
|
||||
let mandatory = DispatchInfo {
|
||||
weight: 1019,
|
||||
class: DispatchClass::Mandatory,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let len = 0_usize;
|
||||
|
||||
@@ -669,18 +701,24 @@ mod tests {
|
||||
assert_eq!(maximum_weight.max_block, all_weight.total());
|
||||
|
||||
// fits into reserved
|
||||
let mandatory1 = DispatchInfo { weight: 5, class: DispatchClass::Mandatory, ..Default::default() };
|
||||
let mandatory1 =
|
||||
DispatchInfo { weight: 5, class: DispatchClass::Mandatory, ..Default::default() };
|
||||
// does not fit into reserved and the block is full.
|
||||
let mandatory2 = DispatchInfo { weight: 6, class: DispatchClass::Mandatory, ..Default::default() };
|
||||
let mandatory2 =
|
||||
DispatchInfo { weight: 6, class: DispatchClass::Mandatory, ..Default::default() };
|
||||
|
||||
// when
|
||||
assert_ok!(
|
||||
calculate_consumed_weight::<<Test as Config>::Call>(
|
||||
maximum_weight.clone(), all_weight.clone(), &mandatory1
|
||||
)
|
||||
);
|
||||
assert_ok!(calculate_consumed_weight::<<Test as Config>::Call>(
|
||||
maximum_weight.clone(),
|
||||
all_weight.clone(),
|
||||
&mandatory1
|
||||
));
|
||||
assert_err!(
|
||||
calculate_consumed_weight::<<Test as Config>::Call>( maximum_weight, all_weight, &mandatory2),
|
||||
calculate_consumed_weight::<<Test as Config>::Call>(
|
||||
maximum_weight,
|
||||
all_weight,
|
||||
&mandatory2
|
||||
),
|
||||
InvalidTransaction::ExhaustsResources
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user