cumulus_test_service/
chain_spec.rs1#![allow(missing_docs)]
18
19use cumulus_client_service::ParachainHostFunctions;
20use cumulus_primitives_core::ParaId;
21use cumulus_test_runtime::AccountId;
22use sc_chain_spec::GenesisConfigBuilderRuntimeCaller;
23use sc_service::{ChainType, GenericChainSpec};
24use serde_json::json;
25
26pub fn get_chain_spec_with_extra_endowed(
30 id: Option<ParaId>,
31 extra_endowed_accounts: Vec<AccountId>,
32 code: &[u8],
33) -> GenericChainSpec {
34 let runtime_caller = GenesisConfigBuilderRuntimeCaller::<ParachainHostFunctions>::new(code);
35 let mut development_preset = runtime_caller
36 .get_named_preset(Some(&sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET.to_string()))
37 .expect("development preset is available on test runtime; qed");
38
39 let existing_balances = development_preset
41 .get("balances")
42 .and_then(|b| b.get("balances"))
43 .and_then(|b| b.as_array())
44 .cloned()
45 .unwrap_or_default();
46
47 let mut all_balances = existing_balances;
49 all_balances.extend(extra_endowed_accounts.into_iter().map(|a| json!([a, 1u64 << 60])));
50
51 let mut patch_json = json!({
52 "balances": {
53 "balances": all_balances,
54 },
55 });
56
57 if let Some(id) = id {
58 sc_chain_spec::json_merge(
60 &mut patch_json,
61 json!({
62 "parachainInfo": {
63 "parachainId": id,
64 },
65
66 }),
67 );
68 };
69
70 sc_chain_spec::json_merge(&mut development_preset, patch_json.into());
71
72 GenericChainSpec::builder(code, None)
73 .with_name("Local Testnet")
74 .with_id(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET)
75 .with_chain_type(ChainType::Local)
76 .with_genesis_config_patch(development_preset)
77 .build()
78}
79
80pub fn get_chain_spec(wasm_binary: Option<&[u8]>, id: Option<ParaId>) -> GenericChainSpec {
82 get_chain_spec_with_extra_endowed(
83 id,
84 Default::default(),
85 wasm_binary.expect("WASM binary was not built, please build it!"),
86 )
87}