mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 16:21:02 +00:00
Remove usage of substrate-test-runtime. (#969)
* Switch from using the substrate_test_runtime Extrinsic to the polkadot_test_runtime one * Copy genesismap into test-runtime * Add UncheckedExtrinsics * Fix tests :^) * Remove unused functions from genesismap * DRY, clean up * Clean up * Update service/src/grandpa_support.rs Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Fix indentation * Update runtime/test-runtime/src/genesismap.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Generated
+4
-2
@@ -4150,7 +4150,6 @@ dependencies = [
|
|||||||
name = "polkadot-network-test"
|
name = "polkadot-network-test"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"env_logger 0.7.1",
|
|
||||||
"futures 0.3.4",
|
"futures 0.3.4",
|
||||||
"log 0.4.8",
|
"log 0.4.8",
|
||||||
"parking_lot 0.10.2",
|
"parking_lot 0.10.2",
|
||||||
@@ -4334,6 +4333,7 @@ dependencies = [
|
|||||||
name = "polkadot-service"
|
name = "polkadot-service"
|
||||||
version = "0.7.30"
|
version = "0.7.30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"env_logger 0.7.1",
|
||||||
"frame-benchmarking",
|
"frame-benchmarking",
|
||||||
"frame-system-rpc-runtime-api",
|
"frame-system-rpc-runtime-api",
|
||||||
"futures 0.3.4",
|
"futures 0.3.4",
|
||||||
@@ -4457,7 +4457,10 @@ name = "polkadot-test-runtime-client"
|
|||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures 0.3.4",
|
"futures 0.3.4",
|
||||||
|
"pallet-timestamp",
|
||||||
"parity-scale-codec",
|
"parity-scale-codec",
|
||||||
|
"polkadot-primitives",
|
||||||
|
"polkadot-runtime-common",
|
||||||
"polkadot-test-runtime",
|
"polkadot-test-runtime",
|
||||||
"sc-block-builder",
|
"sc-block-builder",
|
||||||
"sc-client",
|
"sc-client",
|
||||||
@@ -4467,7 +4470,6 @@ dependencies = [
|
|||||||
"sp-core",
|
"sp-core",
|
||||||
"sp-runtime",
|
"sp-runtime",
|
||||||
"substrate-test-client",
|
"substrate-test-client",
|
||||||
"substrate-test-runtime",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -19,5 +19,4 @@ sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "mas
|
|||||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
sc-block-builder = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
sc-block-builder = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
env_logger = "0.7.0"
|
|
||||||
polkadot-test-runtime-client = { path = "../../runtime/test-runtime/client" }
|
polkadot-test-runtime-client = { path = "../../runtime/test-runtime/client" }
|
||||||
|
|||||||
@@ -27,7 +27,15 @@ use super::*;
|
|||||||
|
|
||||||
fn prepare_good_block() -> (TestClient, Hash, u64, PeerId, IncomingBlock<Block>) {
|
fn prepare_good_block() -> (TestClient, Hash, u64, PeerId, IncomingBlock<Block>) {
|
||||||
let mut client = polkadot_test_runtime_client::new();
|
let mut client = polkadot_test_runtime_client::new();
|
||||||
let block = client.new_block(Default::default()).unwrap().build().unwrap().block;
|
let mut builder = client.new_block(Default::default()).unwrap();
|
||||||
|
|
||||||
|
let extrinsics = polkadot_test_runtime_client::needed_extrinsics(vec![]);
|
||||||
|
|
||||||
|
for extrinsic in &extrinsics {
|
||||||
|
builder.push(extrinsic.clone()).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
let block = builder.build().unwrap().block;
|
||||||
client.import(BlockOrigin::File, block).unwrap();
|
client.import(BlockOrigin::File, block).unwrap();
|
||||||
|
|
||||||
let (hash, number) = (client.block_hash(1).unwrap().unwrap(), 1);
|
let (hash, number) = (client.block_hash(1).unwrap().unwrap(), 1);
|
||||||
@@ -37,7 +45,7 @@ fn prepare_good_block() -> (TestClient, Hash, u64, PeerId, IncomingBlock<Block>)
|
|||||||
(client, hash, number, peer_id.clone(), IncomingBlock {
|
(client, hash, number, peer_id.clone(), IncomingBlock {
|
||||||
hash,
|
hash,
|
||||||
header,
|
header,
|
||||||
body: Some(Vec::new()),
|
body: Some(extrinsics),
|
||||||
justification,
|
justification,
|
||||||
origin: Some(peer_id.clone()),
|
origin: Some(peer_id.clone()),
|
||||||
allow_missing_state: false,
|
allow_missing_state: false,
|
||||||
|
|||||||
@@ -10,11 +10,13 @@ sc-block-builder = { git = "https://github.com/paritytech/substrate", branch = "
|
|||||||
substrate-test-client = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
substrate-test-client = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
polkadot-test-runtime = { path = ".." }
|
polkadot-test-runtime = { path = ".." }
|
||||||
substrate-test-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
polkadot-runtime-common = { path = "../../common" }
|
||||||
|
polkadot-primitives = { path = "../../../primitives" }
|
||||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
codec = { package = "parity-scale-codec", version = "1.0.0" }
|
codec = { package = "parity-scale-codec", version = "1.0.0" }
|
||||||
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
sc-client = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
sc-client = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
|
pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
futures = "0.3.1"
|
futures = "0.3.1"
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ pub use sc_client::LongestChain;
|
|||||||
|
|
||||||
use sp_core::{sr25519, ChangesTrieConfiguration, map, twox_128};
|
use sp_core::{sr25519, ChangesTrieConfiguration, map, twox_128};
|
||||||
use sp_core::storage::{ChildInfo, Storage, StorageChild};
|
use sp_core::storage::{ChildInfo, Storage, StorageChild};
|
||||||
use substrate_test_runtime::genesismap::{GenesisConfig};
|
use polkadot_test_runtime::genesismap::GenesisConfig;
|
||||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Hash as HashT, HashFor};
|
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Hash as HashT, HashFor};
|
||||||
use sc_client::{
|
use sc_client::{
|
||||||
light::fetcher::{
|
light::fetcher::{
|
||||||
@@ -81,7 +81,6 @@ pub type LightExecutor = sc_client::light::call_executor::GenesisCallExecutor<
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct GenesisParameters {
|
pub struct GenesisParameters {
|
||||||
changes_trie_config: Option<ChangesTrieConfiguration>,
|
changes_trie_config: Option<ChangesTrieConfiguration>,
|
||||||
heap_pages_override: Option<u64>,
|
|
||||||
extra_storage: Storage,
|
extra_storage: Storage,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,13 +93,7 @@ impl GenesisParameters {
|
|||||||
sr25519::Public::from(Sr25519Keyring::Bob).into(),
|
sr25519::Public::from(Sr25519Keyring::Bob).into(),
|
||||||
sr25519::Public::from(Sr25519Keyring::Charlie).into(),
|
sr25519::Public::from(Sr25519Keyring::Charlie).into(),
|
||||||
],
|
],
|
||||||
vec![
|
|
||||||
AccountKeyring::Alice.into(),
|
|
||||||
AccountKeyring::Bob.into(),
|
|
||||||
AccountKeyring::Charlie.into(),
|
|
||||||
],
|
|
||||||
1000,
|
1000,
|
||||||
self.heap_pages_override,
|
|
||||||
self.extra_storage.clone(),
|
self.extra_storage.clone(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -176,12 +169,6 @@ pub trait TestClientBuilderExt<B>: Sized {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Override the default value for Wasm heap pages.
|
|
||||||
fn set_heap_pages(mut self, heap_pages: u64) -> Self {
|
|
||||||
self.genesis_init_mut().heap_pages_override = Some(heap_pages);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add an extra value into the genesis storage.
|
/// Add an extra value into the genesis storage.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
@@ -256,7 +243,7 @@ type MaybeFetcherCallback<Req, Resp> = Option<Box<dyn Fn(Req) -> Result<Resp, sp
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct LightFetcher {
|
pub struct LightFetcher {
|
||||||
call: MaybeFetcherCallback<RemoteCallRequest<polkadot_test_runtime::Header>, Vec<u8>>,
|
call: MaybeFetcherCallback<RemoteCallRequest<polkadot_test_runtime::Header>, Vec<u8>>,
|
||||||
body: MaybeFetcherCallback<RemoteBodyRequest<polkadot_test_runtime::Header>, Vec<substrate_test_runtime::Extrinsic>>,
|
body: MaybeFetcherCallback<RemoteBodyRequest<polkadot_test_runtime::Header>, Vec<polkadot_test_runtime::Extrinsic>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LightFetcher {
|
impl LightFetcher {
|
||||||
@@ -274,7 +261,7 @@ impl LightFetcher {
|
|||||||
/// Sets remote body callback.
|
/// Sets remote body callback.
|
||||||
pub fn with_remote_body(
|
pub fn with_remote_body(
|
||||||
self,
|
self,
|
||||||
body: MaybeFetcherCallback<RemoteBodyRequest<polkadot_test_runtime::Header>, Vec<substrate_test_runtime::Extrinsic>>,
|
body: MaybeFetcherCallback<RemoteBodyRequest<polkadot_test_runtime::Header>, Vec<polkadot_test_runtime::Extrinsic>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
LightFetcher {
|
LightFetcher {
|
||||||
call: self.call,
|
call: self.call,
|
||||||
@@ -321,3 +308,23 @@ pub fn new_light_fetcher() -> LightFetcher {
|
|||||||
pub fn new_native_executor() -> sc_executor::NativeExecutor<LocalExecutor> {
|
pub fn new_native_executor() -> sc_executor::NativeExecutor<LocalExecutor> {
|
||||||
sc_executor::NativeExecutor::new(sc_executor::WasmExecutionMethod::Interpreted, None, 8)
|
sc_executor::NativeExecutor::new(sc_executor::WasmExecutionMethod::Interpreted, None, 8)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Extrinsics that must be included in each block.
|
||||||
|
pub fn needed_extrinsics(heads: Vec<polkadot_primitives::parachain::AttestedCandidate>) -> Vec<polkadot_test_runtime::UncheckedExtrinsic> {
|
||||||
|
use polkadot_runtime_common::parachains;
|
||||||
|
|
||||||
|
vec![
|
||||||
|
polkadot_test_runtime::UncheckedExtrinsic {
|
||||||
|
function: polkadot_test_runtime::Call::Parachains(parachains::Call::set_heads(heads)),
|
||||||
|
signature: None,
|
||||||
|
},
|
||||||
|
polkadot_test_runtime::UncheckedExtrinsic {
|
||||||
|
function: polkadot_test_runtime::Call::Timestamp(pallet_timestamp::Call::set({
|
||||||
|
std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH)
|
||||||
|
.expect("now always later than unix epoch; qed")
|
||||||
|
.as_millis() as u64
|
||||||
|
})),
|
||||||
|
signature: None,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Substrate.
|
||||||
|
|
||||||
|
// Substrate is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
|
||||||
|
// Substrate is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Tool for creating the genesis block.
|
||||||
|
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
use super::{AccountId, WASM_BINARY, constants::currency};
|
||||||
|
use sp_core::ChangesTrieConfiguration;
|
||||||
|
use sp_core::storage::Storage;
|
||||||
|
use sp_runtime::BuildStorage;
|
||||||
|
|
||||||
|
/// Configuration of a general Substrate test genesis block.
|
||||||
|
pub struct GenesisConfig {
|
||||||
|
changes_trie_config: Option<ChangesTrieConfiguration>,
|
||||||
|
balances: Vec<(AccountId, u128)>,
|
||||||
|
/// Additional storage key pairs that will be added to the genesis map.
|
||||||
|
extra_storage: Storage,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GenesisConfig {
|
||||||
|
pub fn new(
|
||||||
|
changes_trie_config: Option<ChangesTrieConfiguration>,
|
||||||
|
endowed_accounts: Vec<AccountId>,
|
||||||
|
balance: u128,
|
||||||
|
extra_storage: Storage,
|
||||||
|
) -> Self {
|
||||||
|
GenesisConfig {
|
||||||
|
changes_trie_config,
|
||||||
|
balances: endowed_accounts.into_iter().map(|a| (a, balance * currency::DOLLARS)).collect(),
|
||||||
|
extra_storage,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn genesis_map(&self) -> Storage {
|
||||||
|
// Assimilate the system genesis config.
|
||||||
|
let mut storage = Storage { top: BTreeMap::new(), children: self.extra_storage.children.clone()};
|
||||||
|
let config = crate::GenesisConfig {
|
||||||
|
system: Some(system::GenesisConfig {
|
||||||
|
changes_trie_config: self.changes_trie_config.clone(),
|
||||||
|
code: WASM_BINARY.to_vec(),
|
||||||
|
}),
|
||||||
|
babe: None,
|
||||||
|
indices: None,
|
||||||
|
balances: Some(balances::GenesisConfig {
|
||||||
|
balances: self.balances.clone()
|
||||||
|
}),
|
||||||
|
staking: None,
|
||||||
|
session: None,
|
||||||
|
grandpa: None,
|
||||||
|
claims: None,
|
||||||
|
parachains: None,
|
||||||
|
registrar: None,
|
||||||
|
vesting: None,
|
||||||
|
};
|
||||||
|
config.assimilate_storage(&mut storage).expect("Adding `system::GensisConfig` to the genesis");
|
||||||
|
|
||||||
|
storage
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -69,6 +69,8 @@ pub use parachains::Call as ParachainsCall;
|
|||||||
|
|
||||||
/// Constant values used within the runtime.
|
/// Constant values used within the runtime.
|
||||||
pub mod constants;
|
pub mod constants;
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
pub mod genesismap;
|
||||||
use constants::{time::*, currency::*, fee::*};
|
use constants::{time::*, currency::*, fee::*};
|
||||||
|
|
||||||
// Make the WASM binary available.
|
// Make the WASM binary available.
|
||||||
@@ -204,7 +206,7 @@ impl transaction_payment::Trait for Runtime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parameter_types! {
|
parameter_types! {
|
||||||
pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
|
pub const MinimumPeriod: u64 = 0;
|
||||||
}
|
}
|
||||||
impl timestamp::Trait for Runtime {
|
impl timestamp::Trait for Runtime {
|
||||||
type Moment = u64;
|
type Moment = u64;
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch =
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
polkadot-test-runtime-client = { path = "../runtime/test-runtime/client" }
|
polkadot-test-runtime-client = { path = "../runtime/test-runtime/client" }
|
||||||
sc-block-builder = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
sc-block-builder = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
|
env_logger = "0.7.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["db", "full-node"]
|
default = ["db", "full-node"]
|
||||||
|
|||||||
@@ -244,13 +244,21 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn grandpa_pause_voting_rule_works() {
|
fn grandpa_pause_voting_rule_works() {
|
||||||
|
let _ = env_logger::try_init();
|
||||||
|
|
||||||
let client = Arc::new(polkadot_test_runtime_client::new());
|
let client = Arc::new(polkadot_test_runtime_client::new());
|
||||||
|
|
||||||
let mut push_blocks = {
|
let mut push_blocks = {
|
||||||
let mut client = client.clone();
|
let mut client = client.clone();
|
||||||
move |n| {
|
move |n| {
|
||||||
for _ in 0..n {
|
for _ in 0..n {
|
||||||
let block = client.new_block(Default::default()).unwrap().build().unwrap().block;
|
let mut builder = client.new_block(Default::default()).unwrap();
|
||||||
|
|
||||||
|
for extrinsic in polkadot_test_runtime_client::needed_extrinsics(vec![]) {
|
||||||
|
builder.push(extrinsic).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
let block = builder.build().unwrap().block;
|
||||||
client.import(BlockOrigin::Own, block).unwrap();
|
client.import(BlockOrigin::Own, block).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user