referrerpolicy=no-referrer-when-downgrade

cumulus_test_runtime/
genesis_config_presets.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3
4// Cumulus is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Cumulus is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Cumulus.  If not, see <http://www.gnu.org/licenses/>.
16
17use super::{
18	AccountId, AuraConfig, AuraId, BalancesConfig, ParachainInfoConfig, RuntimeGenesisConfig,
19	SudoConfig,
20};
21use alloc::{vec, vec::Vec};
22
23use cumulus_primitives_core::ParaId;
24use frame_support::build_struct_json_patch;
25use sp_genesis_builder::PresetId;
26use sp_keyring::Sr25519Keyring;
27
28fn cumulus_test_runtime(
29	invulnerables: Vec<AuraId>,
30	endowed_accounts: Vec<AccountId>,
31	id: ParaId,
32) -> serde_json::Value {
33	build_struct_json_patch!(RuntimeGenesisConfig {
34		balances: BalancesConfig {
35			balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
36		},
37		sudo: SudoConfig { key: Some(Sr25519Keyring::Alice.public().into()) },
38		parachain_info: ParachainInfoConfig { parachain_id: id },
39		aura: AuraConfig { authorities: invulnerables },
40	})
41}
42
43fn testnet_genesis_with_default_endowed(self_para_id: ParaId) -> serde_json::Value {
44	let endowed = Sr25519Keyring::well_known().map(|x| x.to_account_id()).collect::<Vec<_>>();
45
46	let invulnerables =
47		Sr25519Keyring::invulnerable().map(|x| x.public().into()).collect::<Vec<_>>();
48	cumulus_test_runtime(invulnerables, endowed, self_para_id)
49}
50
51/// List of supported presets.
52pub fn preset_names() -> Vec<PresetId> {
53	vec![
54		PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET),
55		PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET),
56	]
57}
58
59/// Provides the JSON representation of predefined genesis config for given `id`.
60pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
61	let patch = match id.as_ref() {
62		sp_genesis_builder::DEV_RUNTIME_PRESET |
63		sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET =>
64			testnet_genesis_with_default_endowed(100.into()),
65		_ => return None,
66	};
67	Some(
68		serde_json::to_string(&patch)
69			.expect("serialization to json is expected to work. qed.")
70			.into_bytes(),
71	)
72}