frame_system/mocking.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//! Provide types to help defining a mock environment when testing pallets.
19
20use sp_runtime::generic;
21
22/// An unchecked extrinsic type to be used in tests.
23pub type MockUncheckedExtrinsic<T, Signature = (), Extra = ()> = generic::UncheckedExtrinsic<
24 <T as crate::Config>::AccountId,
25 <T as crate::Config>::RuntimeCall,
26 Signature,
27 Extra,
28>;
29
30/// An implementation of `sp_runtime::traits::Block` to be used in tests.
31pub type MockBlock<T> = generic::Block<
32 generic::Header<u64, sp_runtime::traits::BlakeTwo256>,
33 MockUncheckedExtrinsic<T>,
34>;
35
36/// An implementation of `sp_runtime::traits::Block` to be used in tests with u32 BlockNumber type.
37pub type MockBlockU32<T> = generic::Block<
38 generic::Header<u32, sp_runtime::traits::BlakeTwo256>,
39 MockUncheckedExtrinsic<T>,
40>;
41
42/// An implementation of `sp_runtime::traits::Block` to be used in tests with u128 BlockNumber
43/// type.
44pub type MockBlockU128<T> = generic::Block<
45 generic::Header<u128, sp_runtime::traits::BlakeTwo256>,
46 MockUncheckedExtrinsic<T>,
47>;