Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Add MaxEncodeLen to implement_per_thing! (#10715)
Browse files Browse the repository at this point in the history
* fix doc

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add MaxEncodedLen to implement_per_thing!

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Test that Percent et.al. can be used in Storage.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add comment

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Revert "Test that Percent et.al. can be used in Storage."

This reverts commit 52558af.

* Test MaxEncodedLen in implement_per_thing!

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Revert "Add comment"

This reverts commit 27a96f6.
  • Loading branch information
ggwpez authored Jan 21, 2022
1 parent 9247e15 commit 227a94f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion frame/support/test/tests/pallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
11 changes: 10 additions & 1 deletion primitives/arithmetic/src/per_things.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -905,6 +905,15 @@ macro_rules! implement_per_thing {
}
}

#[test]
fn has_max_encoded_len() {
struct AsMaxEncodedLen<T: codec::MaxEncodedLen> {
_data: T,
}

let _ = AsMaxEncodedLen { _data: $name(1) };
}

#[test]
fn fail_on_invalid_encoded_value() {
let value = <$upper_type>::from($max) * 2;
Expand Down

0 comments on commit 227a94f

Please sign in to comment.