// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program 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.
// This program 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 this program. If not, see .
//! Service integration test utils.
use futures::{task::Poll, Future, TryFutureExt as _};
use log::{debug, info};
use parking_lot::Mutex;
use sc_client_api::{Backend, CallExecutor};
use sc_network::{
config::{MultiaddrWithPeerId, NetworkConfiguration, TransportConfig},
multiaddr, NetworkBlock, NetworkPeers, NetworkStateInfo,
};
use sc_network_sync::SyncingService;
use sc_service::{
client::Client,
config::{BasePath, DatabaseSource, KeystoreConfig, RpcBatchRequestConfig},
BlocksPruning, ChainSpecExtension, Configuration, Error, GenericChainSpec, Role,
RuntimeGenesis, SpawnTaskHandle, TaskManager,
};
use sc_transaction_pool_api::TransactionPool;
use sp_blockchain::HeaderBackend;
use sp_runtime::traits::Block as BlockT;
use std::{iter, net::Ipv4Addr, pin::Pin, sync::Arc, task::Context, time::Duration};
use tempfile::TempDir;
use tokio::{runtime::Runtime, time};
#[cfg(test)]
mod client;
/// Maximum duration of single wait call.
const MAX_WAIT_TIME: Duration = Duration::from_secs(60 * 3);
struct TestNet {
runtime: Runtime,
authority_nodes: Vec<(usize, F, U, MultiaddrWithPeerId)>,
full_nodes: Vec<(usize, F, U, MultiaddrWithPeerId)>,
chain_spec: GenericChainSpec,
base_port: u16,
nodes: usize,
}
impl Drop for TestNet {
fn drop(&mut self) {
// Drop the nodes before dropping the runtime, as the runtime otherwise waits for all
// futures to be ended and we run into a dead lock.
self.full_nodes.drain(..);
self.authority_nodes.drain(..);
}
}
pub trait TestNetNode: Clone + Future