mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 21:37:56 +00:00
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:
+1
-1
@@ -1,4 +1,4 @@
|
||||
error: expected one of: `Pallet`, `Call`, `Storage`, `Event`, `Config`, `Origin`, `Inherent`, `ValidateUnsigned`
|
||||
error: expected one of: `Pallet`, `Call`, `Storage`, `Event`, `Config`, `Origin`, `Inherent`, `ValidateUnsigned`, `FreezeReason`, `HoldReason`, `LockId`, `SlashReason`
|
||||
--> $DIR/invalid_module_details_keyword.rs:9:20
|
||||
|
|
||||
9 | system: System::{enum},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
error: expected one of: `Pallet`, `Call`, `Storage`, `Event`, `Config`, `Origin`, `Inherent`, `ValidateUnsigned`
|
||||
error: expected one of: `Pallet`, `Call`, `Storage`, `Event`, `Config`, `Origin`, `Inherent`, `ValidateUnsigned`, `FreezeReason`, `HoldReason`, `LockId`, `SlashReason`
|
||||
--> $DIR/invalid_module_entry.rs:10:23
|
||||
|
|
||||
10 | Balance: balances::{Error},
|
||||
|
||||
@@ -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(|| {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(core::marker::PhantomData<T>);
|
||||
|
||||
#[pallet::composite_enum]
|
||||
pub enum HoldReasons {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
error: expected one of: `FreezeReason`, `HoldReason`, `LockId`, `SlashReason`
|
||||
--> tests/pallet_ui/composite_enum_unsupported_identifier.rs:10:11
|
||||
|
|
||||
10 | pub enum HoldReasons {}
|
||||
| ^^^^^^^^^^^
|
||||
@@ -1,4 +1,4 @@
|
||||
error: Invalid pallet::event, expected item enum
|
||||
error: Invalid pallet::event, expected enum item
|
||||
--> $DIR/event_wrong_item.rs:19:2
|
||||
|
|
||||
19 | pub struct Foo;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(core::marker::PhantomData<T>);
|
||||
|
||||
#[pallet::composite_enum]
|
||||
pub struct HoldReason;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Invalid pallet::composite_enum, expected enum item
|
||||
--> tests/pallet_ui/hold_reason_non_enum.rs:10:2
|
||||
|
|
||||
10 | pub struct HoldReason;
|
||||
| ^^^
|
||||
@@ -0,0 +1,14 @@
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(core::marker::PhantomData<T>);
|
||||
|
||||
#[pallet::composite_enum]
|
||||
enum HoldReason {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Invalid pallet::composite_enum, `HoldReason` must be public
|
||||
--> tests/pallet_ui/hold_reason_not_pub.rs:10:5
|
||||
|
|
||||
10 | enum HoldReason {}
|
||||
| ^^^^
|
||||
@@ -0,0 +1,17 @@
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(core::marker::PhantomData<T>);
|
||||
|
||||
#[pallet::composite_enum]
|
||||
pub enum LockId {}
|
||||
|
||||
#[pallet::composite_enum]
|
||||
pub enum LockId {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Invalid duplicated `LockId` definition
|
||||
--> tests/pallet_ui/lock_id_duplicate.rs:13:14
|
||||
|
|
||||
13 | pub enum LockId {}
|
||||
| ^^^^^^
|
||||
Reference in New Issue
Block a user