Skip to content

Commit 5c97c0f

Browse files
[Penpal] fix genesis presets - assign proper ED to accounts (#11575)
Penpal had values below the ED for initializing asset balances for some accounts. This has not been detected as no unit tests actually use the presets. This PR fixes the invalid values, and it also adds some unit tests for validating that the presets build at least. Closes #11558. --------- Co-authored-by: clangenb <clangenb@users.noreply.github.com> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 59c4053 commit 5c97c0f

4 files changed

Lines changed: 57 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cumulus/parachains/runtimes/testing/penpal/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ primitive-types = { workspace = true, default-features = false, features = [
9090
"scale-info",
9191
] }
9292

93+
[dev-dependencies]
94+
sp-io = { workspace = true, default-features = true }
95+
9396
[build-dependencies]
9497
substrate-wasm-builder = { optional = true, workspace = true, default-features = true }
9598

cumulus/parachains/runtimes/testing/penpal/src/genesis_config_presets.rs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ fn penpal_parachain_genesis(
8181
assets: vec![
8282
(RelayLocation::get(), sudo.clone(), true, EXISTENTIAL_DEPOSIT),
8383
(LocalPen2Asset::get(), sudo.clone(), false, EXISTENTIAL_DEPOSIT),
84-
(UsdtFromAssetHub::get(), sudo.clone(), true, EXISTENTIAL_DEPOSIT),
85-
(EthFromEthereum::get(), sudo.clone(), true, EXISTENTIAL_DEPOSIT),
84+
(UsdtFromAssetHub::get(), sudo.clone(), true, USDT_ED),
85+
(EthFromEthereum::get(), sudo.clone(), true, ETHER_MIN_BALANCE),
8686
],
8787
metadata: vec![
8888
(
@@ -165,3 +165,44 @@ pub fn preset_names() -> Vec<PresetId> {
165165
pub fn penpal_session_keys(keys: AuraId) -> crate::SessionKeys {
166166
crate::SessionKeys { aura: keys }
167167
}
168+
169+
#[cfg(test)]
170+
mod tests {
171+
use super::*;
172+
173+
// Duplicated from `sc_chain_spec::json_patch::merge` which lives in a node-side crate
174+
// with heavy transitive deps (sc-executor, sc-network, etc.), making it unsuitable as a
175+
// dev-dependency for a runtime crate.
176+
fn merge(base: &mut serde_json::Value, patch: serde_json::Value) {
177+
match (base, patch) {
178+
(serde_json::Value::Object(base), serde_json::Value::Object(patch)) => {
179+
for (k, v) in patch {
180+
merge(base.entry(k).or_insert(serde_json::Value::Null), v);
181+
}
182+
},
183+
(base, patch) => *base = patch,
184+
}
185+
}
186+
187+
fn assert_genesis_preset_valid(preset_id: &sp_genesis_builder::PresetId) {
188+
let patch: serde_json::Value =
189+
serde_json::from_slice(&get_preset(preset_id).expect("preset exists")).unwrap();
190+
let mut config = serde_json::to_value(RuntimeGenesisConfig::default()).unwrap();
191+
merge(&mut config, patch);
192+
let json = serde_json::to_vec(&config).unwrap();
193+
sp_io::TestExternalities::default().execute_with(|| {
194+
frame_support::genesis_builder_helper::build_state::<RuntimeGenesisConfig>(json)
195+
.expect("genesis preset should build valid state");
196+
});
197+
}
198+
199+
#[test]
200+
fn dev_genesis_preset_is_valid() {
201+
assert_genesis_preset_valid(&sp_genesis_builder::DEV_RUNTIME_PRESET.into());
202+
}
203+
204+
#[test]
205+
fn local_testnet_genesis_preset_is_valid() {
206+
assert_genesis_preset_valid(&sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET.into());
207+
}
208+
}

prdoc/pr_11575.prdoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
title: '[Penpal] fix genesis presets - assign proper ED to accounts'''
2+
doc:
3+
- audience: Runtime Dev
4+
description: |-
5+
Penpal had values below the ED for initializing asset balances for some accounts. This has not been detected as no unit tests actually use the presets. This PR fixes the invalid values, and it also adds some unit tests for validating that the presets build at least.
6+
7+
Closes #11558.
8+
crates:
9+
- name: penpal-runtime
10+
bump: patch

0 commit comments

Comments
 (0)