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

polkadot-sdk-docs: Use command_macro! #6624

Merged
merged 40 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5cde862
First try
ndkazu Nov 23, 2024
0220768
Update generate_chain_spec_builder_path()
ndkazu Nov 24, 2024
683c7ab
using cmd_lib
ndkazu Nov 26, 2024
ce8e506
using cmd_lib
ndkazu Nov 26, 2024
2432a09
Tracking output
ndkazu Nov 26, 2024
b2e4e18
Merge branch 'master' into commandMacro
ndkazu Nov 26, 2024
39709b7
Applied suggested corrections
ndkazu Nov 26, 2024
6702a0d
correction
ndkazu Nov 26, 2024
888e375
Merge branch 'master' into commandMacro
ndkazu Nov 26, 2024
aefaf7f
removed process::Command from chain_spec_builder_tests.rs
ndkazu Nov 27, 2024
b204240
Removed unused import
ndkazu Nov 27, 2024
5138c27
Added newm macro
ndkazu Nov 28, 2024
af8c282
prdoc
ndkazu Nov 28, 2024
fe6deeb
Merge branch 'master' into commandMacro
ndkazu Nov 28, 2024
b90d36f
prdoc crates
ndkazu Nov 28, 2024
b29fce3
prdoc crates
ndkazu Nov 28, 2024
7ffc46b
prdoc crates
ndkazu Nov 28, 2024
848e69e
Fix wrong variable name
ndkazu Nov 28, 2024
78979ce
cargo fmt
ndkazu Nov 28, 2024
a96f5f8
Re-factored code according to review/comment
ndkazu Nov 28, 2024
d19ef82
cargo fmt
ndkazu Nov 28, 2024
b5deedb
Merge branch 'master' into commandMacro
ndkazu Nov 28, 2024
c0cff49
Update chain_spec_genesis
ndkazu Nov 28, 2024
a198802
Remove unneeded mut
ndkazu Nov 28, 2024
5dec756
Merge branch 'master' into commandMacro
ndkazu Nov 28, 2024
968a976
Code refactoring based on latest reviews
ndkazu Nov 28, 2024
2010b5f
Merge branch 'master' into commandMacro
ndkazu Nov 28, 2024
45f13bd
use #[docify::export_content]
ndkazu Nov 28, 2024
e641369
Merge branch 'master' into commandMacro
ndkazu Nov 29, 2024
5322d97
Merge branch 'master' into commandMacro
ndkazu Nov 29, 2024
d37c68e
Prdoc & variable name correction
ndkazu Nov 29, 2024
7bf9544
Merge branch 'master' into commandMacro
ndkazu Nov 29, 2024
18f87be
variable name
ndkazu Nov 29, 2024
262529c
Merge branch 'master' into commandMacro
ndkazu Nov 29, 2024
68ed1b6
Merge branch 'master' into commandMacro
ndkazu Nov 30, 2024
7f1a4eb
Merge branch 'master' into commandMacro
ndkazu Dec 2, 2024
9a6c956
Merge branch 'master' into commandMacro
iulianbarbu Dec 4, 2024
ee088d4
removed quotes
ndkazu Dec 7, 2024
3fc927c
Merge branch 'commandMacro' of github.com:ndkazu/polkadot-sdk into co…
ndkazu Dec 7, 2024
4ce23e2
Merge branch 'master' into commandMacro
ndkazu Dec 7, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions docs/sdk/src/reference_docs/chain_spec_runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ substrate-wasm-builder = { optional = true, workspace = true, default-features =

[dev-dependencies]
chain-spec-builder = { workspace = true, default-features = true }
cmd_lib.workspace = true
ndkazu marked this conversation as resolved.
Show resolved Hide resolved
sc-chain-spec = { workspace = true, default-features = true }

[features]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
use serde_json::{json, Value};
use std::{process::Command, str};
use cmd_lib::*;

const WASM_FILE_PATH: &str =
"../../../../../target/release/wbuild/chain-spec-guide-runtime/chain_spec_guide_runtime.wasm";

const CHAIN_SPEC_BUILDER_PATH: &str = "../../../../../target/release/chain-spec-builder";

macro_rules! bash(
( chain-spec-builder $($a:tt)* ) => {{
let path = get_chain_spec_builder_path();
spawn_with_output!(
$path $($a)*
)
.expect("a process running. qed")
.wait_with_output()
.expect("to get output. qed.")
}}
);

fn get_chain_spec_builder_path() -> &'static str {
// dev-dependencies do not build binary. So let's do the naive work-around here:
let _ = std::process::Command::new("cargo")
.arg("build")
.arg("--release")
.arg("-p")
.arg("staging-chain-spec-builder")
.arg("--bin")
.arg("chain-spec-builder")
.status()
.expect("Failed to execute command");
run_cmd!(
cargo build --release -p staging-chain-spec-builder --bin chain-spec-builder
).expect("Failed to execute command");
CHAIN_SPEC_BUILDER_PATH
}

#[test]
#[docify::export]
fn list_presets() {
let output = Command::new(get_chain_spec_builder_path())
.arg("list-presets")
.arg("-r")
.arg(WASM_FILE_PATH)
.output()
.expect("Failed to execute command");

let output: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();
let output = bash!(
chain-spec-builder list-presets -r $WASM_FILE_PATH
);

let mut output: serde_json::Value = serde_json::from_slice(&output.as_bytes()).unwrap();
let expected_output = json!({
"presets":[
"preset_1",
Expand All @@ -47,17 +49,11 @@ fn list_presets() {
#[test]
#[docify::export]
fn get_preset() {
let output = Command::new(get_chain_spec_builder_path())
.arg("display-preset")
.arg("-r")
.arg(WASM_FILE_PATH)
.arg("-p")
.arg("preset_2")
.output()
.expect("Failed to execute command");

let output: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();
let output = bash!(
chain-spec-builder display-preset -r $WASM_FILE_PATH -p preset_2
);

let mut output: serde_json::Value = serde_json::from_slice(&output.as_bytes()).unwrap();
//note: copy of chain_spec_guide_runtime::preset_2
let expected_output = json!({
"bar": {
Expand Down Expand Up @@ -88,9 +84,8 @@ fn generate_chain_spec() {
.arg("preset_2")
.output()
.expect("Failed to execute command");

println!("Expected: {:?}", output.stdout);
ndkazu marked this conversation as resolved.
Show resolved Hide resolved
let mut output: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();

//remove code field for better readability
if let Some(code) = output["genesis"]["runtimeGenesis"].as_object_mut().unwrap().get_mut("code")
{
Expand Down Expand Up @@ -131,23 +126,11 @@ fn generate_chain_spec() {
#[test]
#[docify::export]
fn generate_para_chain_spec() {
let output = Command::new(get_chain_spec_builder_path())
.arg("-c")
.arg("/dev/stdout")
.arg("create")
.arg("-c")
.arg("polkadot")
.arg("-p")
.arg("1000")
.arg("-r")
.arg(WASM_FILE_PATH)
.arg("named-preset")
.arg("preset_2")
.output()
.expect("Failed to execute command");

let mut output: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();

let output = bash!(
chain-spec-builder -c /dev/stdout create -c polkadot -p 1000 -r WASM_FILE_PATH named-preset preset_2
ndkazu marked this conversation as resolved.
Show resolved Hide resolved
);
let mut output: serde_json::Value = serde_json::from_slice(&output.as_bytes()).unwrap();
//remove code field for better readability
if let Some(code) = output["genesis"]["runtimeGenesis"].as_object_mut().unwrap().get_mut("code")
{
Expand Down
Loading