mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 14:51:07 +00:00
Rename pallet trait Trait to Config (#7599)
* rename Trait to Config * add test asserting using Trait is still valid. * fix ui tests
This commit is contained in:
committed by
GitHub
parent
dd3c84c362
commit
1cbfc9257f
@@ -15,7 +15,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::{Trait, Module};
|
||||
use crate::{Config, Module};
|
||||
use codec::{Encode, Decode};
|
||||
use sp_runtime::{
|
||||
traits::{SignedExtension, DispatchInfoOf, Dispatchable, PostDispatchInfoOf, Printable},
|
||||
@@ -33,9 +33,9 @@ use frame_support::{
|
||||
|
||||
/// Block resource (weight) limit check.
|
||||
#[derive(Encode, Decode, Clone, Eq, PartialEq, Default)]
|
||||
pub struct CheckWeight<T: Trait + Send + Sync>(sp_std::marker::PhantomData<T>);
|
||||
pub struct CheckWeight<T: Config + Send + Sync>(sp_std::marker::PhantomData<T>);
|
||||
|
||||
impl<T: Trait + Send + Sync> CheckWeight<T> where
|
||||
impl<T: Config + Send + Sync> CheckWeight<T> where
|
||||
T::Call: Dispatchable<Info=DispatchInfo, PostInfo=PostDispatchInfo>
|
||||
{
|
||||
/// Get the quota ratio of each dispatch class type. This indicates that all operational and mandatory
|
||||
@@ -213,7 +213,7 @@ impl<T: Trait + Send + Sync> CheckWeight<T> where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait + Send + Sync> SignedExtension for CheckWeight<T> where
|
||||
impl<T: Config + Send + Sync> SignedExtension for CheckWeight<T> where
|
||||
T::Call: Dispatchable<Info=DispatchInfo, PostInfo=PostDispatchInfo>
|
||||
{
|
||||
type AccountId = T::AccountId;
|
||||
@@ -294,7 +294,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckWeight<T> where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait + Send + Sync> sp_std::fmt::Debug for CheckWeight<T> {
|
||||
impl<T: Config + Send + Sync> sp_std::fmt::Debug for CheckWeight<T> {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
|
||||
write!(f, "CheckWeight")
|
||||
@@ -316,11 +316,11 @@ mod tests {
|
||||
use frame_support::weights::{Weight, Pays};
|
||||
|
||||
fn normal_weight_limit() -> Weight {
|
||||
<Test as Trait>::AvailableBlockRatio::get() * <Test as Trait>::MaximumBlockWeight::get()
|
||||
<Test as Config>::AvailableBlockRatio::get() * <Test as Config>::MaximumBlockWeight::get()
|
||||
}
|
||||
|
||||
fn normal_length_limit() -> u32 {
|
||||
<Test as Trait>::AvailableBlockRatio::get() * <Test as Trait>::MaximumBlockLength::get()
|
||||
<Test as Config>::AvailableBlockRatio::get() * <Test as Config>::MaximumBlockLength::get()
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -341,7 +341,7 @@ mod tests {
|
||||
check(|max, len| {
|
||||
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(max, len));
|
||||
assert_eq!(System::block_weight().total(), Weight::max_value());
|
||||
assert!(System::block_weight().total() > <Test as Trait>::MaximumBlockWeight::get());
|
||||
assert!(System::block_weight().total() > <Test as Config>::MaximumBlockWeight::get());
|
||||
});
|
||||
check(|max, len| {
|
||||
assert_ok!(CheckWeight::<Test>::do_validate(max, len));
|
||||
@@ -352,7 +352,7 @@ mod tests {
|
||||
fn normal_extrinsic_limited_by_maximum_extrinsic_weight() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let max = DispatchInfo {
|
||||
weight: <Test as Trait>::MaximumExtrinsicWeight::get() + 1,
|
||||
weight: <Test as Config>::MaximumExtrinsicWeight::get() + 1,
|
||||
class: DispatchClass::Normal,
|
||||
..Default::default()
|
||||
};
|
||||
@@ -370,9 +370,9 @@ mod tests {
|
||||
new_test_ext().execute_with(|| {
|
||||
let operational_limit = CheckWeight::<Test>::get_dispatch_limit_ratio(
|
||||
DispatchClass::Operational
|
||||
) * <Test as Trait>::MaximumBlockWeight::get();
|
||||
let base_weight = <Test as Trait>::ExtrinsicBaseWeight::get();
|
||||
let block_base = <Test as Trait>::BlockExecutionWeight::get();
|
||||
) * <Test as Config>::MaximumBlockWeight::get();
|
||||
let base_weight = <Test as Config>::ExtrinsicBaseWeight::get();
|
||||
let block_base = <Test as Config>::BlockExecutionWeight::get();
|
||||
|
||||
let weight = operational_limit - base_weight - block_base;
|
||||
let okay = DispatchInfo {
|
||||
@@ -406,7 +406,7 @@ mod tests {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::register_extra_weight_unchecked(Weight::max_value(), DispatchClass::Normal);
|
||||
assert_eq!(System::block_weight().total(), Weight::max_value());
|
||||
assert!(System::block_weight().total() > <Test as Trait>::MaximumBlockWeight::get());
|
||||
assert!(System::block_weight().total() > <Test as Config>::MaximumBlockWeight::get());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -426,8 +426,8 @@ mod tests {
|
||||
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&max_normal, len));
|
||||
assert_eq!(System::block_weight().total(), 768);
|
||||
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&rest_operational, len));
|
||||
assert_eq!(<Test as Trait>::MaximumBlockWeight::get(), 1024);
|
||||
assert_eq!(System::block_weight().total(), <Test as Trait>::MaximumBlockWeight::get());
|
||||
assert_eq!(<Test as Config>::MaximumBlockWeight::get(), 1024);
|
||||
assert_eq!(System::block_weight().total(), <Test as Config>::MaximumBlockWeight::get());
|
||||
// Checking single extrinsic should not take current block weight into account.
|
||||
assert_eq!(CheckWeight::<Test>::check_extrinsic_weight(&rest_operational), Ok(()));
|
||||
});
|
||||
@@ -446,8 +446,8 @@ mod tests {
|
||||
// Extra 15 here from block execution + base extrinsic weight
|
||||
assert_eq!(System::block_weight().total(), 266);
|
||||
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&max_normal, len));
|
||||
assert_eq!(<Test as Trait>::MaximumBlockWeight::get(), 1024);
|
||||
assert_eq!(System::block_weight().total(), <Test as Trait>::MaximumBlockWeight::get());
|
||||
assert_eq!(<Test as Config>::MaximumBlockWeight::get(), 1024);
|
||||
assert_eq!(System::block_weight().total(), <Test as Config>::MaximumBlockWeight::get());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -553,11 +553,11 @@ mod tests {
|
||||
let normal_limit = normal_weight_limit();
|
||||
let small = DispatchInfo { weight: 100, ..Default::default() };
|
||||
let medium = DispatchInfo {
|
||||
weight: normal_limit - <Test as Trait>::ExtrinsicBaseWeight::get(),
|
||||
weight: normal_limit - <Test as Config>::ExtrinsicBaseWeight::get(),
|
||||
..Default::default()
|
||||
};
|
||||
let big = DispatchInfo {
|
||||
weight: normal_limit - <Test as Trait>::ExtrinsicBaseWeight::get() + 1,
|
||||
weight: normal_limit - <Test as Config>::ExtrinsicBaseWeight::get() + 1,
|
||||
..Default::default()
|
||||
};
|
||||
let len = 0_usize;
|
||||
@@ -589,7 +589,7 @@ mod tests {
|
||||
|
||||
// We allow 75% for normal transaction, so we put 25% - extrinsic base weight
|
||||
BlockWeight::mutate(|current_weight| {
|
||||
current_weight.put(256 - <Test as Trait>::ExtrinsicBaseWeight::get(), DispatchClass::Normal)
|
||||
current_weight.put(256 - <Test as Config>::ExtrinsicBaseWeight::get(), DispatchClass::Normal)
|
||||
});
|
||||
|
||||
let pre = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &info, len).unwrap();
|
||||
@@ -623,7 +623,7 @@ mod tests {
|
||||
let pre = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &info, len).unwrap();
|
||||
assert_eq!(
|
||||
BlockWeight::get().total(),
|
||||
info.weight + 128 + <Test as Trait>::ExtrinsicBaseWeight::get(),
|
||||
info.weight + 128 + <Test as Config>::ExtrinsicBaseWeight::get(),
|
||||
);
|
||||
|
||||
assert!(
|
||||
@@ -632,7 +632,7 @@ mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
BlockWeight::get().total(),
|
||||
info.weight + 128 + <Test as Trait>::ExtrinsicBaseWeight::get(),
|
||||
info.weight + 128 + <Test as Config>::ExtrinsicBaseWeight::get(),
|
||||
);
|
||||
})
|
||||
}
|
||||
@@ -644,12 +644,12 @@ mod tests {
|
||||
let len = 0_usize;
|
||||
|
||||
// Initial weight from `BlockExecutionWeight`
|
||||
assert_eq!(System::block_weight().total(), <Test as Trait>::BlockExecutionWeight::get());
|
||||
assert_eq!(System::block_weight().total(), <Test as Config>::BlockExecutionWeight::get());
|
||||
let r = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &free, len);
|
||||
assert!(r.is_ok());
|
||||
assert_eq!(
|
||||
System::block_weight().total(),
|
||||
<Test as Trait>::ExtrinsicBaseWeight::get() + <Test as Trait>::BlockExecutionWeight::get()
|
||||
<Test as Config>::ExtrinsicBaseWeight::get() + <Test as Config>::BlockExecutionWeight::get()
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user