git.delta.rocks / unique-network / refs/commits / a560e8db71a2

difftreelog

source

runtime/common/tests/mod.rs2.7 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use sp_runtime::BuildStorage;18use sp_core::{Public, Pair};19use sp_std::vec;20use up_common::types::AuraId;21use crate::{GenesisConfig, ParachainInfoConfig};2223pub mod xcm;2425fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {26	TPublic::Pair::from_string(&format!("//{}", seed), None)27		.expect("static values are valid; qed")28		.public()29}3031#[cfg(feature = "collator-selection")]32fn new_test_ext(para_id: u32) -> sp_io::TestExternalities {33	use sp_core::{sr25519};34	use sp_runtime::traits::{IdentifyAccount, Verify};35	use crate::{AccountId, Signature, SessionKeys, CollatorSelectionConfig, SessionConfig};3637	type AccountPublic = <Signature as Verify>::Signer;3839	fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId40	where41		AccountPublic: From<<TPublic::Pair as Pair>::Public>,42	{43		AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()44	}4546	let accounts = vec!["Alice", "Bob"];47	let keys = accounts48		.iter()49		.map(|&acc| {50			let account_id = get_account_id_from_seed::<sr25519::Public>(acc);51			(52				account_id.clone(),53				account_id,54				SessionKeys {55					aura: get_from_seed::<AuraId>(acc),56				},57			)58		})59		.collect::<Vec<_>>();60	let invulnerables = accounts61		.iter()62		.map(|acc| get_account_id_from_seed::<sr25519::Public>(acc))63		.collect::<Vec<_>>();6465	let cfg = GenesisConfig {66		collator_selection: CollatorSelectionConfig { invulnerables },67		session: SessionConfig { keys },68		parachain_info: ParachainInfoConfig {69			parachain_id: para_id.into(),70		},71		..GenesisConfig::default()72	};7374	cfg.build_storage().unwrap().into()75}7677#[cfg(not(feature = "collator-selection"))]78fn new_test_ext(para_id: u32) -> sp_io::TestExternalities {79	use crate::AuraConfig;8081	let cfg = GenesisConfig {82		aura: AuraConfig {83			authorities: vec![84				get_from_seed::<AuraId>("Alice"),85				get_from_seed::<AuraId>("Bob"),86			],87		},88		parachain_info: ParachainInfoConfig {89			parachain_id: para_id.into(),90		},91		..GenesisConfig::default()92	};9394	cfg.build_storage().unwrap().into()95}