Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isEthereum ChainSpec property #110

Merged
merged 3 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion container-chains/templates/frontier/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub fn development_config(para_id: ParaId, seeds: Option<Vec<String>>) -> ChainS
properties.insert("tokenSymbol".into(), "UNIT".into());
properties.insert("tokenDecimals".into(), 12.into());
properties.insert("ss58Format".into(), 42.into());
properties.insert("isEthereum".into(), true.into());

let initial_collator_seeds = seeds.unwrap_or(vec!["Alice".to_string(), "Bob".to_string()]);
let collator_accounts: Vec<AccountId> = initial_collator_seeds
Expand Down Expand Up @@ -127,7 +128,7 @@ pub fn development_config(para_id: ParaId, seeds: Option<Vec<String>>) -> ChainS
None,
None,
None,
None,
Some(properties),
Extensions {
relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
para_id: para_id.into(),
Expand All @@ -141,6 +142,7 @@ pub fn local_testnet_config(para_id: ParaId, seeds: Option<Vec<String>>) -> Chai
properties.insert("tokenSymbol".into(), "UNIT".into());
properties.insert("tokenDecimals".into(), 12.into());
properties.insert("ss58Format".into(), 42.into());
properties.insert("isEthereum".into(), true.into());
let protocol_id = Some(format!("container-chain-{}", para_id));

let initial_collator_seeds = seeds.unwrap_or(vec!["Alice".to_string(), "Bob".to_string()]);
Expand Down
4 changes: 3 additions & 1 deletion container-chains/templates/simple/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub fn development_config(para_id: ParaId, seeds: Option<Vec<String>>) -> ChainS
properties.insert("tokenSymbol".into(), "UNIT".into());
properties.insert("tokenDecimals".into(), 12.into());
properties.insert("ss58Format".into(), 42.into());
properties.insert("isEthereum".into(), false.into());

let initial_collator_seeds = seeds.unwrap_or(vec!["Alice".to_string(), "Bob".to_string()]);
let collator_accounts: Vec<AccountId> = initial_collator_seeds
Expand Down Expand Up @@ -123,7 +124,7 @@ pub fn development_config(para_id: ParaId, seeds: Option<Vec<String>>) -> ChainS
None,
None,
None,
None,
Some(properties),
Extensions {
relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
para_id: para_id.into(),
Expand All @@ -137,6 +138,7 @@ pub fn local_testnet_config(para_id: ParaId, seeds: Option<Vec<String>>) -> Chai
properties.insert("tokenSymbol".into(), "UNIT".into());
properties.insert("tokenDecimals".into(), 12.into());
properties.insert("ss58Format".into(), 42.into());
properties.insert("isEthereum".into(), false.into());
let protocol_id = Some(format!("container-chain-{}", para_id));

let initial_collator_seeds = seeds.unwrap_or(vec!["Alice".to_string(), "Bob".to_string()]);
Expand Down
4 changes: 3 additions & 1 deletion node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ pub fn development_config(
properties.insert("tokenSymbol".into(), "UNIT".into());
properties.insert("tokenDecimals".into(), 12.into());
properties.insert("ss58Format".into(), 42.into());
properties.insert("isEthereum".into(), false.into());

ChainSpec::from_genesis(
// Name
Expand Down Expand Up @@ -197,7 +198,7 @@ pub fn development_config(
None,
None,
None,
None,
Some(properties),
Extensions {
relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
para_id: para_id.into(),
Expand All @@ -215,6 +216,7 @@ pub fn local_testnet_config(
properties.insert("tokenSymbol".into(), "UNIT".into());
properties.insert("tokenDecimals".into(), 12.into());
properties.insert("ss58Format".into(), 42.into());
properties.insert("isEthereum".into(), false.into());

ChainSpec::from_genesis(
// Name
Expand Down
2 changes: 1 addition & 1 deletion pallets/registrar/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fn genesis_error_on_duplicate() {
}

#[test]
#[should_panic = "genesis data for para_id 2 is too large: 5000023 bytes"]
#[should_panic = "genesis data for para_id 2 is too large: 5000024 bytes"]
fn genesis_error_genesis_data_size_too_big() {
let genesis_data = ContainerChainGenesisData {
storage: vec![(vec![], vec![0; 5_000_000]).into()],
Expand Down
13 changes: 13 additions & 0 deletions primitives/container-chain-genesis-data/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ pub fn properties_from_chainspec_json(properties_json: &serde_json::Value) -> To
}) {
properties.token_symbol = x;
}
if let Some(x) = properties_json.get("isEthereum").and_then(|x| {
x.as_bool()
}).or_else(|| {
log::warn!(
"Failed to read properties.isEthereum from container chain chain spec, using default value instead. Invalid value was: {:?}",
properties_json.get("isEthereum")
);

None
}) {
properties.is_ethereum = x;
}

properties
}
Expand All @@ -177,6 +189,7 @@ pub fn properties_to_map(
.map_err(|e| format!("tokenSymbol is not valid UTF8: {}", e))?,
),
),
("isEthereum", serde_json::Value::from(false)),
]
.into_iter()
.map(|(k, v)| (k.to_string(), v))
Expand Down
2 changes: 2 additions & 0 deletions primitives/container-chain-genesis-data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub struct TokenMetadata {
pub token_symbol: BoundedVec<u8, MaxLengthTokenSymbol>,
pub ss58_format: u32,
pub token_decimals: u32,
pub is_ethereum: bool,
}

impl Default for TokenMetadata {
Expand All @@ -97,6 +98,7 @@ impl Default for TokenMetadata {
token_symbol: BoundedVec::truncate_from(b"UNIT".to_vec()),
ss58_format: 42,
token_decimals: 12,
is_ethereum: false,
girazoki marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions test/suites/para/test_tanssi_containers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,16 @@ describeSuite({
expect(authorities.toJSON().includes(author.toString())).to.be.true;
},
});

it({
id: "T10",
title: "Test frontier template isEthereum",
test: async function () {
const genesisData2000 = (await paraApi.query.registrar.paraGenesisData(2000));
expect(genesisData2000.toJSON().properties.isEthereum).to.be.false;
const genesisData2001 = (await paraApi.query.registrar.paraGenesisData(2001));
expect(genesisData2001.toJSON().properties.isEthereum).to.be.true;
},
});
},
});