diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index b57ca6e54e..d94d228919 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -4904,7 +4904,7 @@ dependencies = [ "sp-blockchain 2.0.0", "sp-core 2.0.0", "sp-runtime 2.0.0", - "substrate-test-runtime-client 2.0.0", + "sp-test-primitives 2.0.0", ] [[package]] @@ -5044,17 +5044,14 @@ name = "sc-client-api" version = "2.0.0" dependencies = [ "derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "kvdb-memorydb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sc-client-db 2.0.0", "sc-executor 2.0.0", "sc-telemetry 2.0.0", "sp-api 2.0.0", @@ -5064,7 +5061,6 @@ dependencies = [ "sp-externalities 2.0.0", "sp-inherents 2.0.0", "sp-keyring 2.0.0", - "sp-panic-handler 2.0.0", "sp-runtime 2.0.0", "sp-state-machine 2.0.0", "sp-std 2.0.0", @@ -5072,8 +5068,6 @@ dependencies = [ "sp-transaction-pool-api 2.0.0", "sp-trie 2.0.0", "sp-version 2.0.0", - "substrate-test-runtime-client 2.0.0", - "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -5122,6 +5116,7 @@ dependencies = [ "sc-executor 2.0.0", "sc-keystore 2.0.0", "sc-network 2.0.0", + "sc-network-test 2.0.0", "sc-service 2.0.0", "sc-telemetry 2.0.0", "sp-api 2.0.0", @@ -5169,6 +5164,7 @@ dependencies = [ "sc-executor 2.0.0", "sc-keystore 2.0.0", "sc-network 2.0.0", + "sc-network-test 2.0.0", "sc-service 2.0.0", "sc-telemetry 2.0.0", "schnorrkel 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5259,8 +5255,6 @@ dependencies = [ "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sc-client-api 2.0.0", - "sc-offchain 2.0.0", "sc-runtime-test 2.0.0", "sp-core 2.0.0", "sp-externalities 2.0.0", @@ -5298,6 +5292,7 @@ dependencies = [ "sc-client-api 2.0.0", "sc-keystore 2.0.0", "sc-network 2.0.0", + "sc-network-test 2.0.0", "sc-telemetry 2.0.0", "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", "sp-api 2.0.0", @@ -5374,8 +5369,8 @@ dependencies = [ "sp-core 2.0.0", "sp-keyring 2.0.0", "sp-runtime 2.0.0", + "sp-test-primitives 2.0.0", "substrate-test-client 2.0.0", - "substrate-test-runtime 2.0.0", "substrate-test-runtime-client 2.0.0", "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5385,6 +5380,33 @@ dependencies = [ "zeroize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "sc-network-test" +version = "2.0.0" +dependencies = [ + "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "sc-block-builder 2.0.0", + "sc-client 2.0.0", + "sc-client-api 2.0.0", + "sc-network 2.0.0", + "sp-blockchain 2.0.0", + "sp-consensus 2.0.0", + "sp-consensus-babe 2.0.0", + "sp-core 2.0.0", + "sp-runtime 2.0.0", + "substrate-test-runtime 2.0.0", + "substrate-test-runtime-client 2.0.0", + "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "sc-offchain" version = "2.0.0" @@ -6090,8 +6112,8 @@ dependencies = [ "sp-inherents 2.0.0", "sp-runtime 2.0.0", "sp-std 2.0.0", + "sp-test-primitives 2.0.0", "sp-version 2.0.0", - "substrate-test-runtime-client 2.0.0", ] [[package]] @@ -6326,7 +6348,6 @@ dependencies = [ "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "primitive-types 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustversion 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sc-executor 2.0.0", "sp-core 2.0.0", "sp-externalities 2.0.0", "sp-io 2.0.0", @@ -6350,6 +6371,18 @@ dependencies = [ "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "sp-runtime-interface-test" +version = "2.0.0" +dependencies = [ + "sc-executor 2.0.0", + "sp-core 2.0.0", + "sp-io 2.0.0", + "sp-runtime-interface 2.0.0", + "sp-runtime-interface-test-wasm 2.0.0", + "sp-state-machine 2.0.0", +] + [[package]] name = "sp-runtime-interface-test-wasm" version = "2.0.0" diff --git a/substrate/Cargo.toml b/substrate/Cargo.toml index d1b105ab8b..6b59b68e1c 100644 --- a/substrate/Cargo.toml +++ b/substrate/Cargo.toml @@ -30,6 +30,7 @@ members = [ "client/tracing", "client/keystore", "client/network", + "client/network/test", "client/offchain", "client/peerset", "client/rpc-servers", @@ -114,6 +115,7 @@ members = [ "primitives/runtime-interface", "primitives/runtime-interface/proc-macro", "primitives/runtime-interface/test-wasm", + "primitives/runtime-interface/test", "primitives/serializer", "primitives/session", "primitives/api", diff --git a/substrate/client/api/Cargo.toml b/substrate/client/api/Cargo.toml index 6aa4a144f6..b8a77bde07 100644 --- a/substrate/client/api/Cargo.toml +++ b/substrate/client/api/Cargo.toml @@ -31,10 +31,4 @@ trie = { package = "sp-trie", path = "../../primitives/trie" } txpool-api = { package = "sp-transaction-pool-api", path = "../../primitives/transaction-pool" } [dev-dependencies] -env_logger = "0.7.0" -tempfile = "3.1.0" -client-db = { package = "sc-client-db", path = "../db", features = ["kvdb-rocksdb"] } -test-primitives = { package = "sp-test-primitives", path = "../../primitives/test-primitives" } -test-client = { package = "substrate-test-runtime-client", path = "../../test/utils/runtime/client" } -kvdb-memorydb = "0.1.2" -panic-handler = { package = "sp-panic-handler", path = "../../primitives/panic-handler" } +test-primitives = { package = "sp-test-primitives", path = "../../primitives/test-primitives" } \ No newline at end of file diff --git a/substrate/client/authority-discovery/Cargo.toml b/substrate/client/authority-discovery/Cargo.toml index 330165e0aa..72e4345166 100644 --- a/substrate/client/authority-discovery/Cargo.toml +++ b/substrate/client/authority-discovery/Cargo.toml @@ -30,5 +30,5 @@ sp-runtime = { path = "../../primitives/runtime" } env_logger = "0.7.0" parking_lot = "0.9.0" peerset = { package = "sc-peerset", path = "../peerset" } -test-client = { package = "substrate-test-runtime-client", path = "../../test/utils/runtime/client" } +sp-test-primitives = { path = "../../primitives/test-primitives" } sp-api = { path = "../../primitives/api" } diff --git a/substrate/client/authority-discovery/src/lib.rs b/substrate/client/authority-discovery/src/lib.rs index 80bf971f1d..a70683f682 100644 --- a/substrate/client/authority-discovery/src/lib.rs +++ b/substrate/client/authority-discovery/src/lib.rs @@ -555,7 +555,7 @@ mod tests { use sp_runtime::traits::Zero; use sp_runtime::traits::{ApiRef, Block as BlockT, NumberFor, ProvideRuntimeApi}; use std::sync::{Arc, Mutex}; - use test_client::runtime::Block; + use sp_test_primitives::Block; #[test] fn interval_at_with_start_now() { diff --git a/substrate/client/consensus/aura/Cargo.toml b/substrate/client/consensus/aura/Cargo.toml index 181b144333..5823a6ce6b 100644 --- a/substrate/client/consensus/aura/Cargo.toml +++ b/substrate/client/consensus/aura/Cargo.toml @@ -34,7 +34,8 @@ sc-telemetry = { path = "../../telemetry" } [dev-dependencies] keyring = { package = "sp-keyring", path = "../../../primitives/keyring" } sc-executor = { path = "../../executor" } -network = { package = "sc-network", path = "../../network", features = ["test-helpers"]} +sc-network = { path = "../../network" } +sc-network-test = { path = "../../network/test" } service = { package = "sc-service", path = "../../service" } test-client = { package = "substrate-test-runtime-client", path = "../../../test/utils/runtime/client" } tokio = "0.1.22" diff --git a/substrate/client/consensus/aura/src/lib.rs b/substrate/client/consensus/aura/src/lib.rs index 745c0bebe2..c9be311b11 100644 --- a/substrate/client/consensus/aura/src/lib.rs +++ b/substrate/client/consensus/aura/src/lib.rs @@ -748,10 +748,9 @@ pub fn import_queue( mod tests { use super::*; use consensus_common::NoNetwork as DummyOracle; - use network::test::*; - use network::test::{Block as TestBlock, PeersClient, PeersFullClient}; + use sc_network_test::{Block as TestBlock, *}; use sp_runtime::traits::{Block as BlockT, DigestFor}; - use network::config::ProtocolConfig; + use sc_network::config::ProtocolConfig; use parking_lot::Mutex; use tokio::runtime::current_thread; use keyring::sr25519::Keyring; diff --git a/substrate/client/consensus/babe/Cargo.toml b/substrate/client/consensus/babe/Cargo.toml index 8c61f10b68..8f68da5bbc 100644 --- a/substrate/client/consensus/babe/Cargo.toml +++ b/substrate/client/consensus/babe/Cargo.toml @@ -43,7 +43,8 @@ derive_more = "0.99.2" [dev-dependencies] keyring = { package = "sp-keyring", path = "../../../primitives/keyring" } sc-executor = { path = "../../executor" } -network = { package = "sc-network", path = "../../network", features = ["test-helpers"]} +sc-network = { path = "../../network" } +sc-network-test = { path = "../../network/test" } service = { package = "sc-service", path = "../../service" } test-client = { package = "substrate-test-runtime-client", path = "../../../test/utils/runtime/client" } block-builder = { package = "sc-block-builder", path = "../../block-builder" } diff --git a/substrate/client/consensus/babe/src/tests.rs b/substrate/client/consensus/babe/src/tests.rs index 56482ef5fd..48b58eacd8 100644 --- a/substrate/client/consensus/babe/src/tests.rs +++ b/substrate/client/consensus/babe/src/tests.rs @@ -28,11 +28,10 @@ use consensus_common::NoNetwork as DummyOracle; use consensus_common::import_queue::{ BoxBlockImport, BoxJustificationImport, BoxFinalityProofImport, }; -use network::test::*; -use network::test::{Block as TestBlock, PeersClient}; -use network::config::BoxFinalityProofRequestBuilder; +use sc_network_test::*; +use sc_network_test::{Block as TestBlock, PeersClient}; +use sc_network::config::{BoxFinalityProofRequestBuilder, ProtocolConfig}; use sp_runtime::{generic::DigestItem, traits::{Block as BlockT, DigestFor}}; -use network::config::ProtocolConfig; use tokio::runtime::current_thread; use client_api::BlockchainEvents; use test_client; diff --git a/substrate/client/executor/Cargo.toml b/substrate/client/executor/Cargo.toml index d40e426e3f..6a0723099b 100644 --- a/substrate/client/executor/Cargo.toml +++ b/substrate/client/executor/Cargo.toml @@ -39,8 +39,6 @@ hex-literal = "0.2.1" runtime-test = { package = "sc-runtime-test", path = "runtime-test" } test-runtime = { package = "substrate-test-runtime", path = "../../test/utils/runtime" } runtime-interface = { package = "sp-runtime-interface", path = "../../primitives/runtime-interface" } -client-api = { package = "sc-client-api", path = "../api" } -sc-offchain = { path = "../offchain/" } state_machine = { package = "sp-state-machine", path = "../../primitives/state-machine" } test-case = "0.3.3" diff --git a/substrate/client/finality-grandpa/Cargo.toml b/substrate/client/finality-grandpa/Cargo.toml index 121491fd3d..1ba0cfa766 100644 --- a/substrate/client/finality-grandpa/Cargo.toml +++ b/substrate/client/finality-grandpa/Cargo.toml @@ -31,7 +31,8 @@ grandpa = { package = "finality-grandpa", version = "0.10.1", features = ["deriv [dev-dependencies] grandpa = { package = "finality-grandpa", version = "0.10.1", features = ["derive-codec", "test-helpers"] } -network = { package = "sc-network", path = "../network", features = ["test-helpers"] } +network = { package = "sc-network", path = "../network" } +sc-network-test = { path = "../network/test" } keyring = { package = "sp-keyring", path = "../../primitives/keyring" } test-client = { package = "substrate-test-runtime-client", path = "../../test/utils/runtime/client"} babe_primitives = { package = "sp-consensus-babe", path = "../../primitives/consensus/babe" } diff --git a/substrate/client/finality-grandpa/src/communication/gossip.rs b/substrate/client/finality-grandpa/src/communication/gossip.rs index af08e76157..298d68d58f 100644 --- a/substrate/client/finality-grandpa/src/communication/gossip.rs +++ b/substrate/client/finality-grandpa/src/communication/gossip.rs @@ -1506,7 +1506,7 @@ mod tests { use super::*; use super::environment::SharedVoterSetState; use network_gossip::Validator as GossipValidatorT; - use network::test::Block; + use sc_network_test::Block; use primitives::{crypto::Public, H256}; // some random config (not really needed) diff --git a/substrate/client/finality-grandpa/src/communication/tests.rs b/substrate/client/finality-grandpa/src/communication/tests.rs index f2a2276a47..86bbdb8f64 100644 --- a/substrate/client/finality-grandpa/src/communication/tests.rs +++ b/substrate/client/finality-grandpa/src/communication/tests.rs @@ -19,7 +19,7 @@ use futures::sync::mpsc; use futures::prelude::*; use network::consensus_gossip as network_gossip; -use network::test::{Block, Hash}; +use sc_network_test::{Block, Hash}; use network_gossip::Validator; use tokio::runtime::current_thread; use std::sync::Arc; diff --git a/substrate/client/finality-grandpa/src/tests.rs b/substrate/client/finality-grandpa/src/tests.rs index d9010bd02b..ece9bf167b 100644 --- a/substrate/client/finality-grandpa/src/tests.rs +++ b/substrate/client/finality-grandpa/src/tests.rs @@ -18,8 +18,8 @@ use super::*; use environment::HasVoted; -use network::test::{Block, DummySpecialization, Hash, TestNetFactory, Peer, PeersClient}; -use network::test::{PassThroughVerifier}; +use sc_network_test::{Block, DummySpecialization, Hash, TestNetFactory, Peer, PeersClient}; +use sc_network_test::{PassThroughVerifier}; use network::config::{ProtocolConfig, Roles, BoxFinalityProofRequestBuilder}; use parking_lot::Mutex; use futures03::{StreamExt as _, TryStreamExt as _}; @@ -1553,7 +1553,7 @@ fn voter_catches_up_to_latest_round_when_behind() { #[test] fn grandpa_environment_respects_voting_rules() { use grandpa::Chain; - use network::test::TestClient; + use sc_network_test::TestClient; let peers = &[Ed25519Keyring::Alice]; let voters = make_ids(peers); diff --git a/substrate/client/network/Cargo.toml b/substrate/client/network/Cargo.toml index 98ca2b610c..ac00c48cd7 100644 --- a/substrate/client/network/Cargo.toml +++ b/substrate/client/network/Cargo.toml @@ -51,12 +51,11 @@ zeroize = "1.0.0" babe-primitives = { package = "sp-consensus-babe", path = "../../primitives/consensus/babe" } [dev-dependencies] +sp-test-primitives = { path = "../../primitives/test-primitives" } env_logger = "0.7.0" keyring = { package = "sp-keyring", path = "../../primitives/keyring" } quickcheck = "0.9.0" rand = "0.7.2" -test-client = { package = "substrate-test-runtime-client", path = "../../test/utils/runtime/client" } -test_runtime = { package = "substrate-test-runtime", path = "../../test/utils/runtime" } tempfile = "3.1.0" tokio = "0.1.22" diff --git a/substrate/client/network/src/lib.rs b/substrate/client/network/src/lib.rs index 05c8a1dc86..755ae803fe 100644 --- a/substrate/client/network/src/lib.rs +++ b/substrate/client/network/src/lib.rs @@ -181,15 +181,12 @@ mod utils; pub mod config; pub mod error; -#[cfg(any(test, feature = "test-helpers"))] -pub mod test; - pub use chain::{Client as ClientHandle, FinalityProofProvider}; pub use service::{ NetworkService, NetworkWorker, TransactionPool, ExHashT, ReportHandle, NetworkStateInfo, }; -pub use protocol::{PeerInfo, Context, consensus_gossip, message, specialization}; +pub use protocol::{PeerInfo, Context, ProtocolConfig, consensus_gossip, message, specialization}; pub use protocol::event::{Event, DhtEvent}; pub use protocol::sync::SyncState; pub use libp2p::{Multiaddr, PeerId}; diff --git a/substrate/client/network/src/protocol/legacy_proto/tests.rs b/substrate/client/network/src/protocol/legacy_proto/tests.rs index 08c3a47c0e..32af2198b7 100644 --- a/substrate/client/network/src/protocol/legacy_proto/tests.rs +++ b/substrate/client/network/src/protocol/legacy_proto/tests.rs @@ -27,7 +27,7 @@ use rand::seq::SliceRandom; use std::{io, time::Duration, time::Instant}; use crate::message::Message; use crate::protocol::legacy_proto::{LegacyProto, LegacyProtoOut}; -use test_client::runtime::Block; +use sp_test_primitives::Block; /// Builds two nodes that have each other as bootstrap nodes. /// This is to be used only for testing, and a panic will happen if something goes wrong. diff --git a/substrate/client/network/src/protocol/light_dispatch.rs b/substrate/client/network/src/protocol/light_dispatch.rs index ef240cbf06..869fd703ca 100644 --- a/substrate/client/network/src/protocol/light_dispatch.rs +++ b/substrate/client/network/src/protocol/light_dispatch.rs @@ -686,7 +686,7 @@ pub mod tests { use crate::message::{self, BlockAttributes, Direction, FromBlock, RequestId}; use libp2p::PeerId; use super::{REQUEST_TIMEOUT, LightDispatch, LightDispatchNetwork, RequestData, StorageProof}; - use test_client::runtime::{changes_trie_config, Block, Extrinsic, Header}; + use sp_test_primitives::{changes_trie_config, Block, Extrinsic, Header}; struct DummyFetchChecker { ok: bool } diff --git a/substrate/client/network/src/protocol/sync/extra_requests.rs b/substrate/client/network/src/protocol/sync/extra_requests.rs index 21a29975c0..ecd6fdca99 100644 --- a/substrate/client/network/src/protocol/sync/extra_requests.rs +++ b/substrate/client/network/src/protocol/sync/extra_requests.rs @@ -288,7 +288,7 @@ mod tests { use rand::Rng; use std::collections::{HashMap, HashSet}; use super::*; - use test_client::runtime::{Block, BlockNumber, Hash}; + use sp_test_primitives::{Block, BlockNumber, Hash}; #[test] fn requests_are_processed_in_order() { diff --git a/substrate/client/network/test/Cargo.toml b/substrate/client/network/test/Cargo.toml new file mode 100644 index 0000000000..3ebb7ac6b4 --- /dev/null +++ b/substrate/client/network/test/Cargo.toml @@ -0,0 +1,30 @@ +[package] +description = "Integration tests for Substrate network protocol" +name = "sc-network-test" +version = "2.0.0" +license = "GPL-3.0" +authors = ["Parity Technologies "] +edition = "2018" + +[dependencies] +sc-network = { path = "../" } +log = "0.4.8" +parking_lot = "0.9.0" +futures = "0.1.29" +futures03 = { package = "futures", version = "0.3.1", features = ["compat"] } +futures-timer = "0.4.0" +rand = "0.7.2" +libp2p = { version = "0.13.0", default-features = false, features = ["libp2p-websocket"] } +consensus = { package = "sp-consensus", path = "../../../primitives/consensus/common" } +client = { package = "sc-client", path = "../../" } +client-api = { package = "sc-client-api", path = "../../api" } +sp-blockchain = { path = "../../../primitives/blockchain" } +sp-runtime = { path = "../../../primitives/runtime" } +primitives = { package = "sp-core", path = "../../../primitives/core" } +block-builder = { package = "sc-block-builder", path = "../../block-builder" } +babe-primitives = { package = "sp-consensus-babe", path = "../../../primitives/consensus/babe" } +env_logger = "0.7.0" +test-client = { package = "substrate-test-runtime-client", path = "../../../test/utils/runtime/client" } +test_runtime = { package = "substrate-test-runtime", path = "../../../test/utils/runtime" } +tempfile = "3.1.0" +tokio = "0.1.22" diff --git a/substrate/client/network/src/test/block_import.rs b/substrate/client/network/test/src/block_import.rs similarity index 100% rename from substrate/client/network/src/test/block_import.rs rename to substrate/client/network/test/src/block_import.rs diff --git a/substrate/client/network/src/test/mod.rs b/substrate/client/network/test/src/lib.rs similarity index 97% rename from substrate/client/network/src/test/mod.rs rename to substrate/client/network/test/src/lib.rs index f016ef99d8..cc81789e24 100644 --- a/substrate/client/network/src/test/mod.rs +++ b/substrate/client/network/test/src/lib.rs @@ -24,9 +24,9 @@ mod sync; use std::collections::HashMap; use std::sync::Arc; -use crate::config::build_multiaddr; +use libp2p::build_multiaddr; use log::trace; -use crate::chain::FinalityProofProvider; +use sc_network::FinalityProofProvider; use sp_blockchain::{ Result as ClientResult, well_known_cache_keys::{self, Id as CacheKeyId}, }; @@ -38,7 +38,7 @@ use client_api::{ }; use block_builder::BlockBuilder; use client::LongestChain; -use crate::config::Roles; +use sc_network::config::Roles; use consensus::block_validation::DefaultBlockAnnounceValidator; use consensus::import_queue::BasicQueue; use consensus::import_queue::{ @@ -49,17 +49,17 @@ use consensus::Error as ConsensusError; use consensus::{BlockOrigin, ForkChoiceStrategy, BlockImportParams, BlockCheckParams, JustificationImport}; use futures::prelude::*; use futures03::{StreamExt as _, TryStreamExt as _}; -use crate::{NetworkWorker, NetworkService, ReportHandle, config::ProtocolId}; -use crate::config::{NetworkConfiguration, TransportConfig, BoxFinalityProofRequestBuilder}; +use sc_network::{NetworkWorker, NetworkService, ReportHandle, config::ProtocolId}; +use sc_network::config::{NetworkConfiguration, TransportConfig, BoxFinalityProofRequestBuilder}; use libp2p::PeerId; use parking_lot::Mutex; use primitives::H256; -use crate::protocol::{Context, ProtocolConfig}; +use sc_network::{Context, ProtocolConfig}; use sp_runtime::generic::{BlockId, OpaqueDigestItemId}; use sp_runtime::traits::{Block as BlockT, Header, NumberFor}; use sp_runtime::Justification; -use crate::service::TransactionPool; -use crate::specialization::NetworkSpecialization; +use sc_network::TransactionPool; +use sc_network::specialization::NetworkSpecialization; use test_client::{self, AccountKeyring}; pub use test_client::runtime::{Block, Extrinsic, Hash, Transfer}; @@ -67,13 +67,11 @@ pub use test_client::{TestClient, TestClientBuilder, TestClientBuilderExt}; type AuthorityId = babe_primitives::AuthorityId; -#[cfg(any(test, feature = "test-helpers"))] /// A Verifier that accepts all blocks and passes them on with the configured /// finality to be imported. #[derive(Clone)] pub struct PassThroughVerifier(pub bool); -#[cfg(any(test, feature = "test-helpers"))] /// This `Verifier` accepts all data as valid. impl Verifier for PassThroughVerifier { fn verify( @@ -117,7 +115,7 @@ impl NetworkSpecialization for DummySpecialization { &mut self, _ctx: &mut dyn Context, _peer_id: PeerId, - _status: crate::message::Status + _status: sc_network::message::Status ) {} fn on_disconnect(&mut self, _ctx: &mut dyn Context, _peer_id: PeerId) {} @@ -401,8 +399,8 @@ impl TransactionPool for EmptyTransactionPool { &self, _report_handle: ReportHandle, _who: PeerId, - _rep_change_good: crate::ReputationChange, - _rep_change_bad: crate::ReputationChange, + _rep_change_good: sc_network::ReputationChange, + _rep_change_bad: sc_network::ReputationChange, _transaction: Extrinsic ) {} @@ -563,7 +561,7 @@ pub trait TestNetFactory: Sized { let listen_addr = build_multiaddr![Memory(rand::random::())]; - let network = NetworkWorker::new(crate::config::Params { + let network = NetworkWorker::new(sc_network::config::Params { roles: config.roles, network_config: NetworkConfiguration { listen_addresses: vec![listen_addr.clone()], @@ -637,7 +635,7 @@ pub trait TestNetFactory: Sized { let listen_addr = build_multiaddr![Memory(rand::random::())]; - let network = NetworkWorker::new(crate::config::Params { + let network = NetworkWorker::new(sc_network::config::Params { roles: config.roles, network_config: NetworkConfiguration { listen_addresses: vec![listen_addr.clone()], diff --git a/substrate/client/network/src/test/sync.rs b/substrate/client/network/test/src/sync.rs similarity index 99% rename from substrate/client/network/src/test/sync.rs rename to substrate/client/network/test/src/sync.rs index 9868bd0ed2..b4e166be67 100644 --- a/substrate/client/network/src/test/sync.rs +++ b/substrate/client/network/test/src/sync.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -use crate::config::Roles; +use sc_network::config::Roles; use consensus::BlockOrigin; use futures03::TryFutureExt as _; use std::time::Duration; diff --git a/substrate/primitives/consensus/common/Cargo.toml b/substrate/primitives/consensus/common/Cargo.toml index ea2ee3891c..128d42c20c 100644 --- a/substrate/primitives/consensus/common/Cargo.toml +++ b/substrate/primitives/consensus/common/Cargo.toml @@ -20,7 +20,7 @@ codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive parking_lot = "0.9.0" [dev-dependencies] -test-client = { package = "substrate-test-runtime-client", path = "../../../test/utils/runtime/client" } +sp-test-primitives = { path = "../../test-primitives" } [features] default = [] diff --git a/substrate/primitives/consensus/common/src/import_queue/buffered_link.rs b/substrate/primitives/consensus/common/src/import_queue/buffered_link.rs index 70304bbe27..4772af92f1 100644 --- a/substrate/primitives/consensus/common/src/import_queue/buffered_link.rs +++ b/substrate/primitives/consensus/common/src/import_queue/buffered_link.rs @@ -23,7 +23,7 @@ //! ``` //! use sp_consensus::import_queue::Link; //! # use sp_consensus::import_queue::buffered_link::buffered_link; -//! # use test_client::runtime::Block; +//! # use sp_test_primitives::Block; //! # struct DummyLink; impl Link for DummyLink {} //! # let mut my_link = DummyLink; //! let (mut tx, mut rx) = buffered_link::(); @@ -161,7 +161,7 @@ impl BufferedLinkReceiver { #[cfg(test)] mod tests { - use test_client::runtime::Block; + use sp_test_primitives::Block; #[test] fn is_closed() { diff --git a/substrate/primitives/runtime-interface/Cargo.toml b/substrate/primitives/runtime-interface/Cargo.toml index 704ae1b243..c451407681 100644 --- a/substrate/primitives/runtime-interface/Cargo.toml +++ b/substrate/primitives/runtime-interface/Cargo.toml @@ -15,7 +15,6 @@ static_assertions = "1.0.0" primitive-types = { version = "0.6.1", default-features = false } [dev-dependencies] -executor = { package = "sc-executor", path = "../../client/executor" } test-wasm = { package = "sp-runtime-interface-test-wasm", path = "test-wasm" } state_machine = { package = "sp-state-machine", path = "../../primitives/state-machine" } primitives = { package = "sp-core", path = "../core" } diff --git a/substrate/primitives/runtime-interface/src/lib.rs b/substrate/primitives/runtime-interface/src/lib.rs index ac172a9bc8..9baf47df27 100644 --- a/substrate/primitives/runtime-interface/src/lib.rs +++ b/substrate/primitives/runtime-interface/src/lib.rs @@ -260,97 +260,4 @@ pub type Pointer = *mut T; /// A pointer that can be used in a runtime interface function signature. #[cfg(feature = "std")] -pub type Pointer = wasm_interface::Pointer; - -#[cfg(test)] -mod tests { - use super::*; - use test_wasm::{WASM_BINARY, test_api::HostFunctions}; - use wasm_interface::HostFunctions as HostFunctionsT; - - type TestExternalities = state_machine::TestExternalities; - - fn call_wasm_method(method: &str) -> TestExternalities { - let mut ext = TestExternalities::default(); - let mut ext_ext = ext.ext(); - - executor::call_in_wasm::< - _, - ( - HF, - sp_io::SubstrateHostFunctions, - executor::deprecated_host_interface::SubstrateExternals - ) - >( - method, - &[], - executor::WasmExecutionMethod::Interpreted, - &mut ext_ext, - &WASM_BINARY[..], - 8, - ).expect(&format!("Executes `{}`", method)); - - ext - } - - #[test] - fn test_return_data() { - call_wasm_method::("test_return_data"); - } - - #[test] - fn test_return_option_data() { - call_wasm_method::("test_return_option_data"); - } - - #[test] - fn test_set_storage() { - let mut ext = call_wasm_method::("test_set_storage"); - - let expected = "world"; - assert_eq!(expected.as_bytes(), &ext.ext().storage("hello".as_bytes()).unwrap()[..]); - } - - #[test] - fn test_return_value_into_mutable_reference() { - call_wasm_method::("test_return_value_into_mutable_reference"); - } - - #[test] - fn test_get_and_return_array() { - call_wasm_method::("test_get_and_return_array"); - } - - #[test] - fn test_array_as_mutable_reference() { - call_wasm_method::("test_array_as_mutable_reference"); - } - - #[test] - fn test_return_input_public_key() { - call_wasm_method::("test_return_input_public_key"); - } - - #[test] - #[should_panic( - expected = "Other(\"Instantiation: Export ext_test_api_return_input_version_1 not found\")" - )] - fn host_function_not_found() { - call_wasm_method::<()>("test_return_data"); - } - - #[test] - #[should_panic( - expected = - "FunctionExecution(\"ext_test_api_invalid_utf8_data_version_1\", \ - \"Invalid utf8 data provided\")" - )] - fn test_invalid_utf8_data_should_return_an_error() { - call_wasm_method::("test_invalid_utf8_data_should_return_an_error"); - } - - #[test] - fn test_overwrite_native_function_implementation() { - call_wasm_method::("test_overwrite_native_function_implementation"); - } -} +pub type Pointer = wasm_interface::Pointer; \ No newline at end of file diff --git a/substrate/primitives/runtime-interface/test/Cargo.toml b/substrate/primitives/runtime-interface/test/Cargo.toml new file mode 100644 index 0000000000..269e8bc4aa --- /dev/null +++ b/substrate/primitives/runtime-interface/test/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "sp-runtime-interface-test" +version = "2.0.0" +authors = ["Parity Technologies "] +edition = "2018" +publish = false + +[dependencies] +sp-runtime-interface = { path = "../" } +executor = { package = "sc-executor", path = "../../../client/executor" } +test-wasm = { package = "sp-runtime-interface-test-wasm", path = "../test-wasm" } +state_machine = { package = "sp-state-machine", path = "../../../primitives/state-machine" } +primitives = { package = "sp-core", path = "../../core" } +sp-io = { path = "../../io" } diff --git a/substrate/primitives/runtime-interface/test/src/lib.rs b/substrate/primitives/runtime-interface/test/src/lib.rs new file mode 100644 index 0000000000..3de5e1ddc1 --- /dev/null +++ b/substrate/primitives/runtime-interface/test/src/lib.rs @@ -0,0 +1,107 @@ +// Copyright 2019 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 . + +//! Integration tests for runtime interface primitives + +use sp_runtime_interface::*; +use test_wasm::{WASM_BINARY, test_api::HostFunctions}; +use wasm_interface::HostFunctions as HostFunctionsT; + +type TestExternalities = state_machine::TestExternalities; + +fn call_wasm_method(method: &str) -> TestExternalities { + let mut ext = TestExternalities::default(); + let mut ext_ext = ext.ext(); + + executor::call_in_wasm::< + _, + ( + HF, + sp_io::SubstrateHostFunctions, + executor::deprecated_host_interface::SubstrateExternals + ) + >( + method, + &[], + executor::WasmExecutionMethod::Interpreted, + &mut ext_ext, + &WASM_BINARY[..], + 8, + ).expect(&format!("Executes `{}`", method)); + + ext +} + +#[test] +fn test_return_data() { + call_wasm_method::("test_return_data"); +} + +#[test] +fn test_return_option_data() { + call_wasm_method::("test_return_option_data"); +} + +#[test] +fn test_set_storage() { + let mut ext = call_wasm_method::("test_set_storage"); + + let expected = "world"; + assert_eq!(expected.as_bytes(), &ext.ext().storage("hello".as_bytes()).unwrap()[..]); +} + +#[test] +fn test_return_value_into_mutable_reference() { + call_wasm_method::("test_return_value_into_mutable_reference"); +} + +#[test] +fn test_get_and_return_array() { + call_wasm_method::("test_get_and_return_array"); +} + +#[test] +fn test_array_as_mutable_reference() { + call_wasm_method::("test_array_as_mutable_reference"); +} + +#[test] +fn test_return_input_public_key() { + call_wasm_method::("test_return_input_public_key"); +} + +#[test] +#[should_panic( + expected = "Other(\"Instantiation: Export ext_test_api_return_input_version_1 not found\")" +)] +fn host_function_not_found() { + call_wasm_method::<()>("test_return_data"); +} + +#[test] +#[should_panic( + expected = + "FunctionExecution(\"ext_test_api_invalid_utf8_data_version_1\", \ + \"Invalid utf8 data provided\")" +)] +fn test_invalid_utf8_data_should_return_an_error() { + call_wasm_method::("test_invalid_utf8_data_should_return_an_error"); +} + +#[test] +fn test_overwrite_native_function_implementation() { + call_wasm_method::("test_overwrite_native_function_implementation"); +} diff --git a/substrate/primitives/test-primitives/src/lib.rs b/substrate/primitives/test-primitives/src/lib.rs index 773e88066d..4acf10bbdf 100644 --- a/substrate/primitives/test-primitives/src/lib.rs +++ b/substrate/primitives/test-primitives/src/lib.rs @@ -76,3 +76,12 @@ pub type Digest = sp_runtime::generic::Digest; pub type Block = sp_runtime::generic::Block; /// A test block's header. pub type Header = sp_runtime::generic::Header; + + +/// Changes trie configuration (optionally) used in tests. +pub fn changes_trie_config() -> primitives::ChangesTrieConfiguration { + primitives::ChangesTrieConfiguration { + digest_interval: 4, + digest_levels: 2, + } +} \ No newline at end of file