mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 06:27:58 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -22,44 +22,42 @@
|
||||
//! can pregenerate seed database and `clone` it for every iteration of your benchmarks
|
||||
//! or tests to get consistent, smooth benchmark experience!
|
||||
|
||||
use std::{sync::Arc, path::{Path, PathBuf}, collections::BTreeMap};
|
||||
|
||||
use node_primitives::Block;
|
||||
use crate::client::{Client, Backend};
|
||||
use crate::keyring::*;
|
||||
use sc_client_db::PruningMode;
|
||||
use sc_executor::{NativeExecutor, WasmExecutionMethod};
|
||||
use sp_consensus::{
|
||||
BlockOrigin, BlockImport, BlockImportParams,
|
||||
ForkChoiceStrategy, ImportResult, ImportedAux
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
OpaqueExtrinsic,
|
||||
traits::{Block as BlockT, Verify, Zero, IdentifyAccount},
|
||||
|
||||
use crate::{
|
||||
client::{Backend, Client},
|
||||
keyring::*,
|
||||
};
|
||||
use codec::{Decode, Encode};
|
||||
use futures::executor;
|
||||
use node_primitives::Block;
|
||||
use node_runtime::{
|
||||
Call,
|
||||
CheckedExtrinsic,
|
||||
constants::currency::DOLLARS,
|
||||
UncheckedExtrinsic,
|
||||
MinimumPeriod,
|
||||
SystemCall,
|
||||
BalancesCall,
|
||||
AccountId,
|
||||
Signature,
|
||||
};
|
||||
use sp_core::{ExecutionContext, blake2_256, traits::SpawnNamed, Pair, Public, sr25519, ed25519};
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use sp_block_builder::BlockBuilder;
|
||||
use sp_inherents::InherentData;
|
||||
use sc_client_api::{
|
||||
ExecutionStrategy, BlockBackend,
|
||||
execution_extensions::{ExecutionExtensions, ExecutionStrategies},
|
||||
constants::currency::DOLLARS, AccountId, BalancesCall, Call, CheckedExtrinsic, MinimumPeriod,
|
||||
Signature, SystemCall, UncheckedExtrinsic,
|
||||
};
|
||||
use sc_block_builder::BlockBuilderProvider;
|
||||
use futures::executor;
|
||||
use sc_client_api::{
|
||||
execution_extensions::{ExecutionExtensions, ExecutionStrategies},
|
||||
BlockBackend, ExecutionStrategy,
|
||||
};
|
||||
use sc_client_db::PruningMode;
|
||||
use sc_executor::{NativeExecutor, WasmExecutionMethod};
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use sp_block_builder::BlockBuilder;
|
||||
use sp_consensus::{
|
||||
BlockImport, BlockImportParams, BlockOrigin, ForkChoiceStrategy, ImportResult, ImportedAux,
|
||||
};
|
||||
use sp_core::{blake2_256, ed25519, sr25519, traits::SpawnNamed, ExecutionContext, Pair, Public};
|
||||
use sp_inherents::InherentData;
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::{Block as BlockT, IdentifyAccount, Verify, Zero},
|
||||
OpaqueExtrinsic,
|
||||
};
|
||||
|
||||
/// Keyring full of accounts for benching.
|
||||
///
|
||||
@@ -92,19 +90,21 @@ impl BenchPair {
|
||||
///
|
||||
/// Will panic if cache drop is impossbile.
|
||||
pub fn drop_system_cache() {
|
||||
#[cfg(target_os = "windows")] {
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
log::warn!(
|
||||
target: "bench-logistics",
|
||||
"Clearing system cache on windows is not supported. Benchmark might totally be wrong.",
|
||||
);
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
std::process::Command::new("sync")
|
||||
.output()
|
||||
.expect("Failed to execute system cache clear");
|
||||
|
||||
#[cfg(target_os = "linux")] {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
log::trace!(target: "bench-logistics", "Clearing system cache...");
|
||||
std::process::Command::new("echo")
|
||||
.args(&["3", ">", "/proc/sys/vm/drop_caches", "2>", "/dev/null"])
|
||||
@@ -133,7 +133,8 @@ pub fn drop_system_cache() {
|
||||
log::trace!(target: "bench-logistics", "Clearing system cache done!");
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")] {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
log::trace!(target: "bench-logistics", "Clearing system cache...");
|
||||
if let Err(err) = std::process::Command::new("purge").output() {
|
||||
log::error!("purge error {:?}: ", err);
|
||||
@@ -169,15 +170,10 @@ impl Clone for BenchDb {
|
||||
);
|
||||
let seed_db_files = std::fs::read_dir(seed_dir)
|
||||
.expect("failed to list file in seed dir")
|
||||
.map(|f_result|
|
||||
f_result.expect("failed to read file in seed db")
|
||||
.path()
|
||||
).collect::<Vec<PathBuf>>();
|
||||
fs_extra::copy_items(
|
||||
&seed_db_files,
|
||||
dir.path(),
|
||||
&fs_extra::dir::CopyOptions::new(),
|
||||
).expect("Copy of seed database is ok");
|
||||
.map(|f_result| f_result.expect("failed to read file in seed db").path())
|
||||
.collect::<Vec<PathBuf>>();
|
||||
fs_extra::copy_items(&seed_db_files, dir.path(), &fs_extra::dir::CopyOptions::new())
|
||||
.expect("Copy of seed database is ok");
|
||||
|
||||
// We clear system cache after db clone but before any warmups.
|
||||
// This populates system cache with some data unrelated to actual
|
||||
@@ -204,10 +200,7 @@ pub enum BlockType {
|
||||
impl BlockType {
|
||||
/// Create block content description with specified number of transactions.
|
||||
pub fn to_content(self, size: Option<usize>) -> BlockContent {
|
||||
BlockContent {
|
||||
block_type: self,
|
||||
size,
|
||||
}
|
||||
BlockContent { block_type: self, size }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,13 +223,8 @@ pub enum DatabaseType {
|
||||
impl DatabaseType {
|
||||
fn into_settings(self, path: PathBuf) -> sc_client_db::DatabaseSettingsSrc {
|
||||
match self {
|
||||
Self::RocksDb => sc_client_db::DatabaseSettingsSrc::RocksDb {
|
||||
path,
|
||||
cache_size: 512,
|
||||
},
|
||||
Self::ParityDb => sc_client_db::DatabaseSettingsSrc::ParityDb {
|
||||
path,
|
||||
}
|
||||
Self::RocksDb => sc_client_db::DatabaseSettingsSrc::RocksDb { path, cache_size: 512 },
|
||||
Self::ParityDb => sc_client_db::DatabaseSettingsSrc::ParityDb { path },
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -251,10 +239,7 @@ pub struct TaskExecutor {
|
||||
|
||||
impl TaskExecutor {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
pool: executor::ThreadPool::new()
|
||||
.expect("Failed to create task executor")
|
||||
}
|
||||
Self { pool: executor::ThreadPool::new().expect("Failed to create task executor") }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,21 +264,17 @@ pub struct BlockContentIterator<'a> {
|
||||
|
||||
impl<'a> BlockContentIterator<'a> {
|
||||
fn new(content: BlockContent, keyring: &'a BenchKeyring, client: &Client) -> Self {
|
||||
let runtime_version = client.runtime_version_at(&BlockId::number(0))
|
||||
let runtime_version = client
|
||||
.runtime_version_at(&BlockId::number(0))
|
||||
.expect("There should be runtime version at 0");
|
||||
|
||||
let genesis_hash = client.block_hash(Zero::zero())
|
||||
let genesis_hash = client
|
||||
.block_hash(Zero::zero())
|
||||
.expect("Database error?")
|
||||
.expect("Genesis block always exists; qed")
|
||||
.into();
|
||||
|
||||
BlockContentIterator {
|
||||
iteration: 0,
|
||||
content,
|
||||
keyring,
|
||||
runtime_version,
|
||||
genesis_hash,
|
||||
}
|
||||
BlockContentIterator { iteration: 0, content, keyring, runtime_version, genesis_hash }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,41 +283,36 @@ impl<'a> Iterator for BlockContentIterator<'a> {
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.content.size.map(|size| size <= self.iteration).unwrap_or(false) {
|
||||
return None;
|
||||
return None
|
||||
}
|
||||
|
||||
let sender = self.keyring.at(self.iteration);
|
||||
let receiver = get_account_id_from_seed::<sr25519::Public>(
|
||||
&format!("random-user//{}", self.iteration)
|
||||
);
|
||||
let receiver = get_account_id_from_seed::<sr25519::Public>(&format!(
|
||||
"random-user//{}",
|
||||
self.iteration
|
||||
));
|
||||
|
||||
let signed = self.keyring.sign(
|
||||
CheckedExtrinsic {
|
||||
signed: Some((sender, signed_extra(0, node_runtime::ExistentialDeposit::get() + 1))),
|
||||
signed: Some((
|
||||
sender,
|
||||
signed_extra(0, node_runtime::ExistentialDeposit::get() + 1),
|
||||
)),
|
||||
function: match self.content.block_type {
|
||||
BlockType::RandomTransfersKeepAlive => {
|
||||
Call::Balances(
|
||||
BalancesCall::transfer_keep_alive(
|
||||
sp_runtime::MultiAddress::Id(receiver),
|
||||
node_runtime::ExistentialDeposit::get() + 1,
|
||||
)
|
||||
)
|
||||
},
|
||||
BlockType::RandomTransfersKeepAlive =>
|
||||
Call::Balances(BalancesCall::transfer_keep_alive(
|
||||
sp_runtime::MultiAddress::Id(receiver),
|
||||
node_runtime::ExistentialDeposit::get() + 1,
|
||||
)),
|
||||
BlockType::RandomTransfersReaping => {
|
||||
Call::Balances(
|
||||
BalancesCall::transfer(
|
||||
sp_runtime::MultiAddress::Id(receiver),
|
||||
// Transfer so that ending balance would be 1 less than existential deposit
|
||||
// so that we kill the sender account.
|
||||
100*DOLLARS - (node_runtime::ExistentialDeposit::get() - 1),
|
||||
)
|
||||
)
|
||||
},
|
||||
BlockType::Noop => {
|
||||
Call::System(
|
||||
SystemCall::remark(Vec::new())
|
||||
)
|
||||
Call::Balances(BalancesCall::transfer(
|
||||
sp_runtime::MultiAddress::Id(receiver),
|
||||
// Transfer so that ending balance would be 1 less than existential deposit
|
||||
// so that we kill the sender account.
|
||||
100 * DOLLARS - (node_runtime::ExistentialDeposit::get() - 1),
|
||||
))
|
||||
},
|
||||
BlockType::Noop => Call::System(SystemCall::remark(Vec::new())),
|
||||
},
|
||||
},
|
||||
self.runtime_version.spec_version,
|
||||
@@ -346,8 +322,7 @@ impl<'a> Iterator for BlockContentIterator<'a> {
|
||||
|
||||
let encoded = Encode::encode(&signed);
|
||||
|
||||
let opaque = OpaqueExtrinsic::decode(&mut &encoded[..])
|
||||
.expect("Failed to decode opaque");
|
||||
let opaque = OpaqueExtrinsic::decode(&mut &encoded[..]).expect("Failed to decode opaque");
|
||||
|
||||
self.iteration += 1;
|
||||
|
||||
@@ -373,12 +348,8 @@ impl BenchDb {
|
||||
"Created seed db at {}",
|
||||
dir.path().to_string_lossy(),
|
||||
);
|
||||
let (_client, _backend, _task_executor) = Self::bench_client(
|
||||
database_type,
|
||||
dir.path(),
|
||||
Profile::Native,
|
||||
&keyring,
|
||||
);
|
||||
let (_client, _backend, _task_executor) =
|
||||
Self::bench_client(database_type, dir.path(), Profile::Native, &keyring);
|
||||
let directory_guard = Guard(dir);
|
||||
|
||||
BenchDb { keyring, directory_guard, database_type }
|
||||
@@ -408,7 +379,7 @@ impl BenchDb {
|
||||
keyring: &BenchKeyring,
|
||||
) -> (Client, std::sync::Arc<Backend>, TaskExecutor) {
|
||||
let db_config = sc_client_db::DatabaseSettings {
|
||||
state_cache_size: 16*1024*1024,
|
||||
state_cache_size: 16 * 1024 * 1024,
|
||||
state_cache_child_ratio: Some((0, 100)),
|
||||
state_pruning: PruningMode::ArchiveAll,
|
||||
source: database_type.into_settings(dir.into()),
|
||||
@@ -429,7 +400,8 @@ impl BenchDb {
|
||||
None,
|
||||
None,
|
||||
Default::default(),
|
||||
).expect("Should not fail");
|
||||
)
|
||||
.expect("Should not fail");
|
||||
|
||||
(client, backend, task_executor)
|
||||
}
|
||||
@@ -445,12 +417,14 @@ impl BenchDb {
|
||||
.put_data(sp_timestamp::INHERENT_IDENTIFIER, ×tamp)
|
||||
.expect("Put timestamp failed");
|
||||
|
||||
client.runtime_api()
|
||||
client
|
||||
.runtime_api()
|
||||
.inherent_extrinsics_with_context(
|
||||
&BlockId::number(0),
|
||||
ExecutionContext::BlockConstruction,
|
||||
inherent_data,
|
||||
).expect("Get inherents failed")
|
||||
)
|
||||
.expect("Get inherents failed")
|
||||
}
|
||||
|
||||
/// Iterate over some block content with transaction signed using this database keyring.
|
||||
@@ -474,9 +448,7 @@ impl BenchDb {
|
||||
pub fn generate_block(&mut self, content: BlockContent) -> Block {
|
||||
let client = self.client();
|
||||
|
||||
let mut block = client
|
||||
.new_block(Default::default())
|
||||
.expect("Block creation failed");
|
||||
let mut block = client.new_block(Default::default()).expect("Block creation failed");
|
||||
|
||||
for extrinsic in self.generate_inherents(&client) {
|
||||
block.push(extrinsic).expect("Push inherent failed");
|
||||
@@ -486,14 +458,12 @@ impl BenchDb {
|
||||
for opaque in self.block_content(content, &client) {
|
||||
match block.push(opaque) {
|
||||
Err(sp_blockchain::Error::ApplyExtrinsicFailed(
|
||||
sp_blockchain::ApplyExtrinsicFailed::Validity(e)
|
||||
)) if e.exhausted_resources() => {
|
||||
break;
|
||||
},
|
||||
sp_blockchain::ApplyExtrinsicFailed::Validity(e),
|
||||
)) if e.exhausted_resources() => break,
|
||||
Err(err) => panic!("Error pushing transaction: {:?}", err),
|
||||
Ok(_) => {},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let block = block.build().expect("Block build failed").block;
|
||||
|
||||
@@ -514,12 +484,8 @@ impl BenchDb {
|
||||
/// Clone this database and create context for testing/benchmarking.
|
||||
pub fn create_context(&self, profile: Profile) -> BenchContext {
|
||||
let BenchDb { directory_guard, keyring, database_type } = self.clone();
|
||||
let (client, backend, task_executor) = Self::bench_client(
|
||||
database_type,
|
||||
directory_guard.path(),
|
||||
profile,
|
||||
&keyring
|
||||
);
|
||||
let (client, backend, task_executor) =
|
||||
Self::bench_client(database_type, directory_guard.path(), profile, &keyring);
|
||||
|
||||
BenchContext {
|
||||
client: Arc::new(client),
|
||||
@@ -549,7 +515,8 @@ impl BenchKeyring {
|
||||
let seed = format!("//endowed-user/{}", n);
|
||||
let (account_id, pair) = match key_types {
|
||||
KeyTypes::Sr25519 => {
|
||||
let pair = sr25519::Pair::from_string(&seed, None).expect("failed to generate pair");
|
||||
let pair =
|
||||
sr25519::Pair::from_string(&seed, None).expect("failed to generate pair");
|
||||
let account_id = AccountPublic::from(pair.public()).into_account();
|
||||
(account_id, BenchPair::Sr25519(pair))
|
||||
},
|
||||
@@ -581,28 +548,34 @@ impl BenchKeyring {
|
||||
xt: CheckedExtrinsic,
|
||||
spec_version: u32,
|
||||
tx_version: u32,
|
||||
genesis_hash: [u8; 32]
|
||||
genesis_hash: [u8; 32],
|
||||
) -> UncheckedExtrinsic {
|
||||
match xt.signed {
|
||||
Some((signed, extra)) => {
|
||||
let payload = (xt.function, extra.clone(), spec_version, tx_version, genesis_hash, genesis_hash);
|
||||
let payload = (
|
||||
xt.function,
|
||||
extra.clone(),
|
||||
spec_version,
|
||||
tx_version,
|
||||
genesis_hash,
|
||||
genesis_hash,
|
||||
);
|
||||
let key = self.accounts.get(&signed).expect("Account id not found in keyring");
|
||||
let signature = payload.using_encoded(|b| {
|
||||
if b.len() > 256 {
|
||||
key.sign(&sp_io::hashing::blake2_256(b))
|
||||
} else {
|
||||
key.sign(b)
|
||||
}
|
||||
}).into();
|
||||
let signature = payload
|
||||
.using_encoded(|b| {
|
||||
if b.len() > 256 {
|
||||
key.sign(&sp_io::hashing::blake2_256(b))
|
||||
} else {
|
||||
key.sign(b)
|
||||
}
|
||||
})
|
||||
.into();
|
||||
UncheckedExtrinsic {
|
||||
signature: Some((sp_runtime::MultiAddress::Id(signed), signature, extra)),
|
||||
function: payload.0,
|
||||
}
|
||||
}
|
||||
None => UncheckedExtrinsic {
|
||||
signature: None,
|
||||
function: xt.function,
|
||||
},
|
||||
None => UncheckedExtrinsic { signature: None, function: xt.function },
|
||||
}
|
||||
}
|
||||
|
||||
@@ -641,7 +614,7 @@ impl Profile {
|
||||
block_construction: ExecutionStrategy::NativeElseWasm,
|
||||
offchain_worker: ExecutionStrategy::NativeElseWasm,
|
||||
other: ExecutionStrategy::NativeElseWasm,
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -676,7 +649,7 @@ fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public
|
||||
|
||||
fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
|
||||
where
|
||||
AccountPublic: From<<TPublic::Pair as Pair>::Public>
|
||||
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
|
||||
{
|
||||
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
|
||||
}
|
||||
@@ -684,24 +657,25 @@ where
|
||||
impl BenchContext {
|
||||
/// Import some block.
|
||||
pub fn import_block(&mut self, block: Block) {
|
||||
let mut import_params = BlockImportParams::new(BlockOrigin::NetworkBroadcast, block.header.clone());
|
||||
let mut import_params =
|
||||
BlockImportParams::new(BlockOrigin::NetworkBroadcast, block.header.clone());
|
||||
import_params.body = Some(block.extrinsics().to_vec());
|
||||
import_params.fork_choice = Some(ForkChoiceStrategy::LongestChain);
|
||||
|
||||
assert_eq!(self.client.chain_info().best_number, 0);
|
||||
|
||||
assert_eq!(
|
||||
futures::executor::block_on(self.client.import_block(import_params, Default::default()))
|
||||
.expect("Failed to import block"),
|
||||
ImportResult::Imported(
|
||||
ImportedAux {
|
||||
header_only: false,
|
||||
clear_justification_requests: false,
|
||||
needs_justification: false,
|
||||
bad_justification: false,
|
||||
is_new_best: true,
|
||||
}
|
||||
futures::executor::block_on(
|
||||
self.client.import_block(import_params, Default::default())
|
||||
)
|
||||
.expect("Failed to import block"),
|
||||
ImportResult::Imported(ImportedAux {
|
||||
header_only: false,
|
||||
clear_justification_requests: false,
|
||||
needs_justification: false,
|
||||
bad_justification: false,
|
||||
is_new_best: true,
|
||||
})
|
||||
);
|
||||
|
||||
assert_eq!(self.client.chain_info().best_number, 1);
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
//! Utilities to build a `TestClient` for `node-runtime`.
|
||||
|
||||
use sp_runtime::BuildStorage;
|
||||
use sc_service::client;
|
||||
use sp_runtime::BuildStorage;
|
||||
/// Re-export test-client utilities.
|
||||
pub use substrate_test_client::*;
|
||||
|
||||
@@ -61,13 +61,15 @@ pub trait TestClientBuilderExt: Sized {
|
||||
fn build(self) -> Client;
|
||||
}
|
||||
|
||||
impl TestClientBuilderExt for substrate_test_client::TestClientBuilder<
|
||||
node_primitives::Block,
|
||||
client::LocalCallExecutor<node_primitives::Block, Backend, Executor>,
|
||||
Backend,
|
||||
GenesisParameters,
|
||||
> {
|
||||
fn new() -> Self{
|
||||
impl TestClientBuilderExt
|
||||
for substrate_test_client::TestClientBuilder<
|
||||
node_primitives::Block,
|
||||
client::LocalCallExecutor<node_primitives::Block, Backend, Executor>,
|
||||
Backend,
|
||||
GenesisParameters,
|
||||
>
|
||||
{
|
||||
fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
@@ -75,5 +77,3 @@ impl TestClientBuilderExt for substrate_test_client::TestClientBuilder<
|
||||
self.build_with_native_executor(None).0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,14 +19,13 @@
|
||||
//! Genesis Configuration.
|
||||
|
||||
use crate::keyring::*;
|
||||
use sp_keyring::{Ed25519Keyring, Sr25519Keyring};
|
||||
use node_runtime::{
|
||||
GenesisConfig, BalancesConfig, SessionConfig, StakingConfig, SystemConfig,
|
||||
GrandpaConfig, IndicesConfig, SocietyConfig, wasm_binary_unwrap,
|
||||
AccountId, StakerStatus, BabeConfig, BABE_GENESIS_EPOCH_CONFIG,
|
||||
constants::currency::*, wasm_binary_unwrap, AccountId, BabeConfig, BalancesConfig,
|
||||
GenesisConfig, GrandpaConfig, IndicesConfig, SessionConfig, SocietyConfig, StakerStatus,
|
||||
StakingConfig, SystemConfig, BABE_GENESIS_EPOCH_CONFIG,
|
||||
};
|
||||
use node_runtime::constants::currency::*;
|
||||
use sp_core::ChangesTrieConfiguration;
|
||||
use sp_keyring::{Ed25519Keyring, Sr25519Keyring};
|
||||
use sp_runtime::Perbill;
|
||||
|
||||
/// Create genesis runtime configuration for tests.
|
||||
@@ -41,7 +40,6 @@ pub fn config_endowed(
|
||||
code: Option<&[u8]>,
|
||||
extra_endowed: Vec<AccountId>,
|
||||
) -> GenesisConfig {
|
||||
|
||||
let mut endowed = vec![
|
||||
(alice(), 111 * DOLLARS),
|
||||
(bob(), 100 * DOLLARS),
|
||||
@@ -51,59 +49,44 @@ pub fn config_endowed(
|
||||
(ferdie(), 100 * DOLLARS),
|
||||
];
|
||||
|
||||
endowed.extend(
|
||||
extra_endowed.into_iter().map(|endowed| (endowed, 100*DOLLARS))
|
||||
);
|
||||
endowed.extend(extra_endowed.into_iter().map(|endowed| (endowed, 100 * DOLLARS)));
|
||||
|
||||
GenesisConfig {
|
||||
system: SystemConfig {
|
||||
changes_trie_config: if support_changes_trie { Some(ChangesTrieConfiguration {
|
||||
digest_interval: 2,
|
||||
digest_levels: 2,
|
||||
}) } else { None },
|
||||
changes_trie_config: if support_changes_trie {
|
||||
Some(ChangesTrieConfiguration { digest_interval: 2, digest_levels: 2 })
|
||||
} else {
|
||||
None
|
||||
},
|
||||
code: code.map(|x| x.to_vec()).unwrap_or_else(|| wasm_binary_unwrap().to_vec()),
|
||||
},
|
||||
indices: IndicesConfig {
|
||||
indices: vec![],
|
||||
},
|
||||
balances: BalancesConfig {
|
||||
balances: endowed,
|
||||
},
|
||||
indices: IndicesConfig { indices: vec![] },
|
||||
balances: BalancesConfig { balances: endowed },
|
||||
session: SessionConfig {
|
||||
keys: vec![
|
||||
(dave(), alice(), to_session_keys(
|
||||
&Ed25519Keyring::Alice,
|
||||
&Sr25519Keyring::Alice,
|
||||
)),
|
||||
(eve(), bob(), to_session_keys(
|
||||
&Ed25519Keyring::Bob,
|
||||
&Sr25519Keyring::Bob,
|
||||
)),
|
||||
(ferdie(), charlie(), to_session_keys(
|
||||
&Ed25519Keyring::Charlie,
|
||||
&Sr25519Keyring::Charlie,
|
||||
)),
|
||||
]
|
||||
(dave(), alice(), to_session_keys(&Ed25519Keyring::Alice, &Sr25519Keyring::Alice)),
|
||||
(eve(), bob(), to_session_keys(&Ed25519Keyring::Bob, &Sr25519Keyring::Bob)),
|
||||
(
|
||||
ferdie(),
|
||||
charlie(),
|
||||
to_session_keys(&Ed25519Keyring::Charlie, &Sr25519Keyring::Charlie),
|
||||
),
|
||||
],
|
||||
},
|
||||
staking: StakingConfig {
|
||||
stakers: vec![
|
||||
(dave(), alice(), 111 * DOLLARS, StakerStatus::Validator),
|
||||
(eve(), bob(), 100 * DOLLARS, StakerStatus::Validator),
|
||||
(ferdie(), charlie(), 100 * DOLLARS, StakerStatus::Validator)
|
||||
(ferdie(), charlie(), 100 * DOLLARS, StakerStatus::Validator),
|
||||
],
|
||||
validator_count: 3,
|
||||
minimum_validator_count: 0,
|
||||
slash_reward_fraction: Perbill::from_percent(10),
|
||||
invulnerables: vec![alice(), bob(), charlie()],
|
||||
.. Default::default()
|
||||
},
|
||||
babe: BabeConfig {
|
||||
authorities: vec![],
|
||||
epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG),
|
||||
},
|
||||
grandpa: GrandpaConfig {
|
||||
authorities: vec![],
|
||||
..Default::default()
|
||||
},
|
||||
babe: BabeConfig { authorities: vec![], epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG) },
|
||||
grandpa: GrandpaConfig { authorities: vec![] },
|
||||
im_online: Default::default(),
|
||||
authority_discovery: Default::default(),
|
||||
democracy: Default::default(),
|
||||
@@ -113,11 +96,7 @@ pub fn config_endowed(
|
||||
elections: Default::default(),
|
||||
sudo: Default::default(),
|
||||
treasury: Default::default(),
|
||||
society: SocietyConfig {
|
||||
members: vec![alice(), bob()],
|
||||
pot: 0,
|
||||
max_members: 999,
|
||||
},
|
||||
society: SocietyConfig { members: vec![alice(), bob()], pot: 0, max_members: 999 },
|
||||
vesting: Default::default(),
|
||||
gilt: Default::default(),
|
||||
transaction_storage: Default::default(),
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
|
||||
//! Test accounts.
|
||||
|
||||
use sp_keyring::{AccountKeyring, Sr25519Keyring, Ed25519Keyring};
|
||||
use node_primitives::{AccountId, Balance, Index};
|
||||
use node_runtime::{CheckedExtrinsic, UncheckedExtrinsic, SessionKeys, SignedExtra};
|
||||
use sp_runtime::generic::Era;
|
||||
use codec::Encode;
|
||||
use node_primitives::{AccountId, Balance, Index};
|
||||
use node_runtime::{CheckedExtrinsic, SessionKeys, SignedExtra, UncheckedExtrinsic};
|
||||
use sp_keyring::{AccountKeyring, Ed25519Keyring, Sr25519Keyring};
|
||||
use sp_runtime::generic::Era;
|
||||
|
||||
/// Alice's account id.
|
||||
pub fn alice() -> AccountId {
|
||||
@@ -81,26 +81,31 @@ pub fn signed_extra(nonce: Index, extra_fee: Balance) -> SignedExtra {
|
||||
}
|
||||
|
||||
/// Sign given `CheckedExtrinsic`.
|
||||
pub fn sign(xt: CheckedExtrinsic, spec_version: u32, tx_version: u32, genesis_hash: [u8; 32]) -> UncheckedExtrinsic {
|
||||
pub fn sign(
|
||||
xt: CheckedExtrinsic,
|
||||
spec_version: u32,
|
||||
tx_version: u32,
|
||||
genesis_hash: [u8; 32],
|
||||
) -> UncheckedExtrinsic {
|
||||
match xt.signed {
|
||||
Some((signed, extra)) => {
|
||||
let payload = (xt.function, extra.clone(), spec_version, tx_version, genesis_hash, genesis_hash);
|
||||
let payload =
|
||||
(xt.function, extra.clone(), spec_version, tx_version, genesis_hash, genesis_hash);
|
||||
let key = AccountKeyring::from_account_id(&signed).unwrap();
|
||||
let signature = payload.using_encoded(|b| {
|
||||
if b.len() > 256 {
|
||||
key.sign(&sp_io::hashing::blake2_256(b))
|
||||
} else {
|
||||
key.sign(b)
|
||||
}
|
||||
}).into();
|
||||
let signature = payload
|
||||
.using_encoded(|b| {
|
||||
if b.len() > 256 {
|
||||
key.sign(&sp_io::hashing::blake2_256(b))
|
||||
} else {
|
||||
key.sign(b)
|
||||
}
|
||||
})
|
||||
.into();
|
||||
UncheckedExtrinsic {
|
||||
signature: Some((sp_runtime::MultiAddress::Id(signed), signature, extra)),
|
||||
function: payload.0,
|
||||
}
|
||||
}
|
||||
None => UncheckedExtrinsic {
|
||||
signature: None,
|
||||
function: xt.function,
|
||||
},
|
||||
None => UncheckedExtrinsic { signature: None, function: xt.function },
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#![warn(missing_docs)]
|
||||
|
||||
pub mod bench;
|
||||
pub mod client;
|
||||
pub mod genesis;
|
||||
pub mod keyring;
|
||||
pub mod bench;
|
||||
|
||||
Reference in New Issue
Block a user