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(id: Option<ParaId>) -> GenericChainSpec {
82 get_chain_spec_with_extra_endowed(
83 id,
84 Default::default(),
85 cumulus_test_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
86 )
87}
88
89pub fn get_elastic_scaling_chain_spec(id: Option<ParaId>) -> GenericChainSpec {
91 get_chain_spec_with_extra_endowed(
92 id,
93 Default::default(),
94 cumulus_test_runtime::elastic_scaling::WASM_BINARY
95 .expect("WASM binary was not built, please build it!"),
96 )
97}
98
99pub fn get_relay_parent_offset_chain_spec(id: Option<ParaId>) -> GenericChainSpec {
100 get_chain_spec_with_extra_endowed(
101 id,
102 Default::default(),
103 cumulus_test_runtime::relay_parent_offset::WASM_BINARY
104 .expect("WASM binary was not built, please build it!"),
105 )
106}
107
108pub fn get_elastic_scaling_500ms_chain_spec(id: Option<ParaId>) -> GenericChainSpec {
110 get_chain_spec_with_extra_endowed(
111 id,
112 Default::default(),
113 cumulus_test_runtime::elastic_scaling_500ms::WASM_BINARY
114 .expect("WASM binary was not built, please build it!"),
115 )
116}
117
118pub fn get_elastic_scaling_mvp_chain_spec(id: Option<ParaId>) -> GenericChainSpec {
120 get_chain_spec_with_extra_endowed(
121 id,
122 Default::default(),
123 cumulus_test_runtime::elastic_scaling_mvp::WASM_BINARY
124 .expect("WASM binary was not built, please build it!"),
125 )
126}
127
128pub fn get_elastic_scaling_multi_block_slot_chain_spec(id: Option<ParaId>) -> GenericChainSpec {
129 get_chain_spec_with_extra_endowed(
130 id,
131 Default::default(),
132 cumulus_test_runtime::elastic_scaling_multi_block_slot::WASM_BINARY
133 .expect("WASM binary was not built, please build it!"),
134 )
135}
136
137pub fn get_sync_backing_chain_spec(id: Option<ParaId>) -> GenericChainSpec {
138 get_chain_spec_with_extra_endowed(
139 id,
140 Default::default(),
141 cumulus_test_runtime::sync_backing::WASM_BINARY
142 .expect("WASM binary was not built, please build it!"),
143 )
144}