From 4880741eaa2b9043fd20bbb23222bd2fe0c3c98a Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Fri, 21 Jan 2022 18:08:35 +0100 Subject: [PATCH] Add `MaxEncodeLen` to `implement_per_thing!` (#10715) * fix doc Signed-off-by: Oliver Tale-Yazdi * Add MaxEncodedLen to implement_per_thing! Signed-off-by: Oliver Tale-Yazdi * Test that Percent et.al. can be used in Storage. Signed-off-by: Oliver Tale-Yazdi * Add comment Signed-off-by: Oliver Tale-Yazdi * Revert "Test that Percent et.al. can be used in Storage." This reverts commit 52558afea6f9b53fb07521f1b6393bc320d21dfc. * Test MaxEncodedLen in implement_per_thing! Signed-off-by: Oliver Tale-Yazdi * Revert "Add comment" This reverts commit 27a96f6e527f71a57ace289c041de514edbe9104. --- substrate/frame/support/test/tests/pallet.rs | 2 +- substrate/primitives/arithmetic/src/per_things.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/substrate/frame/support/test/tests/pallet.rs b/substrate/frame/support/test/tests/pallet.rs index 2cb7b283b6..cf88255608 100644 --- a/substrate/frame/support/test/tests/pallet.rs +++ b/substrate/frame/support/test/tests/pallet.rs @@ -432,7 +432,7 @@ pub mod pallet { } // Test that a pallet with non generic event and generic genesis_config is correctly handled -// and that a pallet without the attribute generate_storage_info is correctly handled. +// and that a pallet with the attribute without_storage_info is correctly handled. #[frame_support::pallet] pub mod pallet2 { use super::{SomeAssociation1, SomeType1}; diff --git a/substrate/primitives/arithmetic/src/per_things.rs b/substrate/primitives/arithmetic/src/per_things.rs index 21ad0dd520..fbd45bb693 100644 --- a/substrate/primitives/arithmetic/src/per_things.rs +++ b/substrate/primitives/arithmetic/src/per_things.rs @@ -425,7 +425,7 @@ macro_rules! implement_per_thing { /// #[doc = $title] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] - #[derive(Encode, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, RuntimeDebug, scale_info::TypeInfo)] + #[derive(Encode, Copy, Clone, PartialEq, Eq, codec::MaxEncodedLen, PartialOrd, Ord, RuntimeDebug, scale_info::TypeInfo)] pub struct $name($type); /// Implementation makes any compact encoding of `PerThing::Inner` valid, @@ -905,6 +905,15 @@ macro_rules! implement_per_thing { } } + #[test] + fn has_max_encoded_len() { + struct AsMaxEncodedLen { + _data: T, + } + + let _ = AsMaxEncodedLen { _data: $name(1) }; + } + #[test] fn fail_on_invalid_encoded_value() { let value = <$upper_type>::from($max) * 2;