moonbeam_service/chain_spec/
moonriver.rs1#[cfg(test)]
23use crate::chain_spec::{derive_bip44_pairs_from_mnemonic, get_account_id_from_pair};
24use crate::chain_spec::{generate_accounts, get_from_seed, Extensions};
25use crate::HostFunctions;
26use cumulus_primitives_core::ParaId;
27use hex_literal::hex;
28use moonriver_runtime::{
29 currency::MOVR, genesis_config_preset::testnet_genesis, AccountId, WASM_BINARY,
30};
31use nimbus_primitives::NimbusId;
32use sc_service::ChainType;
33#[cfg(test)]
34use sp_core::ecdsa;
35
36pub type ChainSpec = sc_service::GenericChainSpec<Extensions, HostFunctions>;
38
39pub fn development_chain_spec(mnemonic: Option<String>, num_accounts: Option<u32>) -> ChainSpec {
41 let parent_mnemonic = mnemonic.unwrap_or_else(|| {
43 "bottom drive obey lake curtain smoke basket hold race lonely fit walk".to_string()
44 });
45 let mut accounts = generate_accounts(parent_mnemonic, num_accounts.unwrap_or(10));
46 accounts.push(AccountId::from(hex!(
48 "6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b"
49 )));
50
51 ChainSpec::builder(
52 WASM_BINARY.expect("WASM binary was not build, please build it!"),
53 Extensions {
54 relay_chain: "dev-service".into(),
55 para_id: Default::default(),
56 },
57 )
58 .with_name("Moonriver Development Testnet")
59 .with_id("moonriver_dev")
60 .with_chain_type(ChainType::Development)
61 .with_properties(
62 serde_json::from_str(
63 "{\"tokenDecimals\": 18, \"tokenSymbol\": \"MOVR\", \"SS58Prefix\": 1285}",
64 )
65 .expect("Provided valid json map"),
66 )
67 .with_genesis_config(testnet_genesis(
68 vec![accounts[1], accounts[2], accounts[3]],
70 vec![accounts[0], accounts[1]],
72 vec![(
74 AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
75 get_from_seed::<NimbusId>("Alice"),
76 100_000 * MOVR,
77 )],
78 vec![],
80 accounts.clone(),
81 Default::default(), 1281, ))
84 .build()
85}
86
87pub fn get_chain_spec(para_id: ParaId) -> ChainSpec {
90 ChainSpec::builder(
91 WASM_BINARY.expect("WASM binary was not build, please build it!"),
92 Extensions {
93 relay_chain: "kusama-local".into(),
94 para_id: para_id.into(),
95 },
96 )
97 .with_name("Moonriver Local Testnet")
101 .with_id("moonriver_local")
102 .with_chain_type(ChainType::Local)
103 .with_properties(
104 serde_json::from_str(
105 "{\"tokenDecimals\": 18, \"tokenSymbol\": \"MOVR\", \"SS58Prefix\": 1285}",
106 )
107 .expect("Provided valid json map"),
108 )
109 .with_genesis_config(testnet_genesis(
110 vec![
112 AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")),
113 AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")),
114 AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")),
115 ],
116 vec![
118 AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
119 AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")),
120 ],
121 vec![
123 (
125 AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
126 get_from_seed::<NimbusId>("Alice"),
127 100_000 * MOVR,
128 ),
129 (
131 AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")),
132 get_from_seed::<NimbusId>("Bob"),
133 100_000 * MOVR,
134 ),
135 ],
136 vec![],
138 vec![
140 AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
141 AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")),
142 AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")),
143 AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")),
144 ],
145 para_id,
146 1280, ))
148 .build()
149}
150
151#[cfg(test)]
152mod tests {
153 use super::*;
154 #[test]
155 fn test_derived_pairs_1() {
156 let mnemonic =
157 "bottom drive obey lake curtain smoke basket hold race lonely fit walk".to_string();
158 let accounts = 10;
159 let pairs = derive_bip44_pairs_from_mnemonic::<ecdsa::Public>(&mnemonic, accounts);
160 let first_account = get_account_id_from_pair(pairs.first().unwrap().clone()).unwrap();
161 let last_account = get_account_id_from_pair(pairs.last().unwrap().clone()).unwrap();
162
163 let expected_first_account =
164 AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"));
165 let expected_last_account =
166 AccountId::from(hex!("2898FE7a42Be376C8BC7AF536A940F7Fd5aDd423"));
167 assert_eq!(first_account, expected_first_account);
168 assert_eq!(last_account, expected_last_account);
169 assert_eq!(pairs.len(), 10);
170 }
171 #[test]
172 fn test_derived_pairs_2() {
173 let mnemonic =
174 "slab nerve salon plastic filter inherit valve ozone crash thumb quality whale"
175 .to_string();
176 let accounts = 20;
177 let pairs = derive_bip44_pairs_from_mnemonic::<ecdsa::Public>(&mnemonic, accounts);
178 let first_account = get_account_id_from_pair(pairs.first().unwrap().clone()).unwrap();
179 let last_account = get_account_id_from_pair(pairs.last().unwrap().clone()).unwrap();
180
181 let expected_first_account =
182 AccountId::from(hex!("1e56ca71b596f2b784a27a2fdffef053dbdeff83"));
183 let expected_last_account =
184 AccountId::from(hex!("4148202BF0c0Ad7697Cff87EbB83340C80c947f8"));
185 assert_eq!(first_account, expected_first_account);
186 assert_eq!(last_account, expected_last_account);
187 assert_eq!(pairs.len(), 20);
188 }
189}