mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 05:51:02 +00:00
Add ParasSudoWrapper to test-runtime and bring back register_parachain to test-service (#1811)
* Make register/deregister parachain dispatchables This makes `register_parachain` and `deregister_parachain` of `Registrar` dispatchables. Besides that it brings back the functionality of the test node to register a parachain. * Fix tests * PR review comments
This commit is contained in:
Generated
+1
@@ -5572,6 +5572,7 @@ dependencies = [
|
|||||||
"polkadot-primitives",
|
"polkadot-primitives",
|
||||||
"polkadot-rpc",
|
"polkadot-rpc",
|
||||||
"polkadot-runtime-common",
|
"polkadot-runtime-common",
|
||||||
|
"polkadot-runtime-parachains",
|
||||||
"polkadot-service",
|
"polkadot-service",
|
||||||
"polkadot-test-runtime",
|
"polkadot-test-runtime",
|
||||||
"rand 0.7.3",
|
"rand 0.7.3",
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ polkadot-rpc = { path = "../../rpc" }
|
|||||||
polkadot-runtime-common = { path = "../../runtime/common" }
|
polkadot-runtime-common = { path = "../../runtime/common" }
|
||||||
polkadot-service = { path = "../service" }
|
polkadot-service = { path = "../service" }
|
||||||
polkadot-test-runtime = { path = "../../runtime/test-runtime" }
|
polkadot-test-runtime = { path = "../../runtime/test-runtime" }
|
||||||
|
polkadot-runtime-parachains = { path = "../../runtime/parachains" }
|
||||||
|
|
||||||
# Substrate dependencies
|
# Substrate dependencies
|
||||||
authority-discovery = { package = "sc-authority-discovery", git = "https://github.com/paritytech/substrate", branch = "master" }
|
authority-discovery = { package = "sc-authority-discovery", git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
|
|||||||
@@ -23,12 +23,13 @@ mod chain_spec;
|
|||||||
pub use chain_spec::*;
|
pub use chain_spec::*;
|
||||||
use futures::future::Future;
|
use futures::future::Future;
|
||||||
use polkadot_overseer::OverseerHandler;
|
use polkadot_overseer::OverseerHandler;
|
||||||
use polkadot_primitives::v1::Block;
|
use polkadot_primitives::v1::{Block, Id as ParaId, HeadData, ValidationCode};
|
||||||
use polkadot_runtime_common::BlockHashCount;
|
use polkadot_runtime_common::BlockHashCount;
|
||||||
use polkadot_service::{
|
use polkadot_service::{
|
||||||
new_full, NewFull, FullClient, AbstractClient, ClientHandle, ExecuteWithClient,
|
new_full, NewFull, FullClient, AbstractClient, ClientHandle, ExecuteWithClient,
|
||||||
};
|
};
|
||||||
use polkadot_test_runtime::{Runtime, SignedExtra, SignedPayload, VERSION};
|
use polkadot_test_runtime::{Runtime, SignedExtra, SignedPayload, VERSION, ParasSudoWrapperCall};
|
||||||
|
use polkadot_runtime_parachains::paras::ParaGenesisArgs;
|
||||||
use sc_chain_spec::ChainSpec;
|
use sc_chain_spec::ChainSpec;
|
||||||
use sc_client_api::{execution_extensions::ExecutionStrategies, BlockchainEvents};
|
use sc_client_api::{execution_extensions::ExecutionStrategies, BlockchainEvents};
|
||||||
use sc_executor::native_executor_instance;
|
use sc_executor::native_executor_instance;
|
||||||
@@ -82,9 +83,13 @@ impl ClientHandle for TestClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a Polkadot `Configuration`. By default an in-memory socket will be used, therefore you need to provide boot
|
/// Create a Polkadot `Configuration`.
|
||||||
/// nodes if you want the future node to be connected to other nodes. The `storage_update_func` can be used to make
|
///
|
||||||
/// adjustements to the runtime before the node starts.
|
/// By default an in-memory socket will be used, therefore you need to provide boot
|
||||||
|
/// nodes if you want the future node to be connected to other nodes.
|
||||||
|
///
|
||||||
|
/// The `storage_update_func` function will be executed in an externalities provided environment
|
||||||
|
/// and can be used to make adjustements to the runtime genesis storage.
|
||||||
pub fn node_config(
|
pub fn node_config(
|
||||||
storage_update_func: impl Fn(),
|
storage_update_func: impl Fn(),
|
||||||
task_executor: TaskExecutor,
|
task_executor: TaskExecutor,
|
||||||
@@ -178,9 +183,13 @@ pub fn node_config(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run a Polkadot test node using the Polkadot test runtime. The node will be using an in-memory socket, therefore you
|
/// Run a Polkadot test node using the Polkadot test runtime.
|
||||||
/// need to provide boot nodes if you want it to be connected to other nodes. The `storage_update_func` can be used to
|
///
|
||||||
/// make adjustements to the runtime before the node starts.
|
/// The node will be using an in-memory socket, therefore you need to provide boot nodes if you
|
||||||
|
/// want it to be connected to other nodes.
|
||||||
|
///
|
||||||
|
/// The `storage_update_func` function will be executed in an externalities provided environment
|
||||||
|
/// and can be used to make adjustements to the runtime genesis storage.
|
||||||
pub fn run_test_node(
|
pub fn run_test_node(
|
||||||
task_executor: TaskExecutor,
|
task_executor: TaskExecutor,
|
||||||
key: Sr25519Keyring,
|
key: Sr25519Keyring,
|
||||||
@@ -230,9 +239,10 @@ where
|
|||||||
/// Send a transaction through RPCHandlers to call a function.
|
/// Send a transaction through RPCHandlers to call a function.
|
||||||
pub async fn call_function(
|
pub async fn call_function(
|
||||||
&self,
|
&self,
|
||||||
function: polkadot_test_runtime::Call,
|
function: impl Into<polkadot_test_runtime::Call>,
|
||||||
caller: Sr25519Keyring,
|
caller: Sr25519Keyring,
|
||||||
) -> Result<RpcTransactionOutput, RpcTransactionError> {
|
) -> Result<RpcTransactionOutput, RpcTransactionError> {
|
||||||
|
let function = function.into();
|
||||||
let current_block_hash = self.client.info().best_hash;
|
let current_block_hash = self.client.info().best_hash;
|
||||||
let current_block = self.client.info().best_number.saturated_into();
|
let current_block = self.client.info().best_number.saturated_into();
|
||||||
let genesis_block = self.client.hash(0).unwrap().unwrap();
|
let genesis_block = self.client.hash(0).unwrap().unwrap();
|
||||||
@@ -274,6 +284,25 @@ where
|
|||||||
|
|
||||||
self.rpc_handlers.send_transaction(extrinsic.into()).await
|
self.rpc_handlers.send_transaction(extrinsic.into()).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Register a parachain at this relay chain.
|
||||||
|
pub async fn register_parachain(
|
||||||
|
&self,
|
||||||
|
id: ParaId,
|
||||||
|
validation_code: ValidationCode,
|
||||||
|
genesis_head: HeadData,
|
||||||
|
) -> Result<(), RpcTransactionError> {
|
||||||
|
let call = ParasSudoWrapperCall::sudo_schedule_para_initialize(
|
||||||
|
id,
|
||||||
|
ParaGenesisArgs {
|
||||||
|
genesis_head,
|
||||||
|
validation_code,
|
||||||
|
parachain: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
self.call_function(call, Sr25519Keyring::Alice).await.map(drop)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, C> PolkadotTestNode<S, C>
|
impl<S, C> PolkadotTestNode<S, C>
|
||||||
|
|||||||
@@ -176,7 +176,6 @@ pub struct ParaGenesisArgs {
|
|||||||
pub parachain: bool,
|
pub parachain: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
decl_storage! {
|
decl_storage! {
|
||||||
trait Store for Module<T: Trait> as Paras {
|
trait Store for Module<T: Trait> as Paras {
|
||||||
/// All parachains. Ordered ascending by ParaId. Parathreads are not included.
|
/// All parachains. Ordered ascending by ParaId. Parathreads are not included.
|
||||||
|
|||||||
@@ -63,8 +63,7 @@ use sp_core::OpaqueMetadata;
|
|||||||
use sp_staking::SessionIndex;
|
use sp_staking::SessionIndex;
|
||||||
use pallet_session::historical as session_historical;
|
use pallet_session::historical as session_historical;
|
||||||
use frame_system::EnsureRoot;
|
use frame_system::EnsureRoot;
|
||||||
use runtime_common::paras_sudo_wrapper as paras_sudo_wrapper;
|
use runtime_common::{paras_sudo_wrapper, paras_registrar};
|
||||||
use runtime_common::paras_registrar;
|
|
||||||
|
|
||||||
use runtime_parachains::origin as parachains_origin;
|
use runtime_parachains::origin as parachains_origin;
|
||||||
use runtime_parachains::configuration as parachains_configuration;
|
use runtime_parachains::configuration as parachains_configuration;
|
||||||
@@ -740,9 +739,9 @@ impl pallet_authorship::Trait for Runtime {
|
|||||||
type EventHandler = (Staking, ImOnline);
|
type EventHandler = (Staking, ImOnline);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl parachains_origin::Trait for Runtime { }
|
impl parachains_origin::Trait for Runtime {}
|
||||||
|
|
||||||
impl parachains_configuration::Trait for Runtime { }
|
impl parachains_configuration::Trait for Runtime {}
|
||||||
|
|
||||||
impl parachains_inclusion::Trait for Runtime {
|
impl parachains_inclusion::Trait for Runtime {
|
||||||
type Event = Event;
|
type Event = Event;
|
||||||
@@ -752,17 +751,17 @@ impl parachains_paras::Trait for Runtime {
|
|||||||
type Origin = Origin;
|
type Origin = Origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl parachains_router::Trait for Runtime { }
|
impl parachains_router::Trait for Runtime {}
|
||||||
|
|
||||||
impl parachains_inclusion_inherent::Trait for Runtime { }
|
impl parachains_inclusion_inherent::Trait for Runtime {}
|
||||||
|
|
||||||
impl parachains_scheduler::Trait for Runtime { }
|
impl parachains_scheduler::Trait for Runtime {}
|
||||||
|
|
||||||
impl parachains_initializer::Trait for Runtime {
|
impl parachains_initializer::Trait for Runtime {
|
||||||
type Randomness = Babe;
|
type Randomness = Babe;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl paras_sudo_wrapper::Trait for Runtime { }
|
impl paras_sudo_wrapper::Trait for Runtime {}
|
||||||
|
|
||||||
impl paras_registrar::Trait for Runtime {
|
impl paras_registrar::Trait for Runtime {
|
||||||
type Currency = Balances;
|
type Currency = Balances;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ use primitives::v1::{
|
|||||||
PersistedValidationData, Signature, ValidationCode, ValidationData, ValidatorId, ValidatorIndex,
|
PersistedValidationData, Signature, ValidationCode, ValidationData, ValidatorId, ValidatorIndex,
|
||||||
};
|
};
|
||||||
use runtime_common::{
|
use runtime_common::{
|
||||||
claims, SlowAdjustingFeeUpdate,
|
claims, SlowAdjustingFeeUpdate, paras_sudo_wrapper,
|
||||||
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio,
|
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio,
|
||||||
MaximumBlockLength, BlockExecutionWeight, ExtrinsicBaseWeight, ParachainSessionKeyPlaceholder,
|
MaximumBlockLength, BlockExecutionWeight, ExtrinsicBaseWeight, ParachainSessionKeyPlaceholder,
|
||||||
};
|
};
|
||||||
@@ -74,6 +74,7 @@ pub use pallet_staking::StakerStatus;
|
|||||||
pub use sp_runtime::BuildStorage;
|
pub use sp_runtime::BuildStorage;
|
||||||
pub use pallet_timestamp::Call as TimestampCall;
|
pub use pallet_timestamp::Call as TimestampCall;
|
||||||
pub use pallet_balances::Call as BalancesCall;
|
pub use pallet_balances::Call as BalancesCall;
|
||||||
|
pub use paras_sudo_wrapper::Call as ParasSudoWrapperCall;
|
||||||
|
|
||||||
/// Constant values used within the runtime.
|
/// Constant values used within the runtime.
|
||||||
pub mod constants;
|
pub mod constants;
|
||||||
@@ -448,6 +449,8 @@ impl router::Trait for Runtime {}
|
|||||||
|
|
||||||
impl scheduler::Trait for Runtime {}
|
impl scheduler::Trait for Runtime {}
|
||||||
|
|
||||||
|
impl paras_sudo_wrapper::Trait for Runtime {}
|
||||||
|
|
||||||
construct_runtime! {
|
construct_runtime! {
|
||||||
pub enum Runtime where
|
pub enum Runtime where
|
||||||
Block = Block,
|
Block = Block,
|
||||||
@@ -487,8 +490,8 @@ construct_runtime! {
|
|||||||
Initializer: initializer::{Module, Call, Storage},
|
Initializer: initializer::{Module, Call, Storage},
|
||||||
Paras: paras::{Module, Call, Storage, Origin},
|
Paras: paras::{Module, Call, Storage, Origin},
|
||||||
Scheduler: scheduler::{Module, Call, Storage},
|
Scheduler: scheduler::{Module, Call, Storage},
|
||||||
|
ParasSudoWrapper: paras_sudo_wrapper::{Module, Call},
|
||||||
|
|
||||||
// Sudo. Last module.
|
|
||||||
Sudo: pallet_sudo::{Module, Call, Storage, Config<T>, Event<T>},
|
Sudo: pallet_sudo::{Module, Call, Storage, Config<T>, Event<T>},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user