Skip to content

Commit

Permalink
make polkadot-parachain chain-spec extension more relaxed
Browse files Browse the repository at this point in the history
  • Loading branch information
kianenigma committed May 14, 2024
1 parent fb7362f commit 9107633
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
22 changes: 21 additions & 1 deletion cumulus/polkadot-parachain/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;

/// Generic extensions for Parachain ChainSpecs.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
#[serde(deny_unknown_fields)]
pub struct Extensions {
/// The relay chain of the Parachain.
#[serde(alias = "relayChain", alias = "RelayChain")]
pub relay_chain: String,
/// The id of the Parachain.
#[serde(alias = "paraId", alias = "ParaId")]
pub para_id: u32,
}

Expand Down Expand Up @@ -78,3 +79,22 @@ where
pub fn get_collator_keys_from_seed<AuraId: Public>(seed: &str) -> <AuraId::Pair as Pair>::Public {
get_from_seed::<AuraId>(seed)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn can_decode_extension_camel_and_snake_case() {
let camel_case = r#"{"RelayChain":"relay","ParaId":1}"#;
let snake_case = r#"{"relay_chain":"relay","para_id":1}"#;
let pascal_case = r#"{"RelayChain":"relay","ParaId":1}"#;

let camel_case_extension: Extensions = serde_json::from_str(camel_case).unwrap();
let snake_case_extension: Extensions = serde_json::from_str(snake_case).unwrap();
let pascal_case_extension: Extensions = serde_json::from_str(pascal_case).unwrap();

assert_eq!(camel_case_extension, snake_case_extension);
assert_eq!(snake_case_extension, pascal_case_extension);
}
}
3 changes: 2 additions & 1 deletion templates/parachain/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Pu

/// The extensions for the [`ChainSpec`].
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
#[serde(deny_unknown_fields)]
pub struct Extensions {
/// The relay chain of the Parachain.
#[serde(alias = "relayChain", alias = "RelayChain")]
pub relay_chain: String,
/// The id of the Parachain.
#[serde(alias = "paraId", alias = "ParaId")]
pub para_id: u32,
}

Expand Down

0 comments on commit 9107633

Please sign in to comment.