Implement #[pallet::composite_enum] (#13722)

* Implement #[pallet::hold_reason]

* Appease clippy

* cargo fmt

* Update test expectations

* Update test expectations

* Support composite_enum attribute instead

* Update test expectations

* Change hold_reason to composite_enum

* Add UI test for unsupported identifier when using composite_enum

* Fix comment

* Add documentation for pallet::composable_enum

* More docs

* cargo fmt
This commit is contained in:
Keith Yeung
2023-04-04 20:28:46 +08:00
committed by GitHub
parent c268f3d3c8
commit 1a55f961c6
26 changed files with 682 additions and 11 deletions
@@ -476,6 +476,11 @@ pub mod pallet {
}
}
#[pallet::composite_enum]
pub enum HoldReason {
Staking,
}
#[derive(codec::Encode, sp_runtime::RuntimeDebug)]
#[cfg_attr(feature = "std", derive(codec::Decode))]
pub enum InherentError {
@@ -570,6 +575,16 @@ pub mod pallet2 {
{
fn build(&self) {}
}
#[pallet::composite_enum]
pub enum HoldReason {
Governance,
}
#[pallet::composite_enum]
pub enum SlashReason {
Equivocation,
}
}
/// Test that the supertrait check works when we pass some parameter to the `frame_system::Config`.
@@ -974,6 +989,17 @@ fn validate_unsigned_expand() {
assert_eq!(validity, ValidTransaction::default());
}
#[test]
fn composite_expand() {
let hold_reason: RuntimeHoldReason = pallet::HoldReason::Staking.into();
let hold_reason2: RuntimeHoldReason = pallet2::HoldReason::Governance.into();
let slash_reason: RuntimeSlashReason = pallet2::SlashReason::Equivocation.into();
assert_eq!(hold_reason, RuntimeHoldReason::Example(pallet::HoldReason::Staking));
assert_eq!(hold_reason2, RuntimeHoldReason::Example2(pallet2::HoldReason::Governance));
assert_eq!(slash_reason, RuntimeSlashReason::Example2(pallet2::SlashReason::Equivocation));
}
#[test]
fn pallet_expand_deposit_event() {
TestExternalities::default().execute_with(|| {