test-utils: add chain-spec-builder cli (#1061)

* test-utils: add chain-spec-builder cli

* style changes, mostly indentation

* fix padding

* add issue to todo

* more style fixes

* share seed padding with keystore

* fix master rebase error
This commit is contained in:
azban
2018-11-12 11:21:03 -08:00
committed by Gav Wood
parent 168de867f5
commit 367c99b2bb
11 changed files with 4116 additions and 56 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,10 @@
[package]
name = "chain-spec-builder"
version = "0.1.0"
authors = ["haydn dufrene <haydn.dufrene@gmail.com>"]
[dependencies]
clap = { version = "~2.32", features = ["yaml"] }
node-cli = { path = "../../node/cli" }
substrate-primitives = { path = "../../core/primitives" }
substrate-service = { path = "../../core/service" }
@@ -0,0 +1,24 @@
name: chain-spec-builder
author: "azban <me@azban.net>"
about: Utility for creating chain specs primarily for testing
args:
- initial_authority_seed:
short: a
value_name: INITIAL_AUTHORITY_SEED
help: Initial authority seed
takes_value: true
multiple: true
required: true
- endowed_account_seed:
short: e
value_name: ENDOWED_ACCOUNT_SEED
help: Endowed account seed
takes_value: true
multiple: true
required: true
- upgrade_key_seed:
short: u
value_name: UPGRADE_KEY_SEED
help: Upgrade key seed
takes_value: true
required: true
@@ -0,0 +1,51 @@
#[macro_use]
extern crate clap;
use clap::App;
extern crate node_cli;
extern crate substrate_service;
extern crate substrate_primitives;
use node_cli::chain_spec;
use substrate_service::chain_ops::build_spec;
fn genesis_constructor() -> chain_spec::GenesisConfig {
let yaml = load_yaml!("./cli.yml");
let matches = App::from_yaml(yaml).get_matches();
let authorities = matches.values_of("initial_authority_seed")
.unwrap()
.map(chain_spec::get_authority_id_from_seed)
.collect();
let endowed_accounts = matches.values_of("endowed_account_seed")
.unwrap()
.map(chain_spec::get_authority_id_from_seed)
.collect();
let upgrade_key_seed = matches.value_of("upgrade_key_seed").unwrap();
let upgrade_key = chain_spec::get_authority_id_from_seed(upgrade_key_seed);
chain_spec::testnet_genesis(
authorities,
upgrade_key.into(),
Some(endowed_accounts),
)
}
fn generate_chain_spec() -> String {
let chain_spec = chain_spec::ChainSpec::from_genesis(
"Custom",
"custom",
genesis_constructor,
vec![],
None,
None,
None,
);
build_spec(chain_spec, false).unwrap()
}
fn main() {
let json = generate_chain_spec();
println!("{}", json);
}