From ca063b7c5a0e554bf4d38022a952a471f6c68c5d Mon Sep 17 00:00:00 2001 From: Krayt78 Date: Fri, 13 Dec 2024 22:36:43 +0100 Subject: [PATCH 1/4] first draft --- Cargo.lock | 7 +----- substrate/frame/recovery/Cargo.toml | 24 ++++---------------- substrate/frame/recovery/src/benchmarking.rs | 5 +--- substrate/frame/recovery/src/lib.rs | 18 ++++----------- substrate/frame/recovery/src/mock.rs | 6 +---- substrate/frame/recovery/src/tests.rs | 4 ++-- substrate/frame/recovery/src/weights.rs | 3 ++- 7 files changed, 16 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 02d7da8f7657..5d6a38995e4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14497,15 +14497,10 @@ dependencies = [ name = "pallet-recovery" 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-core 28.0.0", - "sp-io 30.0.0", - "sp-runtime 31.0.1", ] [[package]] diff --git a/substrate/frame/recovery/Cargo.toml b/substrate/frame/recovery/Cargo.toml index 44335e8f575c..9a88455618b8 100644 --- a/substrate/frame/recovery/Cargo.toml +++ b/substrate/frame/recovery/Cargo.toml @@ -18,40 +18,24 @@ 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-io = { workspace = true } -sp-runtime = { workspace = true } +frame = { workspace = true, features = ["experimental", "runtime"] } [dev-dependencies] pallet-balances = { workspace = true, default-features = true } -sp-core = { workspace = true, default-features = true } [features] default = ["std"] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", - 'frame-benchmarking', + "frame/runtime-benchmarks", ] std = [ "codec/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", "pallet-balances/std", "scale-info/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", + "frame/std", ] 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/recovery/src/benchmarking.rs b/substrate/frame/recovery/src/benchmarking.rs index ee97cb77d301..0dea547db2ad 100644 --- a/substrate/frame/recovery/src/benchmarking.rs +++ b/substrate/frame/recovery/src/benchmarking.rs @@ -21,10 +21,7 @@ use super::*; use crate::Pallet; use alloc::{boxed::Box, vec, vec::Vec}; -use frame_benchmarking::v2::*; -use frame_support::traits::{Currency, Get}; -use frame_system::RawOrigin; -use sp_runtime::traits::Bounded; +use frame::{traits::Currency, benchmarking::prelude::*}; const SEED: u32 = 0; const DEFAULT_DELAY: u32 = 0; diff --git a/substrate/frame/recovery/src/lib.rs b/substrate/frame/recovery/src/lib.rs index f8622880538e..eedd4d03a0f2 100644 --- a/substrate/frame/recovery/src/lib.rs +++ b/substrate/frame/recovery/src/lib.rs @@ -155,16 +155,8 @@ extern crate alloc; use alloc::{boxed::Box, vec::Vec}; use codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; -use sp_runtime::{ - traits::{CheckedAdd, CheckedMul, Dispatchable, SaturatedConversion, StaticLookup}, - RuntimeDebug, -}; -use frame_support::{ - dispatch::{GetDispatchInfo, PostDispatchInfo}, - traits::{BalanceStatus, Currency, ReservableCurrency}, - BoundedVec, -}; +use frame::{prelude::*, arithmetic::ArithmeticError,traits::{ReservableCurrency,Currency,BalanceStatus}}; pub use pallet::*; pub use weights::WeightInfo; @@ -211,12 +203,12 @@ pub struct RecoveryConfig { threshold: u16, } -#[frame_support::pallet] +#[frame::pallet] pub mod pallet { use super::*; - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; - use sp_runtime::ArithmeticError; + // use frame_support::pallet_prelude::*; + // use frame_system::pallet_prelude::*; + // use sp_runtime::ArithmeticError; #[pallet::pallet] pub struct Pallet(_); diff --git a/substrate/frame/recovery/src/mock.rs b/substrate/frame/recovery/src/mock.rs index 8e30cbe997e1..2d8b405d9875 100644 --- a/substrate/frame/recovery/src/mock.rs +++ b/substrate/frame/recovery/src/mock.rs @@ -20,11 +20,7 @@ use super::*; use crate as recovery; -use frame_support::{ - derive_impl, parameter_types, - traits::{OnFinalize, OnInitialize}, -}; -use sp_runtime::BuildStorage; +use frame::testing_prelude::*; type Block = frame_system::mocking::MockBlock; diff --git a/substrate/frame/recovery/src/tests.rs b/substrate/frame/recovery/src/tests.rs index 93df07015852..1a19301841dd 100644 --- a/substrate/frame/recovery/src/tests.rs +++ b/substrate/frame/recovery/src/tests.rs @@ -18,12 +18,12 @@ //! Tests for the module. use super::*; -use frame_support::{assert_noop, assert_ok, traits::Currency}; + +use frame::testing_prelude::*; use mock::{ new_test_ext, run_to_block, Balances, BalancesCall, MaxFriends, Recovery, RecoveryCall, RuntimeCall, RuntimeOrigin, Test, }; -use sp_runtime::{bounded_vec, traits::BadOrigin}; #[test] fn basic_setup_works() { diff --git a/substrate/frame/recovery/src/weights.rs b/substrate/frame/recovery/src/weights.rs index 38b085f0a293..f4c04ef574e7 100644 --- a/substrate/frame/recovery/src/weights.rs +++ b/substrate/frame/recovery/src/weights.rs @@ -46,8 +46,9 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use frame::prelude::*; use core::marker::PhantomData; +use frame::runtime::prelude::weights::constants::RocksDbWeight; /// Weight functions needed for `pallet_recovery`. pub trait WeightInfo { From 7d449e83520a31a0f8988cc18c83afaf8022a86b Mon Sep 17 00:00:00 2001 From: Krayt78 Date: Sat, 14 Dec 2024 19:45:40 +0100 Subject: [PATCH 2/4] second pass and fmt --- substrate/frame/recovery/src/benchmarking.rs | 2 +- substrate/frame/recovery/src/lib.rs | 6 +++++- substrate/frame/recovery/src/mock.rs | 5 ++--- substrate/frame/recovery/src/tests.rs | 4 ++-- substrate/frame/src/lib.rs | 2 ++ 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/substrate/frame/recovery/src/benchmarking.rs b/substrate/frame/recovery/src/benchmarking.rs index 0dea547db2ad..f8889bbda4f2 100644 --- a/substrate/frame/recovery/src/benchmarking.rs +++ b/substrate/frame/recovery/src/benchmarking.rs @@ -21,7 +21,7 @@ use super::*; use crate::Pallet; use alloc::{boxed::Box, vec, vec::Vec}; -use frame::{traits::Currency, benchmarking::prelude::*}; +use frame::{benchmarking::prelude::*, traits::Currency}; const SEED: u32 = 0; const DEFAULT_DELAY: u32 = 0; diff --git a/substrate/frame/recovery/src/lib.rs b/substrate/frame/recovery/src/lib.rs index eedd4d03a0f2..9d41c688c3bf 100644 --- a/substrate/frame/recovery/src/lib.rs +++ b/substrate/frame/recovery/src/lib.rs @@ -156,7 +156,11 @@ use alloc::{boxed::Box, vec::Vec}; use codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; -use frame::{prelude::*, arithmetic::ArithmeticError,traits::{ReservableCurrency,Currency,BalanceStatus}}; +use frame::{ + arithmetic::ArithmeticError, + prelude::*, + traits::{BalanceStatus, Currency, ReservableCurrency}, +}; pub use pallet::*; pub use weights::WeightInfo; diff --git a/substrate/frame/recovery/src/mock.rs b/substrate/frame/recovery/src/mock.rs index 2d8b405d9875..db274680269d 100644 --- a/substrate/frame/recovery/src/mock.rs +++ b/substrate/frame/recovery/src/mock.rs @@ -18,13 +18,12 @@ //! Test utilities use super::*; - use crate as recovery; -use frame::testing_prelude::*; +use frame::{deps::sp_io, testing_prelude::*}; type Block = frame_system::mocking::MockBlock; -frame_support::construct_runtime!( +construct_runtime!( pub enum Test { System: frame_system, diff --git a/substrate/frame/recovery/src/tests.rs b/substrate/frame/recovery/src/tests.rs index 1a19301841dd..7f4e676fecc8 100644 --- a/substrate/frame/recovery/src/tests.rs +++ b/substrate/frame/recovery/src/tests.rs @@ -19,11 +19,11 @@ use super::*; -use frame::testing_prelude::*; -use mock::{ +use crate::mock::{ new_test_ext, run_to_block, Balances, BalancesCall, MaxFriends, Recovery, RecoveryCall, RuntimeCall, RuntimeOrigin, Test, }; +use frame::{testing_prelude::*, traits::BadOrigin}; #[test] fn basic_setup_works() { diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 0ca36ca8545a..0e8de6e1a412 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -317,6 +317,8 @@ pub mod testing_prelude { pub use sp_io::TestExternalities; pub use sp_io::TestExternalities as TestState; + + pub use sp_runtime::bounded_vec; } /// All of the types and tools needed to build FRAME-based runtimes. From 4b8c4dccb07a0dbf5d3d5788947e843840d7269e Mon Sep 17 00:00:00 2001 From: Krayt78 Date: Sat, 14 Dec 2024 19:51:06 +0100 Subject: [PATCH 3/4] added weight prelude --- substrate/frame/recovery/src/weights.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/substrate/frame/recovery/src/weights.rs b/substrate/frame/recovery/src/weights.rs index f4c04ef574e7..ed2bf927d425 100644 --- a/substrate/frame/recovery/src/weights.rs +++ b/substrate/frame/recovery/src/weights.rs @@ -46,9 +46,8 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame::prelude::*; +use frame::weights_prelude::*; use core::marker::PhantomData; -use frame::runtime::prelude::weights::constants::RocksDbWeight; /// Weight functions needed for `pallet_recovery`. pub trait WeightInfo { From c67054ad1d522bd9248ec6b70986a53aea12421a Mon Sep 17 00:00:00 2001 From: Krayt78 Date: Tue, 17 Dec 2024 16:24:23 +0100 Subject: [PATCH 4/4] fix toml --- substrate/frame/recovery/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/frame/recovery/Cargo.toml b/substrate/frame/recovery/Cargo.toml index 9a88455618b8..e16c2d535cb7 100644 --- a/substrate/frame/recovery/Cargo.toml +++ b/substrate/frame/recovery/Cargo.toml @@ -26,14 +26,14 @@ pallet-balances = { workspace = true, default-features = true } [features] default = ["std"] runtime-benchmarks = [ - "pallet-balances/runtime-benchmarks", "frame/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", ] std = [ "codec/std", + "frame/std", "pallet-balances/std", "scale-info/std", - "frame/std", ] try-runtime = [ "frame/try-runtime",