diff --git a/Cargo.lock b/Cargo.lock
index e86e42238c18..8e625a4ac85a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5439,6 +5439,7 @@ dependencies = [
"sp-runtime",
"sp-state-machine",
"substrate-test-client",
+ "substrate-test-utils",
"tempfile",
"tokio 0.2.21",
]
@@ -8587,6 +8588,26 @@ dependencies = [
"substrate-test-runtime",
]
+[[package]]
+name = "substrate-test-utils"
+version = "2.0.0-rc5"
+source = "git+https://github.com/paritytech/substrate#473a23f462c60fb5a063ea8dff9261e27ac0ea48"
+dependencies = [
+ "futures 0.3.5",
+ "substrate-test-utils-derive",
+ "tokio 0.2.21",
+]
+
+[[package]]
+name = "substrate-test-utils-derive"
+version = "0.8.0-rc5"
+source = "git+https://github.com/paritytech/substrate#473a23f462c60fb5a063ea8dff9261e27ac0ea48"
+dependencies = [
+ "proc-macro-crate",
+ "quote 1.0.7",
+ "syn 1.0.33",
+]
+
[[package]]
name = "substrate-wasm-builder-runner"
version = "1.0.6"
diff --git a/node/test-service/Cargo.toml b/node/test-service/Cargo.toml
index db6328a9aac2..46d54197a716 100644
--- a/node/test-service/Cargo.toml
+++ b/node/test-service/Cargo.toml
@@ -53,4 +53,5 @@ substrate-test-client = { git = "https://github.com/paritytech/substrate", branc
[dev-dependencies]
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
serde_json = "1.0"
+substrate-test-utils = { git = "https://github.com/paritytech/substrate", branch = "master" }
tokio = { version = "0.2", features = ["macros"] }
diff --git a/node/test-service/tests/build-blocks.rs b/node/test-service/tests/build-blocks.rs
index 612efc8f768e..b809f188aafc 100644
--- a/node/test-service/tests/build-blocks.rs
+++ b/node/test-service/tests/build-blocks.rs
@@ -14,21 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see .
-use tokio::{time::delay_for as sleep, task::spawn};
-use futures::{future, pin_mut, select, FutureExt as _};
+use futures::{future, pin_mut, select};
use polkadot_test_service::*;
use service::TaskExecutor;
use sp_keyring::Sr25519Keyring;
-use std::time::Duration;
-static INTEGRATION_TEST_ALLOWED_TIME: Option<&str> = option_env!("INTEGRATION_TEST_ALLOWED_TIME");
-
-#[tokio::test]
-async fn ensure_test_service_build_blocks() {
- let task_executor: TaskExecutor = (move |fut, _| {
- spawn(fut).map(|_| ())
- })
- .into();
+#[substrate_test_utils::test]
+async fn ensure_test_service_build_blocks(task_executor: TaskExecutor) {
let mut alice = run_test_node(
task_executor.clone(),
Sr25519Keyring::Alice,
@@ -41,38 +33,21 @@ async fn ensure_test_service_build_blocks() {
|| {},
vec![alice.addr.clone()],
);
- let t1 = sleep(Duration::from_secs(
- INTEGRATION_TEST_ALLOWED_TIME
- .and_then(|x| x.parse().ok())
- .unwrap_or(600),
- ))
- .fuse();
- let t2 = async {
- {
- let t1 = future::join(alice.wait_for_blocks(3), bob.wait_for_blocks(3)).fuse();
- let t2 = alice.task_manager.future().fuse();
- let t3 = bob.task_manager.future().fuse();
- pin_mut!(t1, t2, t3);
+ {
+ let t1 = future::join(alice.wait_for_blocks(3), bob.wait_for_blocks(3)).fuse();
+ let t2 = alice.task_manager.future().fuse();
+ let t3 = bob.task_manager.future().fuse();
- select! {
- _ = t1 => {},
- _ = t2 => panic!("service Alice failed"),
- _ = t3 => panic!("service Bob failed"),
- }
- }
+ pin_mut!(t1, t2, t3);
- alice.task_manager.terminate();
- bob.task_manager.terminate();
+ select! {
+ _ = t1 => {},
+ _ = t2 => panic!("service Alice failed"),
+ _ = t3 => panic!("service Bob failed"),
+ }
}
- .fuse();
- pin_mut!(t1, t2);
-
- select! {
- _ = t1 => {
- panic!("the test took too long, maybe no blocks have been produced");
- },
- _ = t2 => {},
- }
+ alice.task_manager.clean_shutdown().await;
+ bob.task_manager.clean_shutdown().await;
}
diff --git a/node/test-service/tests/call-function.rs b/node/test-service/tests/call-function.rs
index 8a4db067ae0b..af62bcf5dbff 100644
--- a/node/test-service/tests/call-function.rs
+++ b/node/test-service/tests/call-function.rs
@@ -14,60 +14,31 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see .
-use tokio::{time::delay_for as sleep, task::spawn};
-use futures::{pin_mut, select, FutureExt as _};
use polkadot_test_service::*;
+use service::TaskExecutor;
use sp_keyring::Sr25519Keyring::{Alice, Bob};
-use std::time::Duration;
-static INTEGRATION_TEST_ALLOWED_TIME: Option<&str> = option_env!("INTEGRATION_TEST_ALLOWED_TIME");
-
-#[tokio::test]
-async fn call_function_actually_work() {
- let mut alice = run_test_node(
- (move |fut, _| {
- spawn(fut).map(|_| ())
- })
- .into(),
- Alice,
- || {},
- Vec::new(),
+#[substrate_test_utils::test]
+async fn call_function_actually_work(task_executor: TaskExecutor) {
+ let alice = run_test_node(task_executor, Alice, || {}, Vec::new());
+
+ let function = polkadot_test_runtime::Call::Balances(pallet_balances::Call::transfer(
+ Default::default(),
+ 1,
+ ));
+ let output = alice.call_function(function, Bob).await.unwrap();
+
+ let res = output.result.expect("return value expected");
+ let json = serde_json::from_str::(res.as_str()).expect("valid JSON");
+ let object = json.as_object().expect("JSON is an object");
+ assert!(object.contains_key("jsonrpc"), "key jsonrpc exists");
+ let result = object.get("result");
+ let result = result.expect("key result exists");
+ assert_eq!(
+ result.as_str().map(|x| x.starts_with("0x")),
+ Some(true),
+ "result starts with 0x"
);
- let t1 = sleep(Duration::from_secs(
- INTEGRATION_TEST_ALLOWED_TIME
- .and_then(|x| x.parse().ok())
- .unwrap_or(600),
- ))
- .fuse();
- let t2 = async {
- let function = polkadot_test_runtime::Call::Balances(pallet_balances::Call::transfer(
- Default::default(),
- 1,
- ));
- let output = alice.call_function(function, Bob).await.unwrap();
-
- let res = output.result.expect("return value expected");
- let json = serde_json::from_str::(res.as_str()).expect("valid JSON");
- let object = json.as_object().expect("JSON is an object");
- assert!(object.contains_key("jsonrpc"), "key jsonrpc exists");
- let result = object.get("result");
- let result = result.expect("key result exists");
- assert_eq!(
- result.as_str().map(|x| x.starts_with("0x")),
- Some(true),
- "result starts with 0x"
- );
-
- alice.task_manager.terminate();
- }
- .fuse();
-
- pin_mut!(t1, t2);
- select! {
- _ = t1 => {
- panic!("the test took too long, maybe no blocks have been produced");
- },
- _ = t2 => {},
- }
+ alice.task_manager.clean_shutdown().await;
}