pallet_bags_list_remote_tests/
migration.rs1use crate::{RuntimeT, LOG_TARGET};
20use frame_support::traits::PalletInfoAccess;
21use pallet_staking::Nominators;
22use remote_externalities::{Builder, Mode, OnlineConfig};
23use sp_runtime::{traits::Block as BlockT, DeserializeOwned};
24
25pub async fn execute<Runtime, Block>(
28 currency_unit: u64,
29 currency_name: &'static str,
30 ws_url: String,
31) where
32 Runtime: 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_staking::Pallet::<Runtime>::name().to_string()],
40 ..Default::default()
41 }))
42 .build()
43 .await
44 .unwrap();
45
46 ext.execute_with(|| {
47 let pre_migrate_nominator_count = <Nominators<Runtime>>::iter().count() as u32;
49 log::info!(target: LOG_TARGET, "Nominator count: {}", pre_migrate_nominator_count);
50
51 use frame_election_provider_support::SortedListProvider;
52 let moved = <Runtime as pallet_staking::Config>::VoterList::unsafe_regenerate(
54 pallet_staking::Nominators::<Runtime>::iter().map(|(n, _)| n),
55 Box::new(|x| Some(pallet_staking::Pallet::<Runtime>::weight_of(x))),
56 );
57 log::info!(target: LOG_TARGET, "Moved {} nominators", moved);
58
59 let voter_list_len = <Runtime as pallet_staking::Config>::VoterList::iter().count() as u32;
60 let voter_list_count = <Runtime as pallet_staking::Config>::VoterList::count();
61 assert_eq!(pre_migrate_nominator_count, voter_list_len);
63 assert_eq!(pre_migrate_nominator_count, voter_list_count);
64
65 crate::display_and_check_bags::<Runtime>(currency_unit, currency_name);
66 });
67}