referrerpolicy=no-referrer-when-downgrade

pallet_bags_list_remote_tests/
try_state.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Substrate.
3// SPDX-License-Identifier: Apache-2.0
4
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// 	http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17//! Test to execute the sanity-check of the voter bag.
18
19use frame_support::{
20	storage::generator::StorageMap,
21	traits::{Get, PalletInfoAccess},
22};
23use remote_externalities::{Builder, Mode, OnlineConfig};
24use sp_runtime::{traits::Block as BlockT, DeserializeOwned};
25
26/// Execute the sanity check of the bags-list.
27pub async fn execute<Runtime, Block>(
28	currency_unit: u64,
29	currency_name: &'static str,
30	ws_url: String,
31) where
32	Runtime: crate::RuntimeT<pallet_bags_list::Instance1>,
33	Block: BlockT + DeserializeOwned,
34	Block::Header: DeserializeOwned,
35{
36	let mut ext = Builder::<Block>::new()
37		.mode(Mode::Online(OnlineConfig {
38			transport: ws_url.to_string().into(),
39			pallets: vec![pallet_bags_list::Pallet::<Runtime, pallet_bags_list::Instance1>::name()
40				.to_string()],
41			hashed_prefixes: vec![
42				<pallet_staking::Bonded<Runtime>>::prefix_hash().to_vec(),
43				<pallet_staking::Ledger<Runtime>>::prefix_hash().to_vec(),
44			],
45			..Default::default()
46		}))
47		.build()
48		.await
49		.unwrap();
50
51	ext.execute_with(|| {
52		sp_core::crypto::set_default_ss58_version(Runtime::SS58Prefix::get().try_into().unwrap());
53
54		pallet_bags_list::Pallet::<Runtime, pallet_bags_list::Instance1>::do_try_state().unwrap();
55
56		log::info!(target: crate::LOG_TARGET, "executed bags-list sanity check with no errors.");
57
58		crate::display_and_check_bags::<Runtime>(currency_unit, currency_name);
59	});
60}