referrerpolicy=no-referrer-when-downgrade

pallet_paged_list/
mock.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//! Helpers for tests.
19
20#![cfg(feature = "std")]
21
22use crate::{paged_list::StoragePagedListMeta, Config, ListPrefix};
23use frame::testing_prelude::*;
24
25type Block = frame_system::mocking::MockBlock<Test>;
26
27// Configure a mock runtime to test the pallet.
28construct_runtime!(
29	pub enum Test {
30		System: frame_system,
31		PagedList: crate,
32		PagedList2: crate::<Instance2>,
33	}
34);
35
36#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
37impl frame_system::Config for Test {
38	type Nonce = u64;
39	type AccountId = u64;
40	type Lookup = IdentityLookup<Self::AccountId>;
41	type Block = Block;
42	type RuntimeEvent = RuntimeEvent;
43}
44
45parameter_types! {
46	pub storage ValuesPerNewPage: u32 = 5;
47	pub const MaxPages: Option<u32> = Some(20);
48}
49
50impl crate::Config for Test {
51	type Value = u32;
52	type ValuesPerNewPage = ValuesPerNewPage;
53}
54
55impl crate::Config<crate::Instance2> for Test {
56	type Value = u32;
57	type ValuesPerNewPage = ValuesPerNewPage;
58}
59
60pub type MetaOf<T, I> =
61	StoragePagedListMeta<ListPrefix<T, I>, <T as Config>::Value, <T as Config>::ValuesPerNewPage>;
62
63/// Build genesis storage according to the mock runtime.
64pub fn new_test_ext() -> TestState {
65	frame_system::GenesisConfig::<Test>::default().build_storage().unwrap().into()
66}
67
68/// Run this closure in test externalities.
69pub fn test_closure<R>(f: impl FnOnce() -> R) -> R {
70	let mut ext = new_test_ext();
71	ext.execute_with(f)
72}