Attribute Macro frame_support_procedural::inject_runtime_type

source ·
#[inject_runtime_type]
Expand description

The optional attribute #[inject_runtime_type] can be attached to RuntimeCall, RuntimeEvent, RuntimeOrigin or PalletInfo in an impl statement that has #[register_default_impl] attached to indicate that this item is generated by construct_runtime.

Attaching this attribute to such an item ensures that the combined impl generated via #[derive_impl(..)] will use the correct type auto-generated by construct_runtime!.

#[test]
fn derive_impl_works_with_runtime_type_injection() {
	assert_type_eq_all!(<Runtime as Config>::RuntimeOrigin, super::RuntimeOrigin);
	assert_type_eq_all!(<Runtime as Config>::RuntimeCall, super::RuntimeCall);
	assert_type_eq_all!(<Runtime as Config>::PalletInfo, super::PalletInfo);
}

However, if no_aggregated_types is specified while using #[derive_impl(..)], then these items are attached verbatim to the combined impl.

#[test]
fn derive_impl_works_with_no_aggregated_types() {
	struct DummyRuntime;

	#[derive_impl(
        super::frame_system::config_preludes::TestDefaultConfig as super::frame_system::DefaultConfig,
        no_aggregated_types
    )]
	impl Config for DummyRuntime {
		type Block = super::Block;
		type AccountId = super::AccountId;
		type PalletInfo = super::PalletInfo;
		type ExampleConstant = ();
	}

	assert_type_eq_all!(<DummyRuntime as Config>::RuntimeOrigin, ());
	assert_type_eq_all!(<DummyRuntime as Config>::RuntimeCall, ());
}