diff --git a/Cargo.lock b/Cargo.lock index 3c55a14256c5..e69d7098b7c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15687,19 +15687,13 @@ dependencies = [ name = "pallet-tips" version = "27.0.0" dependencies = [ - "frame-benchmarking 28.0.0", - "frame-support 28.0.0", - "frame-system 28.0.0", "log", "pallet-balances 28.0.0", "pallet-treasury 27.0.0", "parity-scale-codec", + "polkadot-sdk-frame 0.1.0", "scale-info", "serde", - "sp-core 28.0.0", - "sp-io 30.0.0", - "sp-runtime 31.0.1", - "sp-storage 19.0.0", ] [[package]] diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index b3e340cbcbff..f05549e4d79f 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -204,7 +204,8 @@ pub mod prelude { #[doc(no_inline)] pub use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo}; pub use frame_support::traits::{ - Contains, EstimateNextSessionRotation, IsSubType, OnRuntimeUpgrade, OneSessionHandler, + Contains, EstimateNextSessionRotation, Everything, InsideBoth, InstanceFilter, IsSubType, + OnRuntimeUpgrade, OneSessionHandler, VariantCount, VariantCountOf, }; /// Pallet prelude of `frame-system`. @@ -222,6 +223,9 @@ pub mod prelude { /// All hashing related things pub use super::hashing::*; + /// All account related things. + pub use super::account::*; + /// All arithmetic types and traits used for safe math. pub use super::arithmetic::*; @@ -235,7 +239,9 @@ pub mod prelude { /// Other runtime types and traits #[doc(no_inline)] pub use sp_runtime::{ - BoundToRuntimeAppPublic, DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError, + BoundToRuntimeAppPublic, + DispatchError::{self, BadOrigin}, + DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError, }; } @@ -319,7 +325,7 @@ pub mod testing_prelude { /// Other helper macros from `frame_support` that help with asserting in tests. pub use frame_support::{ assert_err, assert_err_ignore_postinfo, assert_error_encoded_size, assert_noop, assert_ok, - assert_storage_noop, storage_alias, + assert_storage_noop, ensure, storage_alias, }; pub use frame_system::{self, mocking::*}; @@ -345,6 +351,11 @@ pub mod runtime { pub mod prelude { pub use crate::prelude::*; + /// All things runtime metadata. + pub use frame_support::traits::{ + CallMetadata, GetCallMetadata, PalletInfoAccess, STORAGE_VERSION_STORAGE_KEY_POSTFIX, + }; + /// All of the types related to the FRAME runtime executive. pub use frame_executive::*; @@ -361,6 +372,12 @@ pub mod runtime { /// Macro to easily derive the `Config` trait of various pallet for `Runtime`. pub use frame_support::derive_impl; + /// sovereign account ID for a pallet. + pub use frame_support::PalletId; + + /// Runtime storage traits amd types. + pub use frame_support::storage::{migration::*, KeyPrefixIterator, StoragePrefixedMap}; + /// Macros to easily impl traits such as `Get` for types. // TODO: using linking in the Get in the line above triggers an ICE :/ pub use frame_support::{ord_parameter_types, parameter_types}; @@ -545,6 +562,17 @@ pub mod hashing { pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256}; } +/// All account management related traits. +/// +/// This is already part of the [`prelude`]. +pub mod account { + pub use frame_support::traits::{ + ChangeMembers, ContainsLengthBound, EitherOfDiverse, InitializeMembers, NeverEnsureOrigin, + SortedMembers, + }; + pub use sp_runtime::traits::{AccountIdConversion, IdentifyAccount, IdentityLookup}; +} + /// Access to all of the dependencies of this crate. In case the prelude re-exports are not enough, /// this module can be used. /// diff --git a/substrate/frame/tips/Cargo.toml b/substrate/frame/tips/Cargo.toml index 6b5b89e7a197..e3096e17889b 100644 --- a/substrate/frame/tips/Cargo.toml +++ b/substrate/frame/tips/Cargo.toml @@ -17,50 +17,33 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { features = ["derive"], workspace = true } -frame-benchmarking = { optional = true, workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } log = { workspace = true } -pallet-treasury = { workspace = true } scale-info = { features = ["derive"], workspace = true } serde = { features = ["derive"], optional = true, workspace = true, default-features = true } -sp-core = { workspace = true } -sp-io = { workspace = true } -sp-runtime = { workspace = true } +frame = { workspace = true, features = ["experimental", "runtime"] } +pallet-treasury = { workspace = true } [dev-dependencies] pallet-balances = { workspace = true, default-features = true } -sp-storage = { workspace = true, default-features = true } [features] default = ["std"] std = [ "codec/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", + "frame/std", "log/std", "pallet-balances/std", "pallet-treasury/std", "scale-info/std", "serde", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", - "sp-storage/std", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", + "frame/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-treasury/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", + "frame/try-runtime", "pallet-balances/try-runtime", "pallet-treasury/try-runtime", - "sp-runtime/try-runtime", ] diff --git a/substrate/frame/tips/src/benchmarking.rs b/substrate/frame/tips/src/benchmarking.rs index 4a991b11b933..8020d055d4d0 100644 --- a/substrate/frame/tips/src/benchmarking.rs +++ b/substrate/frame/tips/src/benchmarking.rs @@ -19,15 +19,9 @@ #![cfg(feature = "runtime-benchmarks")] -use frame_benchmarking::v1::{ - account, benchmarks_instance_pallet, whitelisted_caller, BenchmarkError, -}; -use frame_support::ensure; -use frame_system::RawOrigin; -use sp_runtime::traits::Saturating; - use super::*; use crate::Pallet as TipsMod; +use frame::benchmarking::prelude::*; const SEED: u32 = 0; @@ -78,7 +72,7 @@ fn create_tips, I: 'static>( } Tips::::mutate(hash, |maybe_tip| { if let Some(open_tip) = maybe_tip { - open_tip.closes = Some(frame_system::pallet_prelude::BlockNumberFor::::zero()); + open_tip.closes = Some(BlockNumberFor::::zero()); } }); Ok(()) @@ -97,7 +91,7 @@ benchmarks_instance_pallet! { let awesome_person_lookup = T::Lookup::unlookup(awesome_person); // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller); - frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); + add_to_whitelist(caller_key.into()); }: _(RawOrigin::Signed(caller), reason, awesome_person_lookup) retract_tip { @@ -113,7 +107,7 @@ benchmarks_instance_pallet! { let hash = T::Hashing::hash_of(&(&reason_hash, &awesome_person)); // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller); - frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); + add_to_whitelist(caller_key.into()); }: _(RawOrigin::Signed(caller), hash) tip_new { @@ -124,7 +118,7 @@ benchmarks_instance_pallet! { let beneficiary_lookup = T::Lookup::unlookup(beneficiary); // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller); - frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); + add_to_whitelist(caller_key.into()); }: _(RawOrigin::Signed(caller), reason, beneficiary_lookup, value) tip { @@ -145,7 +139,7 @@ benchmarks_instance_pallet! { let caller = account("member", t - 1, SEED); // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller); - frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); + add_to_whitelist(caller_key.into()); }: _(RawOrigin::Signed(caller), hash, value) close_tip { @@ -175,7 +169,7 @@ benchmarks_instance_pallet! { let caller = account("caller", t, SEED); // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::::hashed_key_for(&caller); - frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); + add_to_whitelist(caller_key.into()); }: _(RawOrigin::Signed(caller), hash) slash_tip { diff --git a/substrate/frame/tips/src/lib.rs b/substrate/frame/tips/src/lib.rs index 67bcdfa0685e..8eebbbb91e46 100644 --- a/substrate/frame/tips/src/lib.rs +++ b/substrate/frame/tips/src/lib.rs @@ -61,26 +61,15 @@ pub mod migrations; pub mod weights; extern crate alloc; - -use sp_runtime::{ - traits::{AccountIdConversion, BadOrigin, Hash, StaticLookup, TrailingZeroInput, Zero}, - Percent, RuntimeDebug, -}; - use alloc::{vec, vec::Vec}; use codec::{Decode, Encode}; -use frame_support::{ - ensure, - traits::{ - ContainsLengthBound, Currency, EnsureOrigin, ExistenceRequirement::KeepAlive, Get, - OnUnbalanced, ReservableCurrency, SortedMembers, - }, - Parameter, +use frame::{ + prelude::*, + traits::{Currency, ExistenceRequirement::KeepAlive, OnUnbalanced, ReservableCurrency}, }; -use frame_system::pallet_prelude::BlockNumberFor; -#[cfg(any(feature = "try-runtime", test))] -use sp_runtime::TryRuntimeError; +#[cfg(feature = "try-runtime")] +use frame::try_runtime::TryRuntimeError; pub use pallet::*; pub use weights::WeightInfo; @@ -118,11 +107,9 @@ pub struct OpenTip< finders_fee: bool, } -#[frame_support::pallet] +#[frame::pallet] pub mod pallet { use super::*; - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; /// The in-code storage version. const STORAGE_VERSION: StorageVersion = StorageVersion::new(4); @@ -617,12 +604,10 @@ impl, I: 'static> Pallet { tips: Vec<(AccountId, Balance)>, } - use frame_support::{migration::storage_key_iter, Twox64Concat}; - let zero_account = T::AccountId::decode(&mut TrailingZeroInput::new(&[][..])) .expect("infinite input; qed"); - for (hash, old_tip) in storage_key_iter::< + for (hash, old_tip) in storage::migration::storage_key_iter::< T::Hash, OldOpenTip, BlockNumberFor, T::Hash>, Twox64Concat, @@ -654,7 +639,7 @@ impl, I: 'static> Pallet { /// 1. The number of entries in `Tips` should be equal to `Reasons`. /// 2. Reasons exists for each Tip[`OpenTip.reason`]. /// 3. If `OpenTip.finders_fee` is true, then OpenTip.deposit should be greater than zero. - #[cfg(any(feature = "try-runtime", test))] + #[cfg(feature = "try-runtime")] pub fn do_try_state() -> Result<(), TryRuntimeError> { let reasons = Reasons::::iter_keys().collect::>(); let tips = Tips::::iter_keys().collect::>(); diff --git a/substrate/frame/tips/src/migrations/unreserve_deposits.rs b/substrate/frame/tips/src/migrations/unreserve_deposits.rs index afc424309bf4..31cf57c5c6f9 100644 --- a/substrate/frame/tips/src/migrations/unreserve_deposits.rs +++ b/substrate/frame/tips/src/migrations/unreserve_deposits.rs @@ -20,14 +20,13 @@ use alloc::collections::btree_map::BTreeMap; use core::iter::Sum; -use frame_support::{ - pallet_prelude::OptionQuery, - storage_alias, - traits::{Currency, LockableCurrency, OnRuntimeUpgrade, ReservableCurrency}, - weights::RuntimeDbWeight, - Parameter, Twox64Concat, +use frame::{ + runtime::prelude::*, + traits::{Currency, LockableCurrency, ReservableCurrency}, }; -use sp_runtime::{traits::Zero, Saturating}; + +#[cfg(feature = "try-runtime")] +use frame::try_runtime::TryRuntimeError; #[cfg(feature = "try-runtime")] const LOG_TARGET: &str = "runtime::tips::migrations::unreserve_deposits"; @@ -48,23 +47,23 @@ pub trait UnlockConfig: 'static { /// Base deposit to report a tip. /// /// Should match the currency type previously used for the pallet, if applicable. - type TipReportDepositBase: sp_core::Get>; + type TipReportDepositBase: Get>; /// Deposit per byte to report a tip. /// /// Should match the currency type previously used for the pallet, if applicable. - type DataDepositPerByte: sp_core::Get>; + type DataDepositPerByte: Get>; /// The name of the pallet as previously configured in - /// [`construct_runtime!`](frame_support::construct_runtime). - type PalletName: sp_core::Get<&'static str>; + /// [`construct_runtime!`](construct_runtime). + type PalletName: Get<&'static str>; /// The DB weight as configured in the runtime to calculate the correct weight. - type DbWeight: sp_core::Get; + type DbWeight: Get; /// The block number as configured in the runtime. type BlockNumber: Parameter + Zero + Copy + Ord; } /// An open tipping "motion". Retains all details of a tip including information on the finder /// and the members who have voted. -#[storage_alias(dynamic)] +#[frame::storage_alias(dynamic)] type Tips, I: 'static> = StorageMap< >::PalletName, Twox64Concat, @@ -96,9 +95,7 @@ impl, I: 'static> UnreserveDeposits { /// * `BTreeMap`: Map of account IDs to their respective total /// reserved balance by this pallet /// * `frame_support::weights::Weight`: The weight of this operation. - fn get_deposits() -> (BTreeMap>, frame_support::weights::Weight) { - use sp_core::Get; - + fn get_deposits() -> (BTreeMap>, Weight) { let mut tips_len = 0; let account_deposits: BTreeMap> = Tips::::iter() .map(|(_hash, open_tip)| open_tip) @@ -133,9 +130,8 @@ where /// Fails with a `TryRuntimeError` if somehow the amount reserved by this pallet is greater than /// the actual total reserved amount for any accounts. #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { + fn pre_upgrade() -> Result, TryRuntimeError> { use codec::Encode; - use frame_support::ensure; // Get the Tips pallet view of balances it has reserved let (account_deposits, _) = Self::get_deposits(); @@ -167,9 +163,7 @@ where } /// Executes the migration, unreserving funds that are locked in Tip deposits. - fn on_runtime_upgrade() -> frame_support::weights::Weight { - use frame_support::traits::Get; - + fn on_runtime_upgrade() -> Weight { // Get staked and deposited balances as reported by this pallet. let (account_deposits, initial_reads) = Self::get_deposits(); @@ -190,7 +184,7 @@ where #[cfg(feature = "try-runtime")] fn post_upgrade( account_reserved_before_bytes: alloc::vec::Vec, - ) -> Result<(), sp_runtime::TryRuntimeError> { + ) -> Result<(), TryRuntimeError> { use codec::Decode; let account_reserved_before = BTreeMap::>::decode( @@ -230,13 +224,8 @@ where #[cfg(all(feature = "try-runtime", test))] mod test { use super::*; - use crate::{ - migrations::unreserve_deposits::UnreserveDeposits, - tests::{new_test_ext, Balances, RuntimeOrigin, Test, Tips}, - }; - use frame_support::{assert_ok, parameter_types, traits::TypedGet}; - use frame_system::pallet_prelude::BlockNumberFor; - use sp_core::ConstU64; + use crate::tests::{new_test_ext, Balances, RuntimeOrigin, Test, Tips}; + use frame::testing_prelude::*; parameter_types! { const PalletName: &'static str = "Tips"; @@ -247,7 +236,7 @@ mod test { type Currency = Balances; type TipReportDepositBase = ConstU64<1>; type DataDepositPerByte = ConstU64<1>; - type Hash = sp_core::H256; + type Hash = H256; type AccountId = u128; type BlockNumber = BlockNumberFor; type DbWeight = (); @@ -290,15 +279,15 @@ mod test { assert_eq!( ::Currency::reserved_balance(&tipper_0), tipper_0_initial_reserved + - ::TipReportDepositBase::get() + - ::DataDepositPerByte::get() * + <::TipReportDepositBase as TypedGet>::get() + + <::DataDepositPerByte as TypedGet>::get() * tip_0_reason.len() as u64 ); assert_eq!( ::Currency::reserved_balance(&tipper_1), tipper_1_initial_reserved + - ::TipReportDepositBase::get() + - ::DataDepositPerByte::get() * + <::TipReportDepositBase as TypedGet>::get() + + <::DataDepositPerByte as TypedGet>::get() * tip_1_reason.len() as u64 ); diff --git a/substrate/frame/tips/src/migrations/v4.rs b/substrate/frame/tips/src/migrations/v4.rs index 8b0e65c58dbd..58c7cb9c57db 100644 --- a/substrate/frame/tips/src/migrations/v4.rs +++ b/substrate/frame/tips/src/migrations/v4.rs @@ -15,20 +15,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -use core::str; -use sp_io::hashing::twox_128; - use super::super::LOG_TARGET; -use frame_support::{ - storage::StoragePrefixedMap, - traits::{ - Get, GetStorageVersion, PalletInfoAccess, StorageVersion, - STORAGE_VERSION_STORAGE_KEY_POSTFIX, - }, - weights::Weight, -}; +use core::str; use crate as pallet_tips; +use frame::runtime::prelude::*; /// Migrate the entire storage of this pallet to a new prefix. /// @@ -62,7 +53,7 @@ pub fn migrate::storage_prefix(); - frame_support::storage::migration::move_storage_from_pallet( + move_storage_from_pallet( storage_prefix, old_pallet_name.as_bytes(), new_pallet_name.as_bytes(), @@ -70,7 +61,7 @@ pub fn migrate::storage_prefix(); - frame_support::storage::migration::move_storage_from_pallet( + move_storage_from_pallet( storage_prefix, old_pallet_name.as_bytes(), new_pallet_name.as_bytes(), @@ -116,11 +107,10 @@ pub fn pre_migrate< let new_pallet_prefix = twox_128(new_pallet_name.as_bytes()); let storage_version_key = twox_128(STORAGE_VERSION_STORAGE_KEY_POSTFIX); - let mut new_pallet_prefix_iter = frame_support::storage::KeyPrefixIterator::new( - new_pallet_prefix.to_vec(), - new_pallet_prefix.to_vec(), - |key| Ok(key.to_vec()), - ); + let mut new_pallet_prefix_iter = + KeyPrefixIterator::new(new_pallet_prefix.to_vec(), new_pallet_prefix.to_vec(), |key| { + Ok(key.to_vec()) + }); // Ensure nothing except the storage_version_key is stored in the new prefix. assert!(new_pallet_prefix_iter.all(|key| key == storage_version_key)); @@ -155,30 +145,21 @@ pub fn post_migrate< // Assert that no `Tips` and `Reasons` storages remains at the old prefix. let old_pallet_prefix = twox_128(old_pallet_name.as_bytes()); let old_tips_key = [&old_pallet_prefix, &twox_128(storage_prefix_tips)[..]].concat(); - let old_tips_key_iter = frame_support::storage::KeyPrefixIterator::new( - old_tips_key.to_vec(), - old_tips_key.to_vec(), - |_| Ok(()), - ); + let old_tips_key_iter = + KeyPrefixIterator::new(old_tips_key.to_vec(), old_tips_key.to_vec(), |_| Ok(())); assert_eq!(old_tips_key_iter.count(), 0); let old_reasons_key = [&old_pallet_prefix, &twox_128(storage_prefix_reasons)[..]].concat(); - let old_reasons_key_iter = frame_support::storage::KeyPrefixIterator::new( - old_reasons_key.to_vec(), - old_reasons_key.to_vec(), - |_| Ok(()), - ); + let old_reasons_key_iter = + KeyPrefixIterator::new(old_reasons_key.to_vec(), old_reasons_key.to_vec(), |_| Ok(())); assert_eq!(old_reasons_key_iter.count(), 0); // Assert that the `Tips` and `Reasons` storages (if they exist) have been moved to the new // prefix. // NOTE: storage_version_key is already in the new prefix. let new_pallet_prefix = twox_128(new_pallet_name.as_bytes()); - let new_pallet_prefix_iter = frame_support::storage::KeyPrefixIterator::new( - new_pallet_prefix.to_vec(), - new_pallet_prefix.to_vec(), - |_| Ok(()), - ); + let new_pallet_prefix_iter = + KeyPrefixIterator::new(new_pallet_prefix.to_vec(), new_pallet_prefix.to_vec(), |_| Ok(())); assert!(new_pallet_prefix_iter.count() >= 1); assert_eq!(

::on_chain_storage_version(), 4); diff --git a/substrate/frame/tips/src/tests.rs b/substrate/frame/tips/src/tests.rs index 530efb708e41..2faafbe6aa4e 100644 --- a/substrate/frame/tips/src/tests.rs +++ b/substrate/frame/tips/src/tests.rs @@ -18,30 +18,16 @@ //! Treasury pallet tests. #![cfg(test)] - -use sp_core::H256; -use sp_runtime::{ - traits::{BadOrigin, BlakeTwo256, IdentityLookup}, - BuildStorage, Perbill, Permill, -}; -use sp_storage::Storage; - -use frame_support::{ - assert_noop, assert_ok, derive_impl, parameter_types, - storage::StoragePrefixedMap, - traits::{ - tokens::{PayFromAccount, UnityAssetBalanceConversion}, - ConstU32, ConstU64, IntegrityTest, SortedMembers, StorageVersion, - }, - PalletId, -}; - use super::*; use crate::{self as pallet_tips, Event as TipEvent}; +use frame::{ + testing_prelude::*, + traits::tokens::{PayFromAccount, UnityAssetBalanceConversion}, +}; -type Block = frame_system::mocking::MockBlock; +type Block = MockBlock; -frame_support::construct_runtime!( +construct_runtime!( pub enum Test { System: frame_system, @@ -112,7 +98,7 @@ impl pallet_treasury::Config for Test { type WeightInfo = (); type SpendFunds = (); type MaxApprovals = ConstU32<100>; - type SpendOrigin = frame_support::traits::NeverEnsureOrigin; + type SpendOrigin = NeverEnsureOrigin; type AssetKind = (); type Beneficiary = Self::AccountId; type BeneficiaryLookup = IdentityLookup; @@ -135,7 +121,7 @@ impl pallet_treasury::Config for Test { type WeightInfo = (); type SpendFunds = (); type MaxApprovals = ConstU32<100>; - type SpendOrigin = frame_support::traits::NeverEnsureOrigin; + type SpendOrigin = NeverEnsureOrigin; type AssetKind = (); type Beneficiary = Self::AccountId; type BeneficiaryLookup = IdentityLookup; @@ -177,8 +163,8 @@ impl Config for Test { type WeightInfo = (); } -pub fn new_test_ext() -> sp_io::TestExternalities { - let mut ext: sp_io::TestExternalities = RuntimeGenesisConfig { +pub fn new_test_ext() -> TestExternalities { + let mut ext: TestExternalities = RuntimeGenesisConfig { system: frame_system::GenesisConfig::default(), balances: pallet_balances::GenesisConfig { balances: vec![(0, 100), (1, 98), (2, 1)] }, treasury: Default::default(), @@ -195,6 +181,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { pub fn build_and_execute(test: impl FnOnce() -> ()) { new_test_ext().execute_with(|| { test(); + #[cfg(feature = "try-runtime")] Tips::do_try_state().expect("All invariants must hold after a test"); }); } @@ -485,7 +472,7 @@ fn test_last_reward_migration() { s.top = data.into_iter().collect(); - sp_io::TestExternalities::new(s).execute_with(|| { + TestExternalities::new(s).execute_with(|| { let module = pallet_tips::Tips::::pallet_prefix(); let item = pallet_tips::Tips::::storage_prefix(); Tips::migrate_retract_tip_for_tip_new(module, item); @@ -543,15 +530,10 @@ fn test_migration_v4() { let mut s = Storage::default(); s.top = data.into_iter().collect(); - sp_io::TestExternalities::new(s).execute_with(|| { - use frame_support::traits::PalletInfoAccess; - + TestExternalities::new(s).execute_with(|| { let old_pallet = "Treasury"; let new_pallet = ::name(); - frame_support::storage::migration::move_pallet( - new_pallet.as_bytes(), - old_pallet.as_bytes(), - ); + move_pallet(new_pallet.as_bytes(), old_pallet.as_bytes()); StorageVersion::new(0).put::(); crate::migrations::v4::pre_migrate::(old_pallet); @@ -559,15 +541,10 @@ fn test_migration_v4() { crate::migrations::v4::post_migrate::(old_pallet); }); - sp_io::TestExternalities::new(Storage::default()).execute_with(|| { - use frame_support::traits::PalletInfoAccess; - + TestExternalities::new(Storage::default()).execute_with(|| { let old_pallet = "Treasury"; let new_pallet = ::name(); - frame_support::storage::migration::move_pallet( - new_pallet.as_bytes(), - old_pallet.as_bytes(), - ); + move_pallet(new_pallet.as_bytes(), old_pallet.as_bytes()); StorageVersion::new(0).put::(); crate::migrations::v4::pre_migrate::(old_pallet); @@ -589,7 +566,7 @@ fn genesis_funding_works() { pallet_treasury::GenesisConfig::::default() .assimilate_storage(&mut t) .unwrap(); - let mut t: sp_io::TestExternalities = t.into(); + let mut t: TestExternalities = t.into(); t.execute_with(|| { assert_eq!(Balances::free_balance(Treasury::account_id()), initial_funding); @@ -631,10 +608,9 @@ fn report_awesome_and_tip_works_second_instance() { } #[test] +#[cfg(feature = "try-runtime")] fn equal_entries_invariant() { new_test_ext().execute_with(|| { - use frame_support::pallet_prelude::DispatchError::Other; - Balances::make_free_balance_be(&Treasury::account_id(), 101); assert_ok!(Tips::report_awesome(RuntimeOrigin::signed(0), b"awesome.dot".to_vec(), 3)); @@ -658,16 +634,15 @@ fn equal_entries_invariant() { // Invariant violated assert_eq!( Tips::do_try_state(), - Err(Other("Equal length of entries in `Tips` and `Reasons` Storage")) + Err(TryRuntimeError::Other("Equal length of entries in `Tips` and `Reasons` Storage")) ); }) } #[test] +#[cfg(feature = "try-runtime")] fn finders_fee_invariant() { new_test_ext().execute_with(|| { - use frame_support::pallet_prelude::DispatchError::Other; - // Breaks invariant by having a zero deposit. TipReportDepositBase::set(0); @@ -678,16 +653,15 @@ fn finders_fee_invariant() { // Invariant violated assert_eq!( Tips::do_try_state(), - Err(Other("Tips with `finders_fee` should have non-zero `deposit`.")) + Err(TryRuntimeError::Other("Tips with `finders_fee` should have non-zero `deposit`.")) ); }) } #[test] +#[cfg(feature = "try-runtime")] fn reasons_invariant() { new_test_ext().execute_with(|| { - use frame_support::pallet_prelude::DispatchError::Other; - Balances::make_free_balance_be(&Treasury::account_id(), 101); assert_ok!(Tips::report_awesome(RuntimeOrigin::signed(0), b"awesome.dot".to_vec(), 0)); @@ -702,7 +676,7 @@ fn reasons_invariant() { pallet_tips::Tips::::insert(hash[0], open_tip); // Invariant violated - assert_eq!(Tips::do_try_state(), Err(Other("no reason for this tip"))); + assert_eq!(Tips::do_try_state(), Err(TryRuntimeError::Other("no reason for this tip"))); }) } diff --git a/substrate/frame/tips/src/weights.rs b/substrate/frame/tips/src/weights.rs index e9805e9cc9bf..4c8359f0e66f 100644 --- a/substrate/frame/tips/src/weights.rs +++ b/substrate/frame/tips/src/weights.rs @@ -46,7 +46,7 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use frame::weights_prelude::*; use core::marker::PhantomData; /// Weight functions needed for `pallet_tips`.