From 20e305ba728982a7e460eae504088a7d50f71f6e Mon Sep 17 00:00:00 2001 From: Jan-Jan <111935+Jan-Jan@users.noreply.github.com> Date: Thu, 19 Sep 2024 13:57:13 +0200 Subject: [PATCH 01/11] changed mock to use new runtime macro --- .../solochain/pallets/template/src/mock.rs | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/templates/solochain/pallets/template/src/mock.rs b/templates/solochain/pallets/template/src/mock.rs index 0c2a247e802b..6aea83cc7fda 100644 --- a/templates/solochain/pallets/template/src/mock.rs +++ b/templates/solochain/pallets/template/src/mock.rs @@ -5,13 +5,41 @@ use sp_runtime::BuildStorage; type Block = frame_system::mocking::MockBlock; // Configure a mock runtime to test the pallet. -frame_support::construct_runtime!( - pub enum Test - { - System: frame_system, - TemplateModule: pallet_template, - } -); +// frame_support::construct_runtime!( +// pub enum Test +// { +// System: frame_system, +// TemplateModule: pallet_template, +// } +// ); + +#[crate::runtime] +mod runtime { + // The main runtime + #[runtime::runtime] + // Runtime Types to be generated + #[runtime::derive( + RuntimeCall, + RuntimeEvent, + RuntimeError, + RuntimeOrigin, + RuntimeFreezeReason, + RuntimeHoldReason, + RuntimeSlashReason, + RuntimeLockId, + RuntimeTask + )] + // pub struct Runtime; + pub struct Test; + + // Use the concrete pallet type + #[runtime::pallet_index(0)] + pub type System = frame_system::Pallet; + + // // Use path to the pallet + #[runtime::pallet_index(1)] + pub type TemplateModule = pallet_template::Pallet; +} #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { From d95663b33c6f2146b03f30b4a5617c428fdaf2db Mon Sep 17 00:00:00 2001 From: Jan-Jan <111935+Jan-Jan@users.noreply.github.com> Date: Thu, 19 Sep 2024 14:57:35 +0200 Subject: [PATCH 02/11] deleted old macro, fixed trivial bug that references Runtime instead of Test --- templates/solochain/pallets/template/src/mock.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/templates/solochain/pallets/template/src/mock.rs b/templates/solochain/pallets/template/src/mock.rs index 6aea83cc7fda..6754e1b17e6b 100644 --- a/templates/solochain/pallets/template/src/mock.rs +++ b/templates/solochain/pallets/template/src/mock.rs @@ -4,15 +4,6 @@ use sp_runtime::BuildStorage; type Block = frame_system::mocking::MockBlock; -// Configure a mock runtime to test the pallet. -// frame_support::construct_runtime!( -// pub enum Test -// { -// System: frame_system, -// TemplateModule: pallet_template, -// } -// ); - #[crate::runtime] mod runtime { // The main runtime @@ -34,11 +25,11 @@ mod runtime { // Use the concrete pallet type #[runtime::pallet_index(0)] - pub type System = frame_system::Pallet; + pub type System = frame_system::Pallet; // // Use path to the pallet #[runtime::pallet_index(1)] - pub type TemplateModule = pallet_template::Pallet; + pub type Template = pallet_template::Pallet; } #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] From 380edd465ca7cf3c7be47e2c9664d556baac1246 Mon Sep 17 00:00:00 2001 From: Jan-Jan <111935+Jan-Jan@users.noreply.github.com> Date: Thu, 19 Sep 2024 14:58:08 +0200 Subject: [PATCH 03/11] 'Template' instead of 'TemplateModule' --- prdoc/1.9.0/pr_1378.prdoc | 2 +- templates/parachain/pallets/template/src/mock.rs | 2 +- .../parachain/pallets/template/src/tests.rs | 4 ++-- .../parachain/pallets/template/src/weights.rs | 16 ++++++++-------- .../solochain/pallets/template/src/tests.rs | 4 ++-- .../solochain/pallets/template/src/weights.rs | 16 ++++++++-------- templates/solochain/runtime/src/benchmarks.rs | 2 +- templates/solochain/runtime/src/lib.rs | 2 +- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/prdoc/1.9.0/pr_1378.prdoc b/prdoc/1.9.0/pr_1378.prdoc index 6533dcb66303..03427cdba99d 100644 --- a/prdoc/1.9.0/pr_1378.prdoc +++ b/prdoc/1.9.0/pr_1378.prdoc @@ -10,7 +10,7 @@ doc: 3. `#[runtime::pallet_index]` must be attached to a pallet to define its index 4. `#[runtime::disable_call]` can be optionally attached to a pallet to disable its calls 5. `#[runtime::disable_unsigned]` can be optionally attached to a pallet to disable unsigned calls - 6. A pallet instance can be defined as `TemplateModule: pallet_template` + 6. A pallet instance can be defined as `Template: pallet_template` An optional attribute can be defined as `#[frame_support::runtime(legacy_ordering)]` to ensure that the order of hooks is same as the order of pallets (and not based on the pallet_index). This is to support legacy runtimes and should be avoided for new ones. diff --git a/templates/parachain/pallets/template/src/mock.rs b/templates/parachain/pallets/template/src/mock.rs index 46e3117596f5..b8c730b6eb5d 100644 --- a/templates/parachain/pallets/template/src/mock.rs +++ b/templates/parachain/pallets/template/src/mock.rs @@ -22,7 +22,7 @@ mod test_runtime { #[runtime::pallet_index(0)] pub type System = frame_system; #[runtime::pallet_index(1)] - pub type TemplateModule = crate; + pub type Template = crate; } #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] diff --git a/templates/parachain/pallets/template/src/tests.rs b/templates/parachain/pallets/template/src/tests.rs index a4a41af63c2e..92996987f85c 100644 --- a/templates/parachain/pallets/template/src/tests.rs +++ b/templates/parachain/pallets/template/src/tests.rs @@ -5,7 +5,7 @@ use frame_support::{assert_noop, assert_ok}; fn it_works_for_default_value() { new_test_ext().execute_with(|| { // Dispatch a signed extrinsic. - assert_ok!(TemplateModule::do_something(RuntimeOrigin::signed(1), 42)); + assert_ok!(Template::do_something(RuntimeOrigin::signed(1), 42)); // Read pallet storage and assert an expected result. assert_eq!(Something::::get().map(|v| v.block_number), Some(42)); }); @@ -16,7 +16,7 @@ fn correct_error_for_none_value() { new_test_ext().execute_with(|| { // Ensure the expected error is thrown when no value is present. assert_noop!( - TemplateModule::cause_error(RuntimeOrigin::signed(1)), + Template::cause_error(RuntimeOrigin::signed(1)), Error::::NoneValue ); }); diff --git a/templates/parachain/pallets/template/src/weights.rs b/templates/parachain/pallets/template/src/weights.rs index 5bfe28e8b71e..4b4522429c6c 100644 --- a/templates/parachain/pallets/template/src/weights.rs +++ b/templates/parachain/pallets/template/src/weights.rs @@ -41,8 +41,8 @@ pub trait WeightInfo { /// Weights for pallet_template using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - /// Storage: TemplateModule Something (r:0 w:1) - /// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Template Something (r:0 w:1) + /// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn do_something() -> Weight { // Proof Size summary in bytes: // Measured: `0` @@ -51,8 +51,8 @@ impl WeightInfo for SubstrateWeight { Weight::from_parts(9_000_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } - /// Storage: TemplateModule Something (r:1 w:1) - /// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Template Something (r:1 w:1) + /// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn cause_error() -> Weight { // Proof Size summary in bytes: // Measured: `32` @@ -66,8 +66,8 @@ impl WeightInfo for SubstrateWeight { // For backwards compatibility and tests impl WeightInfo for () { - /// Storage: TemplateModule Something (r:0 w:1) - /// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Template Something (r:0 w:1) + /// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn do_something() -> Weight { // Proof Size summary in bytes: // Measured: `0` @@ -76,8 +76,8 @@ impl WeightInfo for () { Weight::from_parts(9_000_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - /// Storage: TemplateModule Something (r:1 w:1) - /// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Template Something (r:1 w:1) + /// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn cause_error() -> Weight { // Proof Size summary in bytes: // Measured: `32` diff --git a/templates/solochain/pallets/template/src/tests.rs b/templates/solochain/pallets/template/src/tests.rs index 83e4bea7377b..0c4ccc24edf8 100644 --- a/templates/solochain/pallets/template/src/tests.rs +++ b/templates/solochain/pallets/template/src/tests.rs @@ -7,7 +7,7 @@ fn it_works_for_default_value() { // Go past genesis block so events get deposited System::set_block_number(1); // Dispatch a signed extrinsic. - assert_ok!(TemplateModule::do_something(RuntimeOrigin::signed(1), 42)); + assert_ok!(Template::do_something(RuntimeOrigin::signed(1), 42)); // Read pallet storage and assert an expected result. assert_eq!(Something::::get(), Some(42)); // Assert that the correct event was deposited @@ -20,7 +20,7 @@ fn correct_error_for_none_value() { new_test_ext().execute_with(|| { // Ensure the expected error is thrown when no value is present. assert_noop!( - TemplateModule::cause_error(RuntimeOrigin::signed(1)), + Template::cause_error(RuntimeOrigin::signed(1)), Error::::NoneValue ); }); diff --git a/templates/solochain/pallets/template/src/weights.rs b/templates/solochain/pallets/template/src/weights.rs index 7c42936e09f2..c2879fa503c6 100644 --- a/templates/solochain/pallets/template/src/weights.rs +++ b/templates/solochain/pallets/template/src/weights.rs @@ -41,8 +41,8 @@ pub trait WeightInfo { /// Weights for pallet_template using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - /// Storage: TemplateModule Something (r:0 w:1) - /// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Template Something (r:0 w:1) + /// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn do_something() -> Weight { // Proof Size summary in bytes: // Measured: `0` @@ -51,8 +51,8 @@ impl WeightInfo for SubstrateWeight { Weight::from_parts(9_000_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } - /// Storage: TemplateModule Something (r:1 w:1) - /// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Template Something (r:1 w:1) + /// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn cause_error() -> Weight { // Proof Size summary in bytes: // Measured: `32` @@ -66,8 +66,8 @@ impl WeightInfo for SubstrateWeight { // For backwards compatibility and tests impl WeightInfo for () { - /// Storage: TemplateModule Something (r:0 w:1) - /// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Template Something (r:0 w:1) + /// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn do_something() -> Weight { // Proof Size summary in bytes: // Measured: `0` @@ -76,8 +76,8 @@ impl WeightInfo for () { Weight::from_parts(9_000_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - /// Storage: TemplateModule Something (r:1 w:1) - /// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Template Something (r:1 w:1) + /// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn cause_error() -> Weight { // Proof Size summary in bytes: // Measured: `32` diff --git a/templates/solochain/runtime/src/benchmarks.rs b/templates/solochain/runtime/src/benchmarks.rs index a42daf56b58e..f39c2bd29593 100644 --- a/templates/solochain/runtime/src/benchmarks.rs +++ b/templates/solochain/runtime/src/benchmarks.rs @@ -29,5 +29,5 @@ frame_benchmarking::define_benchmarks!( [pallet_balances, Balances] [pallet_timestamp, Timestamp] [pallet_sudo, Sudo] - [pallet_template, TemplateModule] + [pallet_template, Template] ); diff --git a/templates/solochain/runtime/src/lib.rs b/templates/solochain/runtime/src/lib.rs index ce38c65479e5..279518c8f47c 100644 --- a/templates/solochain/runtime/src/lib.rs +++ b/templates/solochain/runtime/src/lib.rs @@ -220,5 +220,5 @@ mod runtime { // Include the custom logic from the pallet-template in the runtime. #[runtime::pallet_index(7)] - pub type TemplateModule = pallet_template; + pub type Template = pallet_template; } From 2a942f471053a9f5158cc13b3ef30f93effe6719 Mon Sep 17 00:00:00 2001 From: Jan-Jan <111935+Jan-Jan@users.noreply.github.com> Date: Thu, 19 Sep 2024 15:07:43 +0200 Subject: [PATCH 04/11] update docs --- templates/solochain/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/solochain/README.md b/templates/solochain/README.md index c4ce5c7f3fbb..7f36a997985d 100644 --- a/templates/solochain/README.md +++ b/templates/solochain/README.md @@ -185,7 +185,7 @@ template and note the following: configuration is defined by a code block that begins with `impl $PALLET_NAME::Config for Runtime`. - The pallets are composed into a single runtime by way of the - [`construct_runtime!`](https://paritytech.github.io/substrate/master/frame_support/macro.construct_runtime.html) + [#[runtime]](https://paritytech.github.io/polkadot-sdk/master/frame_support/attr.runtime.html) macro, which is part of the [core FRAME pallet library](https://docs.substrate.io/reference/frame-pallets/#system-pallets). From a46d14bd85446a750f8d0d5d6d36a5519e95f022 Mon Sep 17 00:00:00 2001 From: Jan-Jan <111935+Jan-Jan@users.noreply.github.com> Date: Thu, 19 Sep 2024 15:08:30 +0200 Subject: [PATCH 05/11] minimal template: refer to 'crate::runtime' instead of 'frame_construct_runtime' --- templates/minimal/runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index cce13c48af71..2a7bd3a368ae 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -77,7 +77,7 @@ type SignedExtra = ( ); // Composes the runtime by adding all the used pallets and deriving necessary types. -#[frame_construct_runtime] +#[crate::runtime] mod runtime { /// The main runtime type. #[runtime::runtime] From 98b756be2c4b178b29b50acb056d623c3cedbf2e Mon Sep 17 00:00:00 2001 From: Jan-Jan <111935+Jan-Jan@users.noreply.github.com> Date: Thu, 19 Sep 2024 16:19:39 +0200 Subject: [PATCH 06/11] '#[frame_construct_runtime]' rather than '#[crate::runtime]' --- templates/minimal/runtime/src/lib.rs | 2 +- templates/solochain/pallets/template/src/mock.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index 2a7bd3a368ae..cce13c48af71 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -77,7 +77,7 @@ type SignedExtra = ( ); // Composes the runtime by adding all the used pallets and deriving necessary types. -#[crate::runtime] +#[frame_construct_runtime] mod runtime { /// The main runtime type. #[runtime::runtime] diff --git a/templates/solochain/pallets/template/src/mock.rs b/templates/solochain/pallets/template/src/mock.rs index 6754e1b17e6b..d2dd0fe6b915 100644 --- a/templates/solochain/pallets/template/src/mock.rs +++ b/templates/solochain/pallets/template/src/mock.rs @@ -4,7 +4,7 @@ use sp_runtime::BuildStorage; type Block = frame_system::mocking::MockBlock; -#[crate::runtime] +#[frame_construct_runtime] mod runtime { // The main runtime #[runtime::runtime] From b17061d07e41e4cbec46baece872a1e114d05b41 Mon Sep 17 00:00:00 2001 From: Jan-Jan <111935+Jan-Jan@users.noreply.github.com> Date: Thu, 19 Sep 2024 16:37:02 +0200 Subject: [PATCH 07/11] using '#[frame_support::runtime]' --- templates/solochain/pallets/template/src/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/solochain/pallets/template/src/mock.rs b/templates/solochain/pallets/template/src/mock.rs index d2dd0fe6b915..05b4c55434b3 100644 --- a/templates/solochain/pallets/template/src/mock.rs +++ b/templates/solochain/pallets/template/src/mock.rs @@ -4,7 +4,7 @@ use sp_runtime::BuildStorage; type Block = frame_system::mocking::MockBlock; -#[frame_construct_runtime] +#[frame_support::runtime] mod runtime { // The main runtime #[runtime::runtime] From 63f7a6c59e394f0d93c38cef9baa64e37f2555c6 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Sat, 21 Sep 2024 09:18:45 +0200 Subject: [PATCH 08/11] Update templates/solochain/pallets/template/src/mock.rs --- templates/solochain/pallets/template/src/mock.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/solochain/pallets/template/src/mock.rs b/templates/solochain/pallets/template/src/mock.rs index 05b4c55434b3..b8cc589c4c8b 100644 --- a/templates/solochain/pallets/template/src/mock.rs +++ b/templates/solochain/pallets/template/src/mock.rs @@ -20,7 +20,6 @@ mod runtime { RuntimeLockId, RuntimeTask )] - // pub struct Runtime; pub struct Test; // Use the concrete pallet type From f5e250a159a683e8a632de403f7a11b062366cc3 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Sat, 21 Sep 2024 09:18:51 +0200 Subject: [PATCH 09/11] Update templates/solochain/pallets/template/src/mock.rs --- templates/solochain/pallets/template/src/mock.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/solochain/pallets/template/src/mock.rs b/templates/solochain/pallets/template/src/mock.rs index b8cc589c4c8b..9392de8d24bf 100644 --- a/templates/solochain/pallets/template/src/mock.rs +++ b/templates/solochain/pallets/template/src/mock.rs @@ -26,7 +26,6 @@ mod runtime { #[runtime::pallet_index(0)] pub type System = frame_system::Pallet; - // // Use path to the pallet #[runtime::pallet_index(1)] pub type Template = pallet_template::Pallet; } From 1bae5460a4e86e7796b17ac65d913f61e5847e59 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Sat, 21 Sep 2024 09:18:58 +0200 Subject: [PATCH 10/11] Update templates/solochain/pallets/template/src/mock.rs --- templates/solochain/pallets/template/src/mock.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/solochain/pallets/template/src/mock.rs b/templates/solochain/pallets/template/src/mock.rs index 9392de8d24bf..1b86cd9b7709 100644 --- a/templates/solochain/pallets/template/src/mock.rs +++ b/templates/solochain/pallets/template/src/mock.rs @@ -22,7 +22,6 @@ mod runtime { )] pub struct Test; - // Use the concrete pallet type #[runtime::pallet_index(0)] pub type System = frame_system::Pallet; From 1fa943421f03cb9f5f37bda170a2f5ed326db43a Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Mon, 23 Sep 2024 22:18:25 +0000 Subject: [PATCH 11/11] ".git/.scripts/commands/fmt/fmt.sh" --- templates/parachain/pallets/template/src/tests.rs | 5 +---- templates/solochain/pallets/template/src/tests.rs | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/templates/parachain/pallets/template/src/tests.rs b/templates/parachain/pallets/template/src/tests.rs index 92996987f85c..2f641ce08fbb 100644 --- a/templates/parachain/pallets/template/src/tests.rs +++ b/templates/parachain/pallets/template/src/tests.rs @@ -15,9 +15,6 @@ fn it_works_for_default_value() { fn correct_error_for_none_value() { new_test_ext().execute_with(|| { // Ensure the expected error is thrown when no value is present. - assert_noop!( - Template::cause_error(RuntimeOrigin::signed(1)), - Error::::NoneValue - ); + assert_noop!(Template::cause_error(RuntimeOrigin::signed(1)), Error::::NoneValue); }); } diff --git a/templates/solochain/pallets/template/src/tests.rs b/templates/solochain/pallets/template/src/tests.rs index 0c4ccc24edf8..d05433c3add6 100644 --- a/templates/solochain/pallets/template/src/tests.rs +++ b/templates/solochain/pallets/template/src/tests.rs @@ -19,9 +19,6 @@ fn it_works_for_default_value() { fn correct_error_for_none_value() { new_test_ext().execute_with(|| { // Ensure the expected error is thrown when no value is present. - assert_noop!( - Template::cause_error(RuntimeOrigin::signed(1)), - Error::::NoneValue - ); + assert_noop!(Template::cause_error(RuntimeOrigin::signed(1)), Error::::NoneValue); }); }