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_block_bundling_chain_spec(id: Option<ParaId>) -> GenericChainSpec {
119 get_chain_spec_with_extra_endowed(
120 id,
121 Default::default(),
122 cumulus_test_runtime::block_bundling::WASM_BINARY
123 .expect("WASM binary was not built, please build it!"),
124 )
125}
126
127pub fn get_sync_backing_chain_spec(id: Option<ParaId>) -> GenericChainSpec {
128 get_chain_spec_with_extra_endowed(
129 id,
130 Default::default(),
131 cumulus_test_runtime::sync_backing::WASM_BINARY
132 .expect("WASM binary was not built, please build it!"),
133 )
134}
135
136pub fn get_async_backing_v3_chain_spec(id: Option<ParaId>) -> GenericChainSpec {
138 get_chain_spec_with_extra_endowed(
139 id,
140 Default::default(),
141 cumulus_test_runtime::async_backing_v3::WASM_BINARY
142 .expect("WASM binary was not built, please build it!"),
143 )
144}
145
146pub fn get_async_backing_v3_rpo_chain_spec(id: Option<ParaId>) -> GenericChainSpec {
148 get_chain_spec_with_extra_endowed(
149 id,
150 Default::default(),
151 cumulus_test_runtime::async_backing_v3_rpo::WASM_BINARY
152 .expect("WASM binary was not built, please build it!"),
153 )
154}
155
156pub fn get_elastic_scaling_v3_chain_spec(id: Option<ParaId>) -> GenericChainSpec {
158 get_chain_spec_with_extra_endowed(
159 id,
160 Default::default(),
161 cumulus_test_runtime::elastic_scaling_v3::WASM_BINARY
162 .expect("WASM binary was not built, please build it!"),
163 )
164}
165
166pub fn get_async_backing_chain_spec(id: Option<ParaId>) -> GenericChainSpec {
167 get_chain_spec_with_extra_endowed(
168 id,
169 Default::default(),
170 cumulus_test_runtime::async_backing::WASM_BINARY
171 .expect("WASM binary was not built, please build it!"),
172 )
173}
174
175pub fn get_with_authority_discovery_chain_spec(id: Option<ParaId>) -> GenericChainSpec {
182 get_chain_spec_with_extra_endowed(
183 id,
184 Default::default(),
185 cumulus_test_runtime::with_authority_discovery::WASM_BINARY
186 .expect("WASM binary was not built, please build it!"),
187 )
188}