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

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_runtime::{BuildStorage, Storage};18use sp_core::{Public, Pair};19use up_common::types::AuraId;20use crate::{Runtime, GenesisConfig, ParachainInfoConfig, RuntimeEvent, System};2122pub use sp_runtime::AccountId32 as AccountId;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::BuildGenesisConfig::<Runtime> { balances }55		.build_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};67	use crate::{AccountId, Signature, SessionKeys, CollatorSelectionConfig, SessionConfig};6869	type AccountPublic = <Signature as Verify>::Signer;7071	fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId72	where73		AccountPublic: From<<TPublic::Pair as Pair>::Public>,74	{75		AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()76	}7778	let accounts = ["Alice", "Bob"];79	let keys = accounts80		.iter()81		.map(|&acc| {82			let account_id = get_account_id_from_seed::<sr25519::Public>(acc);83			(84				account_id.clone(),85				account_id,86				SessionKeys {87					aura: get_from_seed::<AuraId>(acc),88				},89			)90		})91		.collect::<Vec<_>>();92	let invulnerables = accounts93		.iter()94		.map(|acc| get_account_id_from_seed::<sr25519::Public>(acc))95		.collect::<Vec<_>>();9697	let cfg = BuildGenesisConfig {98		collator_selection: CollatorSelectionConfig { invulnerables },99		session: SessionConfig { keys },100		parachain_info: ParachainInfoConfig {101			parachain_id: PARA_ID.into(),102			..Default::default()103		},104		..Default::default()105	};106107	cfg.build_storage().unwrap()108}109110#[cfg(not(feature = "collator-selection"))]111fn make_basic_storage() -> Storage {112	use crate::AuraConfig;113114	let cfg = BuildGenesisConfig {115		aura: AuraConfig {116			authorities: vec![117				get_from_seed::<AuraId>("Alice"),118				get_from_seed::<AuraId>("Bob"),119			],120		},121		parachain_info: ParachainInfoConfig {122			parachain_id: PARA_ID.into(),123			..Default::default()124		},125		..Default::default()126	};127128	cfg.build_storage().unwrap().into()129}