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

difftreelog

source

runtime/common/tests/mod.rs3.5 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_core::{Pair, Public};18pub use sp_runtime::AccountId32 as AccountId;19use sp_runtime::{BuildStorage, Storage};20use up_common::types::AuraId;2122use crate::{ParachainInfoConfig, Runtime, RuntimeEvent, RuntimeGenesisConfig, System};23pub type Balance = u128;2425pub mod xcm;2627#[cfg(any(feature = "opal-runtime", feature = "quartz-runtime"))]28/// PARA_ID for Opal/Sapphire/Quartz29const PARA_ID: u32 = 2095;3031#[cfg(feature = "unique-runtime")]32/// PARA_ID for Unique33const PARA_ID: u32 = 2037;3435fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {36	TPublic::Pair::from_string(&format!("//{seed}"), None)37		.expect("static values are valid; qed")38		.public()39}4041fn last_events(n: usize) -> Vec<RuntimeEvent> {42	System::events()43		.into_iter()44		.map(|e| e.event)45		.rev()46		.take(n)47		.rev()48		.collect()49}5051fn new_test_ext(balances: Vec<(AccountId, Balance)>) -> sp_io::TestExternalities {52	let mut storage = make_basic_storage();5354	pallet_balances::GenesisConfig::<Runtime> { balances }55		.assimilate_storage(&mut storage)56		.unwrap();5758	let mut ext = sp_io::TestExternalities::new(storage);59	ext.execute_with(|| System::set_block_number(1));60	ext61}6263#[cfg(feature = "collator-selection")]64fn make_basic_storage() -> Storage {65	use sp_core::sr25519;66	use sp_runtime::traits::{IdentifyAccount, Verify};6768	use crate::{AccountId, CollatorSelectionConfig, SessionConfig, SessionKeys, Signature};6970	type AccountPublic = <Signature as Verify>::Signer;7172	fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId73	where74		AccountPublic: From<<TPublic::Pair as Pair>::Public>,75	{76		AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()77	}7879	let accounts = ["Alice", "Bob"];80	let keys = accounts81		.iter()82		.map(|&acc| {83			let account_id = get_account_id_from_seed::<sr25519::Public>(acc);84			(85				account_id.clone(),86				account_id,87				SessionKeys {88					aura: get_from_seed::<AuraId>(acc),89				},90			)91		})92		.collect::<Vec<_>>();93	let invulnerables = accounts94		.iter()95		.map(|acc| get_account_id_from_seed::<sr25519::Public>(acc))96		.collect::<Vec<_>>();9798	let cfg = RuntimeGenesisConfig {99		collator_selection: CollatorSelectionConfig { invulnerables },100		session: SessionConfig { keys },101		parachain_info: ParachainInfoConfig {102			parachain_id: PARA_ID.into(),103			..Default::default()104		},105		..Default::default()106	};107108	cfg.build_storage().unwrap()109}110111#[cfg(not(feature = "collator-selection"))]112fn make_basic_storage() -> Storage {113	use crate::AuraConfig;114115	let cfg = RuntimeGenesisConfig {116		aura: AuraConfig {117			authorities: vec![118				get_from_seed::<AuraId>("Alice"),119				get_from_seed::<AuraId>("Bob"),120			],121		},122		parachain_info: ParachainInfoConfig {123			parachain_id: PARA_ID.into(),124			..Default::default()125		},126		..Default::default()127	};128129	cfg.build_storage().unwrap().into()130}