referrerpolicy=no-referrer-when-downgrade

frame_support_test_stg_frame_crate/
lib.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18// ! A basic pallet to test it compiles along with a runtime using it when `frame_system` and
19// `frame_support` are reexported by a `frame` crate.
20
21use frame::deps::{frame_support, frame_system};
22
23#[frame_support::pallet]
24pub mod pallet {
25	use super::*;
26	use frame_support::pallet_prelude::*;
27
28	#[pallet::pallet]
29	pub struct Pallet<T>(_);
30
31	#[pallet::config]
32	// The only valid syntax here is the following or
33	// ```
34	// pub trait Config: frame::deps::frame_system::Config {}
35	// ```
36	pub trait Config: frame_system::Config {}
37
38	#[pallet::genesis_config]
39	#[derive(frame_support::DefaultNoBound)]
40	pub struct GenesisConfig<T: Config> {
41		#[serde(skip)]
42		_config: core::marker::PhantomData<T>,
43	}
44
45	#[pallet::genesis_build]
46	impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
47		fn build(&self) {}
48	}
49}
50
51#[cfg(test)]
52// Dummy test to make sure a runtime would compile.
53mod tests {
54	use super::{
55		frame_support::{construct_runtime, derive_impl},
56		frame_system, pallet,
57	};
58
59	type Block = frame_system::mocking::MockBlock<Runtime>;
60
61	impl crate::pallet::Config for Runtime {}
62
63	#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
64	impl frame_system::Config for Runtime {
65		type Block = Block;
66	}
67
68	construct_runtime! {
69		pub struct Runtime
70		{
71			System: frame_system,
72			Pallet: pallet,
73		}
74	}
75}