Skip to content

Commit

Permalink
Add new spec file Change tests dir to runtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
EleisonC committed Nov 29, 2024
1 parent 419a9d8 commit 6197599
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion templates/minimal/dev_chain_spec.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions templates/minimal/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ build = "build.rs"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { features = ["derive"], workspace = true }
docify = { workspace = true }
clap = { features = ["derive"], workspace = true }
futures = { features = ["thread-pool"], workspace = true }
futures-timer = { workspace = true }
serde = { features = ["derive"], workspace = true, default-features = true }
jsonrpsee = { features = ["server"], workspace = true }
serde_json = { workspace = true, default-features = true }

Expand Down
7 changes: 6 additions & 1 deletion templates/minimal/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition.workspace = true
publish = false

[dependencies]
codec = { workspace = true }
codec = { features = ["derive"], workspace = true }
scale-info = { workspace = true }
polkadot-sdk = { workspace = true, features = [
"pallet-balances",
Expand All @@ -25,6 +25,11 @@ serde_json = { workspace = true, default-features = false, features = ["alloc"]
# local pallet templates
pallet-minimal-template = { workspace = true }

[dev-dependencies]
serde = { features = ["derive"], workspace = true, default-features = true }
sc-service = { workspace = true }
sc-chain-spec = { workspace = true }

[build-dependencies]
polkadot-sdk = { optional = true, workspace = true, features = [
"substrate-wasm-builder",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use serde::{Deserialize, Serialize};
use serde_json::Value;
use core::str;
use std::error::Error;
use std::io::BufReader;

pub type ChainSpec = sc_service::GenericChainSpec<Extensions>;

Expand All @@ -29,13 +30,10 @@ impl Extensions {
}
}

fn decode_runtime_info(ch_spec_data: &ChainSpec) ->
Result<(String, u32, u32), Box<dyn Error>> {
let chain_spec_as_json = ch_spec_data.as_json(false)
.expect("Failed to serialize existing chain spec");
let json_value: Value = serde_json::from_str(&chain_spec_as_json)?; // Deserialize the chain spec JSON string into a usable serde_Json Value object.

let runtime_hx_cde = json_value
fn decode_runtime_info(spec_data: Value) ->
Result<(String, u32, u32), Box<dyn Error>> {
let runtime_hx_cde = spec_data
.get("genesis").expect("failed to get genesis")
.get("runtimeGenesis").expect("failed to get runtimeGenesis")
.get("code").expect("failed to get code")
Expand Down Expand Up @@ -72,13 +70,18 @@ fn test_minimal_dev_chain_spec_rt_validity() {
.with_properties(properties.clone())
.build()
.as_json(false)
.unwrap()
.as_str()
).unwrap();

let existing_chain_spec_file =
let existing_chain_spec_file =
std::fs::File::open("../dev_chain_spec.json").expect("file should open. qed");
let existing_chain_spec_reader = BufReader::new(existing_chain_spec_file);
let existing_chain_spec: serde_json::Value =
serde_json::from_reader(existing_chain_spec_reader).expect("should read proper JSON. qed");
assert_eq!(test_chain_spec, existing_chain_spec);

let data1 = decode_runtime_info(existing_chain_spec).unwrap();
let data2 = decode_runtime_info(test_chain_spec).unwrap();
assert_eq!(data1, data2);
}

0 comments on commit 6197599

Please sign in to comment.