diff --git a/Cargo.lock b/Cargo.lock index dad578ba0c1b..a659a7810cc4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14031,16 +14031,11 @@ dependencies = [ name = "pallet-nis" version = "28.0.0" dependencies = [ - "frame-benchmarking 28.0.0", - "frame-support 28.0.0", - "frame-system 28.0.0", "pallet-balances 28.0.0", "parity-scale-codec", + "polkadot-sdk-frame 0.1.0", "scale-info", - "sp-arithmetic 23.0.0", - "sp-core 28.0.0", "sp-io 30.0.0", - "sp-runtime 31.0.1", ] [[package]] diff --git a/prdoc/pr_6293.prdoc b/prdoc/pr_6293.prdoc new file mode 100644 index 000000000000..9a82745c5e25 --- /dev/null +++ b/prdoc/pr_6293.prdoc @@ -0,0 +1,10 @@ +title: Migrate pallet-nis benchmark to v2 +doc: +- audience: Runtime Dev + description: |- + Part of: + + - #6202. +crates: +- name: pallet-nis + bump: patch diff --git a/substrate/frame/nis/Cargo.toml b/substrate/frame/nis/Cargo.toml index 78e086d0ed12..909cf03c563e 100644 --- a/substrate/frame/nis/Cargo.toml +++ b/substrate/frame/nis/Cargo.toml @@ -18,12 +18,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { features = ["derive"], workspace = true } scale-info = { features = ["derive"], workspace = true } -frame-benchmarking = { optional = true, workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } -sp-arithmetic = { workspace = true } -sp-core = { workspace = true } -sp-runtime = { workspace = true } +frame = { workspace = true, features = ["experimental", "runtime"] } [dev-dependencies] pallet-balances = { workspace = true, default-features = true } @@ -33,26 +28,14 @@ sp-io = { workspace = true, default-features = true } default = ["std"] std = [ "codec/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", - "pallet-balances/std", + "frame/std", "scale-info/std", - "sp-arithmetic/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", + "frame/runtime-benchmarks", "pallet-balances/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", + "frame/try-runtime", "pallet-balances/try-runtime", - "sp-runtime/try-runtime", ] diff --git a/substrate/frame/nis/src/benchmarking.rs b/substrate/frame/nis/src/benchmarking.rs index 2c7ad651f990..26024e1a6250 100644 --- a/substrate/frame/nis/src/benchmarking.rs +++ b/substrate/frame/nis/src/benchmarking.rs @@ -19,19 +19,9 @@ #![cfg(feature = "runtime-benchmarks")] -use super::*; -use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller, BenchmarkError}; -use frame_support::traits::{ - fungible::Inspect as FunInspect, nonfungible::Inspect, EnsureOrigin, Get, -}; -use frame_system::RawOrigin; -use sp_arithmetic::Perquintill; -use sp_runtime::{ - traits::{Bounded, One, Zero}, - DispatchError, PerThing, -}; - -use crate::Pallet as Nis; +use frame::benchmarking::prelude::*; + +use crate::*; const SEED: u32 = 0; @@ -49,62 +39,88 @@ fn fill_queues() -> Result<(), DispatchError> { T::Currency::set_balance(&caller, T::MinBid::get() * BalanceOf::::from(queues + bids)); for _ in 0..bids { - Nis::::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?; + Pallet::::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?; } for d in 1..queues { - Nis::::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1 + d)?; + Pallet::::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1 + d)?; } Ok(()) } -benchmarks! { - place_bid { - let l in 0..(T::MaxQueueLen::get() - 1); +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn place_bid(l: Linear<0, { T::MaxQueueLen::get() - 1 }>) -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); let ed = T::Currency::minimum_balance(); let bid = T::MinBid::get(); T::Currency::set_balance(&caller, (ed + bid) * BalanceOf::::from(l + 1) + bid); - for i in 0..l { - Nis::::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?; + for _ in 0..l { + Pallet::::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?; } - }: _(RawOrigin::Signed(caller.clone()), T::MinBid::get() * BalanceOf::::from(2u32), 1) - verify { - assert_eq!(QueueTotals::::get()[0], (l + 1, T::MinBid::get() * BalanceOf::::from(l + 2))); + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), T::MinBid::get() * BalanceOf::::from(2_u32), 1); + + assert_eq!( + QueueTotals::::get()[0], + (l + 1, T::MinBid::get() * BalanceOf::::from(l + 2)) + ); + + Ok(()) } - place_bid_max { + #[benchmark] + fn place_bid_max() -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); let origin = RawOrigin::Signed(caller.clone()); let ed = T::Currency::minimum_balance(); let bid = T::MinBid::get(); let ql = T::MaxQueueLen::get(); T::Currency::set_balance(&caller, (ed + bid) * BalanceOf::::from(ql + 1) + bid); - for i in 0..T::MaxQueueLen::get() { - Nis::::place_bid(origin.clone().into(), T::MinBid::get(), 1)?; + for _ in 0..T::MaxQueueLen::get() { + Pallet::::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?; } - }: place_bid(origin, T::MinBid::get() * BalanceOf::::from(2u32), 1) - verify { - assert_eq!(QueueTotals::::get()[0], ( - T::MaxQueueLen::get(), - T::MinBid::get() * BalanceOf::::from(T::MaxQueueLen::get() + 1), - )); + + #[extrinsic_call] + place_bid(origin, T::MinBid::get() * BalanceOf::::from(2_u32), 1); + + assert_eq!( + QueueTotals::::get()[0], + ( + T::MaxQueueLen::get(), + T::MinBid::get() * BalanceOf::::from(T::MaxQueueLen::get() + 1), + ) + ); + + Ok(()) } - retract_bid { - let l in 1..T::MaxQueueLen::get(); + #[benchmark] + fn retract_bid(l: Linear<1, { T::MaxQueueLen::get() }>) -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); let ed = T::Currency::minimum_balance(); let bid = T::MinBid::get(); T::Currency::set_balance(&caller, (ed + bid) * BalanceOf::::from(l + 1) + bid); - for i in 0..l { - Nis::::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?; + for _ in 0..l { + Pallet::::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?; } - }: _(RawOrigin::Signed(caller.clone()), T::MinBid::get(), 1) - verify { - assert_eq!(QueueTotals::::get()[0], (l - 1, T::MinBid::get() * BalanceOf::::from(l - 1))); + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), T::MinBid::get(), 1); + + assert_eq!( + QueueTotals::::get()[0], + (l - 1, T::MinBid::get() * BalanceOf::::from(l - 1)) + ); + + Ok(()) } - fund_deficit { + #[benchmark] + fn fund_deficit() -> Result<(), BenchmarkError> { T::BenchmarkSetup::create_counterpart_asset(); let origin = T::FundOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; @@ -112,49 +128,65 @@ benchmarks! { let bid = T::MinBid::get().max(One::one()); let ed = T::Currency::minimum_balance(); T::Currency::set_balance(&caller, ed + bid); - Nis::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; - Nis::::process_queues(Perquintill::one(), 1, 1, &mut WeightCounter::unlimited()); - Nis::::communify(RawOrigin::Signed(caller.clone()).into(), 0)?; - let original = T::Currency::balance(&Nis::::account_id()); - T::Currency::set_balance(&Nis::::account_id(), BalanceOf::::min_value()); - }: _(origin) - verify { + Pallet::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; + Pallet::::process_queues(Perquintill::one(), 1, 1, &mut WeightCounter::unlimited()); + Pallet::::communify(RawOrigin::Signed(caller.clone()).into(), 0)?; + let original = T::Currency::balance(&Pallet::::account_id()); + T::Currency::set_balance(&Pallet::::account_id(), BalanceOf::::min_value()); + + #[extrinsic_call] + _(origin as T::RuntimeOrigin); + // Must fund at least 99.999% of the required amount. - let missing = Perquintill::from_rational( - T::Currency::balance(&Nis::::account_id()), original).left_from_one(); + let missing = + Perquintill::from_rational(T::Currency::balance(&Pallet::::account_id()), original) + .left_from_one(); assert!(missing <= Perquintill::one() / 100_000); + + Ok(()) } - communify { + #[benchmark] + fn communify() -> Result<(), BenchmarkError> { T::BenchmarkSetup::create_counterpart_asset(); let caller: T::AccountId = whitelisted_caller(); let bid = T::MinBid::get().max(One::one()) * 100u32.into(); let ed = T::Currency::minimum_balance(); T::Currency::set_balance(&caller, ed + bid + bid); - Nis::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; - Nis::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; - Nis::::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited()); - }: _(RawOrigin::Signed(caller.clone()), 0) - verify { - assert_eq!(Nis::::owner(&0), None); + Pallet::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; + Pallet::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; + Pallet::::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited()); + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), 0); + + assert_eq!(Pallet::::owner(&0), None); + + Ok(()) } - privatize { + #[benchmark] + fn privatize() -> Result<(), BenchmarkError> { T::BenchmarkSetup::create_counterpart_asset(); let caller: T::AccountId = whitelisted_caller(); let bid = T::MinBid::get().max(One::one()); let ed = T::Currency::minimum_balance(); T::Currency::set_balance(&caller, ed + bid + bid); - Nis::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; - Nis::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; - Nis::::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited()); - Nis::::communify(RawOrigin::Signed(caller.clone()).into(), 0)?; - }: _(RawOrigin::Signed(caller.clone()), 0) - verify { - assert_eq!(Nis::::owner(&0), Some(caller)); + Pallet::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; + Pallet::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; + Pallet::::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited()); + Pallet::::communify(RawOrigin::Signed(caller.clone()).into(), 0)?; + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), 0); + + assert_eq!(Pallet::::owner(&0), Some(caller)); + + Ok(()) } - thaw_private { + #[benchmark] + fn thaw_private() -> Result<(), BenchmarkError> { T::BenchmarkSetup::create_counterpart_asset(); let whale: T::AccountId = account("whale", 0, SEED); let caller: T::AccountId = whitelisted_caller(); @@ -162,17 +194,27 @@ benchmarks! { let ed = T::Currency::minimum_balance(); T::Currency::set_balance(&caller, ed + bid + bid); // Ensure we don't get throttled. - T::Currency::set_balance(&whale, T::ThawThrottle::get().0.saturating_reciprocal_mul_ceil(T::Currency::balance(&caller))); - Nis::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; - Nis::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; - Nis::::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited()); + T::Currency::set_balance( + &whale, + T::ThawThrottle::get() + .0 + .saturating_reciprocal_mul_ceil(T::Currency::balance(&caller)), + ); + Pallet::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; + Pallet::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; + Pallet::::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited()); frame_system::Pallet::::set_block_number(Receipts::::get(0).unwrap().expiry); - }: _(RawOrigin::Signed(caller.clone()), 0, None) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), 0, None); + assert!(Receipts::::get(0).is_none()); + + Ok(()) } - thaw_communal { + #[benchmark] + fn thaw_communal() -> Result<(), BenchmarkError> { T::BenchmarkSetup::create_counterpart_asset(); let whale: T::AccountId = account("whale", 0, SEED); let caller: T::AccountId = whitelisted_caller(); @@ -180,69 +222,93 @@ benchmarks! { let ed = T::Currency::minimum_balance(); T::Currency::set_balance(&caller, ed + bid + bid); // Ensure we don't get throttled. - T::Currency::set_balance(&whale, T::ThawThrottle::get().0.saturating_reciprocal_mul_ceil(T::Currency::balance(&caller))); - Nis::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; - Nis::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; - Nis::::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited()); + T::Currency::set_balance( + &whale, + T::ThawThrottle::get() + .0 + .saturating_reciprocal_mul_ceil(T::Currency::balance(&caller)), + ); + Pallet::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; + Pallet::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; + Pallet::::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited()); frame_system::Pallet::::set_block_number(Receipts::::get(0).unwrap().expiry); - Nis::::communify(RawOrigin::Signed(caller.clone()).into(), 0)?; - }: _(RawOrigin::Signed(caller.clone()), 0) - verify { + Pallet::::communify(RawOrigin::Signed(caller.clone()).into(), 0)?; + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), 0); + assert!(Receipts::::get(0).is_none()); + + Ok(()) } - process_queues { + #[benchmark] + fn process_queues() -> Result<(), BenchmarkError> { fill_queues::()?; - }: { - Nis::::process_queues( - Perquintill::one(), - Zero::zero(), - u32::max_value(), - &mut WeightCounter::unlimited(), - ) + + #[block] + { + Pallet::::process_queues( + Perquintill::one(), + Zero::zero(), + u32::max_value(), + &mut WeightCounter::unlimited(), + ); + } + + Ok(()) } - process_queue { - let our_account = Nis::::account_id(); - let issuance = Nis::::issuance(); + #[benchmark] + fn process_queue() { + let our_account = Pallet::::account_id(); + let issuance = Pallet::::issuance(); let mut summary = Summary::::get(); - }: { - Nis::::process_queue( - 1u32, - 1u32.into(), - &our_account, - &issuance, - 0, - &mut Bounded::max_value(), - &mut (T::MaxQueueLen::get(), Bounded::max_value()), - &mut summary, - &mut WeightCounter::unlimited(), - ) + + #[block] + { + Pallet::::process_queue( + 1_u32, + 1_u32.into(), + &our_account, + &issuance, + 0, + &mut Bounded::max_value(), + &mut (T::MaxQueueLen::get(), Bounded::max_value()), + &mut summary, + &mut WeightCounter::unlimited(), + ); + } } - process_bid { + #[benchmark] + fn process_bid() { let who = account::("bidder", 0, SEED); let min_bid = T::MinBid::get().max(One::one()); let ed = T::Currency::minimum_balance(); T::Currency::set_balance(&who, ed + min_bid); - let bid = Bid { - amount: T::MinBid::get(), - who, - }; - let our_account = Nis::::account_id(); - let issuance = Nis::::issuance(); + let bid = Bid { amount: T::MinBid::get(), who }; + let our_account = Pallet::::account_id(); + let issuance = Pallet::::issuance(); let mut summary = Summary::::get(); - }: { - Nis::::process_bid( - bid, - 2u32.into(), - &our_account, - &issuance, - &mut Bounded::max_value(), - &mut Bounded::max_value(), - &mut summary, - ) + + #[block] + { + Pallet::::process_bid( + bid, + 2_u32.into(), + &our_account, + &issuance, + &mut Bounded::max_value(), + &mut Bounded::max_value(), + &mut summary, + ); + } } - impl_benchmark_test_suite!(Nis, crate::mock::new_test_ext_empty(), crate::mock::Test); + impl_benchmark_test_suite! { + Pallet, + mock::new_test_ext_empty(), + mock::Test + } } diff --git a/substrate/frame/nis/src/lib.rs b/substrate/frame/nis/src/lib.rs index 87e2276e768d..6c53c0f3674a 100644 --- a/substrate/frame/nis/src/lib.rs +++ b/substrate/frame/nis/src/lib.rs @@ -78,24 +78,37 @@ extern crate alloc; -use frame_support::traits::{ - fungible::{self, Inspect as FunInspect, Mutate as FunMutate}, - tokens::{DepositConsequence, Fortitude, Preservation, Provenance, WithdrawConsequence}, -}; -pub use pallet::*; -use sp_arithmetic::{traits::Unsigned, RationalArg}; -use sp_core::TypedGet; -use sp_runtime::{ - traits::{Convert, ConvertBack}, - DispatchError, Perquintill, -}; +pub mod weights; mod benchmarking; #[cfg(test)] mod mock; #[cfg(test)] mod tests; -pub mod weights; + +pub use pallet::*; +pub use weights::WeightInfo; + +use alloc::{vec, vec::Vec}; +use frame::{ + prelude::*, + traits::{ + fungible::{ + self, Balanced as FunBalanced, Inspect as FunInspect, Mutate as FunMutate, + MutateHold as FunMutateHold, + }, + nonfungible::{Inspect as NftInspect, Transfer as NftTransfer}, + tokens::{ + Balance, DepositConsequence, + Fortitude::{self, *}, + Precision::*, + Preservation::{self, *}, + Provenance, + Restriction::*, + WithdrawConsequence, + }, + }, +}; pub struct WithMaximumOf(core::marker::PhantomData); impl Convert for WithMaximumOf @@ -169,33 +182,9 @@ impl BenchmarkSetup for () { fn create_counterpart_asset() {} } -#[frame_support::pallet] +#[frame::pallet] pub mod pallet { - use super::{FunInspect, FunMutate}; - pub use crate::weights::WeightInfo; - use alloc::{vec, vec::Vec}; - use frame_support::{ - pallet_prelude::*, - traits::{ - fungible::{self, hold::Mutate as FunHoldMutate, Balanced as FunBalanced}, - nonfungible::{Inspect as NftInspect, Transfer as NftTransfer}, - tokens::{ - Balance, - Fortitude::Polite, - Precision::{BestEffort, Exact}, - Preservation::Expendable, - Restriction::{Free, OnHold}, - }, - Defensive, DefensiveSaturating, OnUnbalanced, - }, - PalletId, - }; - use frame_system::pallet_prelude::*; - use sp_arithmetic::{PerThing, Perquintill}; - use sp_runtime::{ - traits::{AccountIdConversion, Bounded, Convert, ConvertBack, Saturating, Zero}, - Rounding, TokenError, - }; + use super::*; type BalanceOf = <::Currency as FunInspect<::AccountId>>::Balance; @@ -224,7 +213,7 @@ pub mod pallet { type Currency: FunInspect + FunMutate + FunBalanced - + FunHoldMutate; + + FunMutateHold; /// Overarching hold reason. type RuntimeHoldReason: From; diff --git a/substrate/frame/nis/src/mock.rs b/substrate/frame/nis/src/mock.rs index 2b008f8ec2a4..8b259517e59c 100644 --- a/substrate/frame/nis/src/mock.rs +++ b/substrate/frame/nis/src/mock.rs @@ -17,32 +17,38 @@ //! Test environment for NIS pallet. -use crate::{self as pallet_nis, Perquintill, WithMaximumOf}; - -use frame_support::{ - derive_impl, ord_parameter_types, parameter_types, - traits::{fungible::Inspect, ConstU32, ConstU64, OnFinalize, OnInitialize, StorageMapShim}, - weights::Weight, - PalletId, -}; -use pallet_balances::{Instance1, Instance2}; -use sp_core::ConstU128; -use sp_runtime::BuildStorage; +use frame::{runtime::prelude::*, testing_prelude::*, traits::StorageMapShim}; -type Block = frame_system::mocking::MockBlock; +use crate::{self as pallet_nis, *}; pub type Balance = u64; +type Block = frame_system::mocking::MockBlock; + // Configure a mock runtime to test the pallet. -frame_support::construct_runtime!( - pub enum Test - { - System: frame_system, - Balances: pallet_balances::, - NisBalances: pallet_balances::, - Nis: pallet_nis, - } -); +#[frame_construct_runtime] +mod runtime { + #[runtime::runtime] + #[runtime::derive( + RuntimeCall, + RuntimeError, + RuntimeEvent, + RuntimeFreezeReason, + RuntimeHoldReason, + RuntimeOrigin, + RuntimeTask + )] + pub struct Test; + + #[runtime::pallet_index(0)] + pub type System = frame_system; + #[runtime::pallet_index(1)] + pub type Balances = pallet_balances; + #[runtime::pallet_index(2)] + pub type NisBalances = pallet_balances; + #[runtime::pallet_index(3)] + pub type Nis = pallet_nis; +} #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { @@ -50,7 +56,7 @@ impl frame_system::Config for Test { type AccountData = pallet_balances::AccountData; } -impl pallet_balances::Config for Test { +impl pallet_balances::Config for Test { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; @@ -67,13 +73,13 @@ impl pallet_balances::Config for Test { type DoneSlashHandler = (); } -impl pallet_balances::Config for Test { +impl pallet_balances::Config for Test { type Balance = u128; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; type ExistentialDeposit = ConstU128<1>; type AccountStore = StorageMapShim< - pallet_balances::Account, + pallet_balances::Account, u64, pallet_balances::AccountData, >; @@ -106,7 +112,7 @@ impl pallet_nis::Config for Test { type RuntimeEvent = RuntimeEvent; type PalletId = NisPalletId; type Currency = Balances; - type CurrencyBalance = >::Balance; + type CurrencyBalance = >::Balance; type FundOrigin = frame_system::EnsureSigned; type Deficit = (); type IgnoredIssuance = IgnoredIssuance; @@ -131,7 +137,7 @@ impl pallet_nis::Config for Test { // our desired mockup. pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - pallet_balances::GenesisConfig:: { + pallet_balances::GenesisConfig:: { balances: vec![(1, 100), (2, 100), (3, 100), (4, 100)], } .assimilate_storage(&mut t) diff --git a/substrate/frame/nis/src/tests.rs b/substrate/frame/nis/src/tests.rs index a17aaf421827..dce2538027a9 100644 --- a/substrate/frame/nis/src/tests.rs +++ b/substrate/frame/nis/src/tests.rs @@ -17,20 +17,14 @@ //! Tests for NIS pallet. -use super::*; -use crate::{mock::*, Error}; -use frame_support::{ - assert_noop, assert_ok, - traits::{ - fungible::{hold::Inspect as InspectHold, Inspect as FunInspect, Mutate as FunMutate}, - nonfungible::{Inspect, Transfer}, - tokens::{Fortitude::Force, Precision::Exact, Preservation::Expendable}, - }, +use frame::{ + runtime::prelude::TokenError::FundsUnavailable, testing_prelude::*, + traits::fungible::InspectHold, }; -use sp_arithmetic::Perquintill; -use sp_runtime::{ - Saturating, - TokenError::{self, FundsUnavailable}, + +use crate::{ + mock::{Balance, *}, + *, }; fn pot() -> Balance { diff --git a/substrate/frame/nis/src/weights.rs b/substrate/frame/nis/src/weights.rs index 4f476fd22c21..6853df2f6a95 100644 --- a/substrate/frame/nis/src/weights.rs +++ b/substrate/frame/nis/src/weights.rs @@ -46,8 +46,7 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use core::marker::PhantomData; +use frame::weights_prelude::*; /// Weight functions needed for `pallet_nis`. pub trait WeightInfo { diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 03d815e349df..43516238c2da 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -190,7 +190,7 @@ pub mod prelude { /// `frame_system`'s parent crate, which is mandatory in all pallets build with this crate. /// /// Conveniently, the keyword `frame_system` is in scope as one uses `use - /// polkadot_sdk_frame::prelude::*` + /// polkadot_sdk_frame::prelude::*`. #[doc(inline)] pub use frame_system; @@ -200,30 +200,35 @@ pub mod prelude { #[doc(no_inline)] pub use frame_support::pallet_prelude::*; - /// Dispatch types from `frame-support`, other fundamental traits + /// Dispatch types from `frame-support`, other fundamental traits. #[doc(no_inline)] pub use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo}; - pub use frame_support::traits::{Contains, IsSubType, OnRuntimeUpgrade}; + pub use frame_support::traits::{ + Contains, Defensive, DefensiveSaturating, IsSubType, OnRuntimeUpgrade, OnUnbalanced, + }; /// Pallet prelude of `frame-system`. #[doc(no_inline)] pub use frame_system::pallet_prelude::*; + /// All arithmetic types and traits. + pub use super::arithmetic::*; + /// All FRAME-relevant derive macros. #[doc(no_inline)] pub use super::derive::*; - /// All hashing related things + /// All hashing related things. pub use super::hashing::*; - /// Runtime traits + /// Runtime traits. #[doc(no_inline)] pub use sp_runtime::traits::{ - BlockNumberProvider, Bounded, DispatchInfoOf, Dispatchable, SaturatedConversion, - Saturating, StaticLookup, TrailingZeroInput, + AccountIdConversion, BlockNumberProvider, Bounded, Convert, ConvertBack, DispatchInfoOf, + Dispatchable, SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput, }; - /// Other error/result types for runtime + /// Other error/result types for runtime. #[doc(no_inline)] pub use sp_runtime::{DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError}; } diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index c64987b17d35..20c0dec4e9c2 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -909,7 +909,7 @@ pub mod pallet_prelude { Task, TypedGet, }, Blake2_128, Blake2_128Concat, Blake2_256, CloneNoBound, DebugNoBound, EqNoBound, Identity, - PartialEqNoBound, RuntimeDebugNoBound, Twox128, Twox256, Twox64Concat, + PalletId, PartialEqNoBound, RuntimeDebugNoBound, Twox128, Twox256, Twox64Concat, }; pub use codec::{Decode, Encode, MaxEncodedLen}; pub use core::marker::PhantomData;