mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 20:27:58 +00:00
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:
@@ -18,16 +18,20 @@
|
||||
|
||||
use primitives::{AuthorityId, ed25519};
|
||||
use node_primitives::AccountId;
|
||||
use node_runtime::{GenesisConfig, ConsensusConfig, CouncilSeatsConfig, CouncilVotingConfig, DemocracyConfig,
|
||||
SessionConfig, StakingConfig, TimestampConfig, BalancesConfig, TreasuryConfig, UpgradeKeyConfig,
|
||||
ContractConfig, Permill, Perbill};
|
||||
use node_runtime::{ConsensusConfig, CouncilSeatsConfig, CouncilVotingConfig, DemocracyConfig,
|
||||
SessionConfig, StakingConfig, TimestampConfig, BalancesConfig, TreasuryConfig,
|
||||
UpgradeKeyConfig, ContractConfig, Permill, Perbill};
|
||||
pub use node_runtime::GenesisConfig;
|
||||
use substrate_service;
|
||||
|
||||
use substrate_keystore::pad_seed;
|
||||
|
||||
const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
|
||||
|
||||
/// Specialised `ChainSpec`.
|
||||
pub type ChainSpec = substrate_service::ChainSpec<GenesisConfig>;
|
||||
|
||||
/// BBQ birch testnet generator
|
||||
pub fn bbq_birch_config() -> Result<ChainSpec, String> {
|
||||
ChainSpec::from_embedded(include_bytes!("../res/bbq-birch.json"))
|
||||
}
|
||||
@@ -43,7 +47,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
hex!["f295940fa750df68a686fcf4abd4111c8a9c5a5a5a83c4c8639c451a94a7adfd"].into(),
|
||||
];
|
||||
const MILLICENTS: u128 = 1_000_000_000;
|
||||
const CENTS: u128 = 1_000 * MILLICENTS; // assume this is worth about a cent.
|
||||
const CENTS: u128 = 1_000 * MILLICENTS; // assume this is worth about a cent.
|
||||
const DOLLARS: u128 = 100 * CENTS;
|
||||
|
||||
const SECS_PER_BLOCK: u64 = 4;
|
||||
@@ -53,12 +57,12 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
|
||||
GenesisConfig {
|
||||
consensus: Some(ConsensusConfig {
|
||||
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm").to_vec(), // TODO change
|
||||
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm").to_vec(), // TODO change
|
||||
authorities: initial_authorities.clone(),
|
||||
}),
|
||||
system: None,
|
||||
balances: Some(BalancesConfig {
|
||||
balances: endowed_accounts.iter().map(|&k|(k, 10_000_000 * DOLLARS)).collect(),
|
||||
balances: endowed_accounts.iter().map(|&k| (k, 10_000_000 * DOLLARS)).collect(),
|
||||
transaction_base_fee: 1 * CENTS,
|
||||
transaction_byte_fee: 10 * MILLICENTS,
|
||||
existential_deposit: 1 * DOLLARS,
|
||||
@@ -68,7 +72,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
}),
|
||||
session: Some(SessionConfig {
|
||||
validators: initial_authorities.iter().cloned().map(Into::into).collect(),
|
||||
session_length: 5 * MINUTES
|
||||
session_length: 5 * MINUTES,
|
||||
}),
|
||||
staking: Some(StakingConfig {
|
||||
current_era: 0,
|
||||
@@ -84,9 +88,9 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
minimum_validator_count: 4,
|
||||
}),
|
||||
democracy: Some(DemocracyConfig {
|
||||
launch_period: 5 * MINUTES, // 1 day per public referendum
|
||||
voting_period: 5 * MINUTES, // 3 days to discuss & vote on an active referendum
|
||||
minimum_deposit: 50 * DOLLARS, // 12000 as the minimum deposit for a referendum
|
||||
launch_period: 5 * MINUTES, // 1 day per public referendum
|
||||
voting_period: 5 * MINUTES, // 3 days to discuss & vote on an active referendum
|
||||
minimum_deposit: 50 * DOLLARS, // 12000 as the minimum deposit for a referendum
|
||||
}),
|
||||
council_seats: Some(CouncilSeatsConfig {
|
||||
active_council: vec![],
|
||||
@@ -98,8 +102,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
approval_voting_period: 2 * DAYS,
|
||||
term_duration: 28 * DAYS,
|
||||
desired_seats: 0,
|
||||
inactive_grace_period: 1, // one additional vote should go by before an inactive voter can be reaped.
|
||||
|
||||
inactive_grace_period: 1, // one additional vote should go by before an inactive voter can be reaped.
|
||||
}),
|
||||
council_voting: Some(CouncilVotingConfig {
|
||||
cooloff_period: 4 * DAYS,
|
||||
@@ -130,8 +133,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
|
||||
/// Staging testnet config.
|
||||
pub fn staging_testnet_config() -> ChainSpec {
|
||||
let boot_nodes = vec![
|
||||
];
|
||||
let boot_nodes = vec![];
|
||||
ChainSpec::from_genesis(
|
||||
"Staging Testnet",
|
||||
"staging_testnet",
|
||||
@@ -144,15 +146,30 @@ pub fn staging_testnet_config() -> ChainSpec {
|
||||
)
|
||||
}
|
||||
|
||||
fn testnet_genesis(initial_authorities: Vec<AuthorityId>, upgrade_key: AccountId) -> GenesisConfig {
|
||||
let endowed_accounts = vec![
|
||||
ed25519::Pair::from_seed(b"Alice ").public().0.into(),
|
||||
ed25519::Pair::from_seed(b"Bob ").public().0.into(),
|
||||
ed25519::Pair::from_seed(b"Charlie ").public().0.into(),
|
||||
ed25519::Pair::from_seed(b"Dave ").public().0.into(),
|
||||
ed25519::Pair::from_seed(b"Eve ").public().0.into(),
|
||||
ed25519::Pair::from_seed(b"Ferdie ").public().0.into(),
|
||||
];
|
||||
/// Helper function to generate AuthorityID from seed
|
||||
pub fn get_authority_id_from_seed(seed: &str) -> AuthorityId {
|
||||
let padded_seed = pad_seed(seed);
|
||||
// NOTE from ed25519 impl:
|
||||
// prefer pkcs#8 unless security doesn't matter -- this is used primarily for tests.
|
||||
ed25519::Pair::from_seed(&padded_seed).public().0.into()
|
||||
}
|
||||
|
||||
/// Helper function to create GenesisConfig for testing
|
||||
pub fn testnet_genesis(
|
||||
initial_authorities: Vec<AuthorityId>,
|
||||
upgrade_key: AccountId,
|
||||
endowed_accounts: Option<Vec<AuthorityId>>,
|
||||
) -> GenesisConfig {
|
||||
let endowed_accounts = endowed_accounts.unwrap_or_else(|| {
|
||||
vec![
|
||||
get_authority_id_from_seed("Alice"),
|
||||
get_authority_id_from_seed("Bob"),
|
||||
get_authority_id_from_seed("Charlie"),
|
||||
get_authority_id_from_seed("Dave"),
|
||||
get_authority_id_from_seed("Eve"),
|
||||
get_authority_id_from_seed("Ferdie"),
|
||||
]
|
||||
});
|
||||
GenesisConfig {
|
||||
consensus: Some(ConsensusConfig {
|
||||
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm").to_vec(),
|
||||
@@ -166,7 +183,7 @@ fn testnet_genesis(initial_authorities: Vec<AuthorityId>, upgrade_key: AccountId
|
||||
transfer_fee: 0,
|
||||
creation_fee: 0,
|
||||
reclaim_rebate: 0,
|
||||
balances: endowed_accounts.iter().map(|&k|(k, (1 << 60))).collect(),
|
||||
balances: endowed_accounts.iter().map(|&k| (k.into(), (1 << 60))).collect(),
|
||||
}),
|
||||
session: Some(SessionConfig {
|
||||
validators: initial_authorities.iter().cloned().map(Into::into).collect(),
|
||||
@@ -192,8 +209,8 @@ fn testnet_genesis(initial_authorities: Vec<AuthorityId>, upgrade_key: AccountId
|
||||
}),
|
||||
council_seats: Some(CouncilSeatsConfig {
|
||||
active_council: endowed_accounts.iter()
|
||||
.filter(|a| initial_authorities.iter().find(|&b| a.as_bytes() == b.0).is_none())
|
||||
.map(|a| (a.clone(), 1000000)).collect(),
|
||||
.filter(|a| initial_authorities.iter().find(|&b| a.0 == b.0).is_none())
|
||||
.map(|a| (a.clone().into(), 1000000)).collect(),
|
||||
candidacy_bond: 10,
|
||||
voter_bond: 2,
|
||||
present_slash_per_voter: 1,
|
||||
@@ -209,7 +226,7 @@ fn testnet_genesis(initial_authorities: Vec<AuthorityId>, upgrade_key: AccountId
|
||||
voting_period: 20,
|
||||
}),
|
||||
timestamp: Some(TimestampConfig {
|
||||
period: 5, // 5 second block time.
|
||||
period: 5, // 5 second block time.
|
||||
}),
|
||||
treasury: Some(TreasuryConfig {
|
||||
proposal_bond: Permill::from_percent(5),
|
||||
@@ -232,10 +249,12 @@ fn testnet_genesis(initial_authorities: Vec<AuthorityId>, upgrade_key: AccountId
|
||||
}
|
||||
|
||||
fn development_config_genesis() -> GenesisConfig {
|
||||
testnet_genesis(vec![
|
||||
ed25519::Pair::from_seed(b"Alice ").public().into(),
|
||||
],
|
||||
ed25519::Pair::from_seed(b"Alice ").public().0.into()
|
||||
testnet_genesis(
|
||||
vec![
|
||||
get_authority_id_from_seed("Alice"),
|
||||
],
|
||||
get_authority_id_from_seed("Alice").into(),
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -245,11 +264,13 @@ pub fn development_config() -> ChainSpec {
|
||||
}
|
||||
|
||||
fn local_testnet_genesis() -> GenesisConfig {
|
||||
testnet_genesis(vec![
|
||||
ed25519::Pair::from_seed(b"Alice ").public().into(),
|
||||
ed25519::Pair::from_seed(b"Bob ").public().into(),
|
||||
],
|
||||
ed25519::Pair::from_seed(b"Alice ").public().0.into()
|
||||
testnet_genesis(
|
||||
vec![
|
||||
get_authority_id_from_seed("Alice"),
|
||||
get_authority_id_from_seed("Bob"),
|
||||
],
|
||||
get_authority_id_from_seed("Alice").into(),
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -276,7 +297,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_connectivity() {
|
||||
fn test_connectiviy() {
|
||||
service_test::connectivity::<Factory>(integration_test_config());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,12 +37,13 @@ extern crate node_primitives;
|
||||
#[macro_use]
|
||||
extern crate substrate_service;
|
||||
extern crate node_executor;
|
||||
extern crate substrate_keystore;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
pub use cli::error;
|
||||
mod chain_spec;
|
||||
pub mod chain_spec;
|
||||
mod service;
|
||||
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
Reference in New Issue
Block a user