mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 15:41:02 +00:00
Remove sleep from tests (#4639)
* Remove sleep and use polkadot test service Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * updates Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Fix other tests Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Run metrics tests separately Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * copy some substrate utilities Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * update runtime metric test Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Remove sleep from cli tests Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * cargo Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Polkadot companion for Substrate#10463 (#4519) * Grandpa and Beefy protocol names include chain id Signed-off-by: acatangiu <adrian@parity.io> * chain_spec: include fork id * use simplified protocol name * fix after merge * avoid using hash default, even for protocol names * update lockfile for substrate Co-authored-by: parity-processbot <> * configuration: Update upgrade validation delay doc (#4662) * typo Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * review feedback Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * cargo lock Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * use testnet profile Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Don't run with runtime-benchmark feature Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * conditional compile up one level Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> Co-authored-by: Sergei Shulepov <sergei@parity.io>
This commit is contained in:
@@ -62,3 +62,6 @@ pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "m
|
||||
serde_json = "1.0.74"
|
||||
substrate-test-utils = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
tokio = { version = "1.15", features = ["macros"] }
|
||||
|
||||
[features]
|
||||
runtime-metrics=["polkadot-test-runtime/runtime-metrics"]
|
||||
@@ -28,7 +28,9 @@ use polkadot_overseer::Handle;
|
||||
use polkadot_primitives::v1::{Balance, CollatorPair, HeadData, Id as ParaId, ValidationCode};
|
||||
use polkadot_runtime_common::BlockHashCount;
|
||||
use polkadot_runtime_parachains::paras::ParaGenesisArgs;
|
||||
use polkadot_service::{ClientHandle, Error, ExecuteWithClient, FullClient, IsCollator, NewFull};
|
||||
use polkadot_service::{
|
||||
ClientHandle, Error, ExecuteWithClient, FullClient, IsCollator, NewFull, PrometheusConfig,
|
||||
};
|
||||
use polkadot_test_runtime::{
|
||||
ParasSudoWrapperCall, Runtime, SignedExtra, SignedPayload, SudoCall, UncheckedExtrinsic,
|
||||
VERSION,
|
||||
@@ -48,7 +50,11 @@ use sp_blockchain::HeaderBackend;
|
||||
use sp_keyring::Sr25519Keyring;
|
||||
use sp_runtime::{codec::Encode, generic, traits::IdentifyAccount, MultiSigner};
|
||||
use sp_state_machine::BasicExternalities;
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
use std::{
|
||||
net::{Ipv4Addr, SocketAddr},
|
||||
path::PathBuf,
|
||||
sync::Arc,
|
||||
};
|
||||
use substrate_test_client::{
|
||||
BlockchainEventsExt, RpcHandlersExt, RpcTransactionError, RpcTransactionOutput,
|
||||
};
|
||||
@@ -102,6 +108,14 @@ impl ClientHandle for TestClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a prometheus config usable for testing.
|
||||
pub fn test_prometheus_config(port: u16) -> PrometheusConfig {
|
||||
PrometheusConfig::new_with_default_registry(
|
||||
SocketAddr::new(Ipv4Addr::LOCALHOST.into(), port),
|
||||
"test-chain".to_string(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Create a Polkadot `Configuration`.
|
||||
///
|
||||
/// By default an in-memory socket will be used, therefore you need to provide boot
|
||||
@@ -160,7 +174,7 @@ pub fn node_config(
|
||||
keep_blocks: KeepBlocks::All,
|
||||
transaction_storage: TransactionStorageMode::BlockBody,
|
||||
chain_spec: Box::new(spec),
|
||||
wasm_method: WasmExecutionMethod::Interpreted,
|
||||
wasm_method: WasmExecutionMethod::Compiled,
|
||||
wasm_runtime_overrides: Default::default(),
|
||||
// NOTE: we enforce the use of the native runtime to make the errors more debuggable
|
||||
execution_strategies: ExecutionStrategies {
|
||||
@@ -195,21 +209,11 @@ pub fn node_config(
|
||||
}
|
||||
}
|
||||
|
||||
/// Run a test validator node that uses the test runtime.
|
||||
///
|
||||
/// 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 adjustments to the runtime genesis storage.
|
||||
/// Run a test validator node that uses the test runtime and specified `config`.
|
||||
pub fn run_validator_node(
|
||||
tokio_handle: tokio::runtime::Handle,
|
||||
key: Sr25519Keyring,
|
||||
storage_update_func: impl Fn(),
|
||||
boot_nodes: Vec<MultiaddrWithPeerId>,
|
||||
config: Configuration,
|
||||
worker_program_path: Option<PathBuf>,
|
||||
) -> PolkadotTestNode {
|
||||
let config = node_config(storage_update_func, tokio_handle, key, boot_nodes, true);
|
||||
let multiaddr = config.network.listen_addresses[0].clone();
|
||||
let NewFull { task_manager, client, network, rpc_handlers, overseer_handle, .. } =
|
||||
new_full(config, IsCollator::No, worker_program_path)
|
||||
|
||||
@@ -23,21 +23,23 @@ async fn ensure_test_service_build_blocks() {
|
||||
let mut builder = sc_cli::LoggerBuilder::new("");
|
||||
builder.with_colors(false);
|
||||
builder.init().expect("Sets up logger");
|
||||
|
||||
let mut alice = run_validator_node(
|
||||
let alice_config = node_config(
|
||||
|| {},
|
||||
tokio::runtime::Handle::current(),
|
||||
Sr25519Keyring::Alice,
|
||||
|| {},
|
||||
Vec::new(),
|
||||
None,
|
||||
true,
|
||||
);
|
||||
let mut bob = run_validator_node(
|
||||
let mut alice = run_validator_node(alice_config, None);
|
||||
|
||||
let bob_config = node_config(
|
||||
|| {},
|
||||
tokio::runtime::Handle::current(),
|
||||
Sr25519Keyring::Bob,
|
||||
|| {},
|
||||
vec![alice.addr.clone()],
|
||||
None,
|
||||
true,
|
||||
);
|
||||
let mut bob = run_validator_node(bob_config, None);
|
||||
|
||||
{
|
||||
let t1 = future::join(alice.wait_for_blocks(3), bob.wait_for_blocks(3)).fuse();
|
||||
|
||||
@@ -19,8 +19,10 @@ use sp_keyring::Sr25519Keyring::{Alice, Bob, Charlie};
|
||||
|
||||
#[substrate_test_utils::test]
|
||||
async fn call_function_actually_work() {
|
||||
let alice =
|
||||
run_validator_node(tokio::runtime::Handle::current(), Alice, || {}, Vec::new(), None);
|
||||
let alice_config =
|
||||
node_config(|| {}, tokio::runtime::Handle::current(), Alice, Vec::new(), true);
|
||||
|
||||
let alice = run_validator_node(alice_config, None);
|
||||
|
||||
let function = polkadot_test_runtime::Call::Balances(pallet_balances::Call::transfer {
|
||||
dest: Charlie.to_account_id().into(),
|
||||
|
||||
Reference in New Issue
Block a user