Ensure correct variant count in Runtime[Hold/Freeze]Reason (#1900)

closes https://github.com/paritytech/polkadot-sdk/issues/1882

## Breaking Changes

This PR introduces a new item to `pallet_balances::Config`:

```diff
trait Config {
++    type RuntimeFreezeReasons;
}
```

This value is only used to check it against `type MaxFreeze`. A similar
check has been added for `MaxHolds` against `RuntimeHoldReasons`, which
is already given to `pallet_balances`.

In all contexts, you should pass the real `RuntimeFreezeReasons`
generated by `construct_runtime` to `type RuntimeFreezeReasons`. Passing
`()` would also work, but it would imply that the runtime uses no
freezes at all.

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
Kian Paimani
2023-10-24 11:01:04 +01:00
committed by GitHub
parent a5a2432d22
commit 35eb133baa
102 changed files with 154 additions and 10 deletions
+7 -2
View File
@@ -27,7 +27,7 @@ use frame_support::{
parameter_types,
traits::{
fungible, ConstU32, ConstU64, ConstU8, Imbalance as ImbalanceT, OnUnbalanced,
StorageMapShim, StoredMap, WhitelistedStorageKeys,
StorageMapShim, StoredMap, VariantCount, WhitelistedStorageKeys,
},
weights::{IdentityFee, Weight},
};
@@ -70,6 +70,10 @@ pub enum TestId {
Baz,
}
impl VariantCount for TestId {
const VARIANT_COUNT: u32 = 3;
}
frame_support::construct_runtime!(
pub struct Test
{
@@ -132,9 +136,10 @@ impl Config for Test {
type ReserveIdentifier = TestId;
type WeightInfo = ();
type RuntimeHoldReason = TestId;
type RuntimeFreezeReason = RuntimeFreezeReason;
type FreezeIdentifier = TestId;
type MaxFreezes = ConstU32<2>;
type MaxHolds = ConstU32<2>;
type MaxHolds = ConstU32<3>;
}
#[derive(Clone)]