From d9abf24fb474959268eb6a3c337fd51ce7ac0dd1 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Tue, 4 Feb 2025 14:15:33 +0200 Subject: [PATCH 1/3] BACKPORT-CONFLICT --- substrate/frame/parameters/src/tests/mock.rs | 2 +- .../src/construct_runtime/expand/origin.rs | 1 + .../support/test/tests/enum_deprecation.rs | 171 ++++++++++++++++++ 3 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 substrate/frame/support/test/tests/enum_deprecation.rs diff --git a/substrate/frame/parameters/src/tests/mock.rs b/substrate/frame/parameters/src/tests/mock.rs index 53a3b3e394c4b..8d6f7d25ceac5 100644 --- a/substrate/frame/parameters/src/tests/mock.rs +++ b/substrate/frame/parameters/src/tests/mock.rs @@ -75,7 +75,7 @@ pub mod dynamic_params { } #[dynamic_pallet_params] - #[codec(index = 3)] + #[codec(index = 4)] pub mod somE_weird_SPElLInG_s { #[codec(index = 0)] pub static V: u64 = 0; diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/origin.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/origin.rs index 4a14853c04eec..5a6a89afef3f6 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/origin.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/origin.rs @@ -206,6 +206,7 @@ pub fn expand_outer_origin( system(#system_path::Origin<#runtime>), #caller_variants #[allow(dead_code)] + #[codec(skip)] Void(#scrate::__private::Void) } diff --git a/substrate/frame/support/test/tests/enum_deprecation.rs b/substrate/frame/support/test/tests/enum_deprecation.rs new file mode 100644 index 0000000000000..72b14dad96291 --- /dev/null +++ b/substrate/frame/support/test/tests/enum_deprecation.rs @@ -0,0 +1,171 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#![allow(useless_deprecated, deprecated, clippy::deprecated_semver)] + +use std::collections::BTreeMap; + +use frame_support::{ + derive_impl, + dispatch::Parameter, + parameter_types, + traits::{ConstU32, StorageVersion}, + OrdNoBound, PartialOrdNoBound, +}; +use scale_info::TypeInfo; + +parameter_types! { + /// Used to control if the storage version should be updated. + storage UpdateStorageVersion: bool = false; +} + +pub struct SomeType1; +impl From for u64 { + fn from(_t: SomeType1) -> Self { + 0u64 + } +} + +pub trait SomeAssociation1 { + type _1: Parameter + codec::MaxEncodedLen + TypeInfo; +} +impl SomeAssociation1 for u64 { + type _1 = u64; +} + +#[frame_support::pallet] +pub mod pallet { + use super::*; + use frame_support::pallet_prelude::*; + + pub(crate) const STORAGE_VERSION: StorageVersion = StorageVersion::new(10); + + #[pallet::config] + pub trait Config: frame_system::Config + where + ::AccountId: From + SomeAssociation1, + { + type Balance: Parameter + Default + TypeInfo; + + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + } + + #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] + pub struct Pallet(_); + + #[pallet::error] + #[derive(PartialEq, Eq)] + pub enum Error { + /// error doc comment put in metadata + InsufficientProposersBalance, + NonExistentStorageValue, + Code(u8), + #[codec(skip)] + Skipped(u128), + CompactU8(#[codec(compact)] u8), + } + + #[pallet::event] + pub enum Event + where + T::AccountId: SomeAssociation1 + From, + { + #[deprecated = "second"] + #[codec(index = 1)] + A, + #[deprecated = "first"] + #[codec(index = 0)] + B, + } + + #[pallet::origin] + #[derive( + EqNoBound, + RuntimeDebugNoBound, + CloneNoBound, + PartialEqNoBound, + PartialOrdNoBound, + OrdNoBound, + Encode, + Decode, + TypeInfo, + MaxEncodedLen, + )] + pub struct Origin(PhantomData); +} + +frame_support::parameter_types!( + pub const MyGetParam3: u32 = 12; +); + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] +impl frame_system::Config for Runtime { + type BaseCallFilter = frame_support::traits::Everything; + type RuntimeOrigin = RuntimeOrigin; + type Nonce = u64; + type RuntimeCall = RuntimeCall; + type Hash = sp_runtime::testing::H256; + type Hashing = sp_runtime::traits::BlakeTwo256; + type AccountId = u64; + type Lookup = sp_runtime::traits::IdentityLookup; + type Block = Block; + type RuntimeEvent = RuntimeEvent; + type MaxConsumers = ConstU32<16>; +} +impl pallet::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = u64; +} + +pub type Header = sp_runtime::generic::Header; +pub type Block = sp_runtime::generic::Block; +pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic< + u64, + RuntimeCall, + sp_runtime::testing::UintAuthorityId, + frame_system::CheckNonZeroSender, +>; + +frame_support::construct_runtime!( + pub struct Runtime { + // Exclude part `Storage` in order not to check its metadata in tests. + System: frame_system exclude_parts { Pallet, Storage }, + Example: pallet, + + } +); + +#[test] +fn pallet_metadata() { + use sp_metadata_ir::{DeprecationInfoIR, DeprecationStatusIR}; + let pallets = Runtime::metadata_ir().pallets; + let example = pallets[0].clone(); + { + // Example pallet events are partially and fully deprecated + let meta = example.event.unwrap(); + assert_eq!( + DeprecationInfoIR::VariantsDeprecated(BTreeMap::from([ + (codec::Compact(0), DeprecationStatusIR::Deprecated { note: "first", since: None }), + ( + codec::Compact(1), + DeprecationStatusIR::Deprecated { note: "second", since: None } + ) + ])), + meta.deprecation_info + ); + } +} From 644ca6d0249bd994a6a70474c2cb900c24b449d9 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Wed, 5 Feb 2025 11:00:04 +0200 Subject: [PATCH 2/3] fix backport conflict --- .../support/test/tests/enum_deprecation.rs | 171 ------------------ 1 file changed, 171 deletions(-) delete mode 100644 substrate/frame/support/test/tests/enum_deprecation.rs diff --git a/substrate/frame/support/test/tests/enum_deprecation.rs b/substrate/frame/support/test/tests/enum_deprecation.rs deleted file mode 100644 index 72b14dad96291..0000000000000 --- a/substrate/frame/support/test/tests/enum_deprecation.rs +++ /dev/null @@ -1,171 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#![allow(useless_deprecated, deprecated, clippy::deprecated_semver)] - -use std::collections::BTreeMap; - -use frame_support::{ - derive_impl, - dispatch::Parameter, - parameter_types, - traits::{ConstU32, StorageVersion}, - OrdNoBound, PartialOrdNoBound, -}; -use scale_info::TypeInfo; - -parameter_types! { - /// Used to control if the storage version should be updated. - storage UpdateStorageVersion: bool = false; -} - -pub struct SomeType1; -impl From for u64 { - fn from(_t: SomeType1) -> Self { - 0u64 - } -} - -pub trait SomeAssociation1 { - type _1: Parameter + codec::MaxEncodedLen + TypeInfo; -} -impl SomeAssociation1 for u64 { - type _1 = u64; -} - -#[frame_support::pallet] -pub mod pallet { - use super::*; - use frame_support::pallet_prelude::*; - - pub(crate) const STORAGE_VERSION: StorageVersion = StorageVersion::new(10); - - #[pallet::config] - pub trait Config: frame_system::Config - where - ::AccountId: From + SomeAssociation1, - { - type Balance: Parameter + Default + TypeInfo; - - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - } - - #[pallet::pallet] - #[pallet::storage_version(STORAGE_VERSION)] - pub struct Pallet(_); - - #[pallet::error] - #[derive(PartialEq, Eq)] - pub enum Error { - /// error doc comment put in metadata - InsufficientProposersBalance, - NonExistentStorageValue, - Code(u8), - #[codec(skip)] - Skipped(u128), - CompactU8(#[codec(compact)] u8), - } - - #[pallet::event] - pub enum Event - where - T::AccountId: SomeAssociation1 + From, - { - #[deprecated = "second"] - #[codec(index = 1)] - A, - #[deprecated = "first"] - #[codec(index = 0)] - B, - } - - #[pallet::origin] - #[derive( - EqNoBound, - RuntimeDebugNoBound, - CloneNoBound, - PartialEqNoBound, - PartialOrdNoBound, - OrdNoBound, - Encode, - Decode, - TypeInfo, - MaxEncodedLen, - )] - pub struct Origin(PhantomData); -} - -frame_support::parameter_types!( - pub const MyGetParam3: u32 = 12; -); - -#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] -impl frame_system::Config for Runtime { - type BaseCallFilter = frame_support::traits::Everything; - type RuntimeOrigin = RuntimeOrigin; - type Nonce = u64; - type RuntimeCall = RuntimeCall; - type Hash = sp_runtime::testing::H256; - type Hashing = sp_runtime::traits::BlakeTwo256; - type AccountId = u64; - type Lookup = sp_runtime::traits::IdentityLookup; - type Block = Block; - type RuntimeEvent = RuntimeEvent; - type MaxConsumers = ConstU32<16>; -} -impl pallet::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type Balance = u64; -} - -pub type Header = sp_runtime::generic::Header; -pub type Block = sp_runtime::generic::Block; -pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic< - u64, - RuntimeCall, - sp_runtime::testing::UintAuthorityId, - frame_system::CheckNonZeroSender, ->; - -frame_support::construct_runtime!( - pub struct Runtime { - // Exclude part `Storage` in order not to check its metadata in tests. - System: frame_system exclude_parts { Pallet, Storage }, - Example: pallet, - - } -); - -#[test] -fn pallet_metadata() { - use sp_metadata_ir::{DeprecationInfoIR, DeprecationStatusIR}; - let pallets = Runtime::metadata_ir().pallets; - let example = pallets[0].clone(); - { - // Example pallet events are partially and fully deprecated - let meta = example.event.unwrap(); - assert_eq!( - DeprecationInfoIR::VariantsDeprecated(BTreeMap::from([ - (codec::Compact(0), DeprecationStatusIR::Deprecated { note: "first", since: None }), - ( - codec::Compact(1), - DeprecationStatusIR::Deprecated { note: "second", since: None } - ) - ])), - meta.deprecation_info - ); - } -} From b00aeb9a3101c262453fc217b5540435338f25c9 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 5 Feb 2025 12:30:30 +0100 Subject: [PATCH 3/3] prdoc Signed-off-by: Oliver Tale-Yazdi --- prdoc/pr_7460.prdoc | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 prdoc/pr_7460.prdoc diff --git a/prdoc/pr_7460.prdoc b/prdoc/pr_7460.prdoc new file mode 100644 index 0000000000000..bee1eed648ab1 --- /dev/null +++ b/prdoc/pr_7460.prdoc @@ -0,0 +1,10 @@ +title: Update SCALE codec indices + +doc: + - audience: Runtime Dev + description: | + We need this in order to be able to update `parity-scale-codec` to the latest version after it's released. That's because `parity-scale-codec` added support for checking for duplicate indexes at compile time. + +crates: + - name: frame-support-procedural + bump: patch