Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request paritytech#266 from subspace/subspace-test-runtime…
Browse files Browse the repository at this point in the history
…-service

Introduce subspace-test-runtime and subspace-test-service
  • Loading branch information
liuchengxu authored Feb 21, 2022
2 parents 37ca628 + 3044cbe commit c41c2ce
Show file tree
Hide file tree
Showing 10 changed files with 1,833 additions and 1 deletion.
119 changes: 118 additions & 1 deletion Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ members = [
"polkadot/node/subsystem-types",
"polkadot/node/subsystem-util",
"substrate/*",
"test/subspace-test-client",
"test/subspace-test-runtime",
"test/subspace-test-service",
]

# The list of dependencies below (which can be both direct and indirect dependencies) are crates
Expand Down
36 changes: 36 additions & 0 deletions test/subspace-test-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[package]
name = "subspace-test-client"
version = "0.1.0"
authors = ["Subspace Labs <https://subspace.network>"]
edition = "2021"
license = "GPL-3.0-or-later"
homepage = "https://subspace.network"
repository = "https://github.com/subspace/subspace"
include = [
"/src",
"/Cargo.toml",
]

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
futures = "0.3.19"
rand = "0.8.3"
schnorrkel = "0.9.1"
sc-chain-spec = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" }
sc-client-api = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" }
sc-consensus-subspace = { version = "0.1.0", path = "../../crates/sc-consensus-subspace" }
sc-executor = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927", features = ["wasmtime"] }
sc-service = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927", features = ["wasmtime"] }
sp-api = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" }
sp-consensus-subspace = { version = "0.1.0", path = "../../crates/sp-consensus-subspace" }
sp-core = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" }
sp-runtime = { git = "https://github.com/paritytech/substrate", rev = "e6def65920d30029e42d498cb07cec5dd433b927" }
subspace-archiving = { path = "../../crates/subspace-archiving" }
subspace-core-primitives = { path = "../../crates/subspace-core-primitives" }
subspace-runtime-primitives = { path = "../../crates/subspace-runtime-primitives" }
subspace-service = { path = "../../crates/subspace-service" }
subspace-solving = { path = "../../crates/subspace-solving" }
subspace-test-runtime = { version = "0.1.0", features = ["do-not-enforce-cost-of-storage"], path = "../subspace-test-runtime" }
zeroize = "1.4.3"
88 changes: 88 additions & 0 deletions test/subspace-test-client/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//! Chain specification for the test runtime.
use sc_chain_spec::ChainType;
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};
use subspace_runtime_primitives::{AccountId, Balance, BlockNumber, Signature};
use subspace_test_runtime::{
BalancesConfig, GenesisConfig, SudoConfig, SystemConfig, VestingConfig, SSC, WASM_BINARY,
};

/// The `ChainSpec` parameterized for subspace test runtime.
pub type TestChainSpec = sc_service::GenericChainSpec<subspace_test_runtime::GenesisConfig>;

/// Generate a crypto pair from seed.
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public()
}

type AccountPublic = <Signature as Verify>::Signer;

/// Generate an account ID from seed.
pub fn get_account_id_from_seed(seed: &str) -> AccountId {
AccountPublic::from(get_from_seed::<sr25519::Public>(seed)).into_account()
}

/// Local testnet config (multivalidator Alice + Bob).
pub fn subspace_local_testnet_config() -> TestChainSpec {
let wasm_binary = WASM_BINARY.expect("Development wasm not available");
TestChainSpec::from_genesis(
"Local Testnet",
"local_testnet",
ChainType::Local,
|| {
create_genesis_config(
wasm_binary,
// Sudo account
get_account_id_from_seed("Alice"),
// Pre-funded accounts
vec![
(get_account_id_from_seed("Alice"), 1_000 * SSC),
(get_account_id_from_seed("Bob"), 1_000 * SSC),
(get_account_id_from_seed("Charlie"), 1_000 * SSC),
(get_account_id_from_seed("Dave"), 1_000 * SSC),
(get_account_id_from_seed("Eve"), 1_000 * SSC),
(get_account_id_from_seed("Ferdie"), 1_000 * SSC),
(get_account_id_from_seed("Alice//stash"), 1_000 * SSC),
(get_account_id_from_seed("Bob//stash"), 1_000 * SSC),
(get_account_id_from_seed("Charlie//stash"), 1_000 * SSC),
(get_account_id_from_seed("Dave//stash"), 1_000 * SSC),
(get_account_id_from_seed("Eve//stash"), 1_000 * SSC),
(get_account_id_from_seed("Ferdie//stash"), 1_000 * SSC),
],
vec![],
)
},
vec![],
None,
Some("subspace-test"),
None,
None,
Default::default(),
)
}

/// Configure initial storage state for FRAME modules.
fn create_genesis_config(
wasm_binary: &[u8],
sudo_account: AccountId,
balances: Vec<(AccountId, Balance)>,
// who, start, period, period_count, per_period
vesting: Vec<(AccountId, BlockNumber, BlockNumber, u32, Balance)>,
) -> GenesisConfig {
GenesisConfig {
system: SystemConfig {
// Add Wasm runtime to storage.
code: wasm_binary.to_vec(),
},
balances: BalancesConfig { balances },
transaction_payment: Default::default(),
sudo: SudoConfig {
// Assign network admin rights.
key: Some(sudo_account),
},
vesting: VestingConfig { vesting },
}
}
Loading

0 comments on commit c41c2ce

Please sign in to comment.