Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2949849
Initial commit
cecton Jun 15, 2020
8672ca5
Change branch
cecton Jun 15, 2020
b3eed66
WIP
cecton Jun 19, 2020
e960f56
WIP
cecton Jun 22, 2020
54f9db5
WIP
cecton Jun 22, 2020
bb244ab
WIP
cecton Jun 23, 2020
b32f136
CLEANUP
cecton Jun 23, 2020
98479fd
WIP
cecton Jun 23, 2020
3342c2e
WIP
cecton Jun 23, 2020
cbc7479
WIP
cecton Jun 26, 2020
4dc2222
WIP
cecton Jun 30, 2020
614bfaf
WIP
cecton Jun 30, 2020
24eced7
WIP
cecton Jul 1, 2020
f163df5
Merge remote-tracking branch 'origin/master' into cecton-fix-int-test-3
cecton Jul 1, 2020
d00411a
Switch substrate branch to cumulus-branch
cecton Jul 1, 2020
1ee7240
WIP
cecton Jul 1, 2020
eb996e0
WIP
cecton Jul 2, 2020
4278565
change branch
cecton Jul 2, 2020
d8b2855
adapt code
cecton Jul 2, 2020
ea8e3f0
Merge commit 82db23f2ed78bfd1f9829563a1cfcb918215474d (conflicts)
cecton Jul 9, 2020
51183c9
Merge commit 5cac590a4b13004df5eec8dbe9a3c24f6d21a15e (no conflict)
cecton Jul 9, 2020
6ad5d6b
Merge commit 416c97030c08eb46dfe1372e408e0b23a66183a0 (conflicts)
cecton Jul 9, 2020
87650dd
Merge commit 03205eb60104499eba0634f8a61d707326d03f86 (conflicts)
cecton Jul 9, 2020
0ab83a5
adapt code
cecton Jul 9, 2020
b405a22
Update branches
cecton Jul 9, 2020
9b4a31b
adapt code
cecton Jul 9, 2020
eaaf7a9
CLEANUP
cecton Jul 10, 2020
d186bfb
replace asyncstd by tokio
cecton Jul 10, 2020
533b879
CLEANUP
cecton Jul 10, 2020
aaef29d
CLEANUP
cecton Jul 10, 2020
712f428
CLEANUP
cecton Jul 10, 2020
2deb133
CLEANUP
cecton Jul 10, 2020
8c16c1b
fmt
cecton Jul 10, 2020
ea1ff8e
CLEANUP
cecton Jul 10, 2020
792faca
CLEANUP
cecton Jul 10, 2020
325a217
Applied suggestion and added prefix for debugging & cleanup
cecton Jul 14, 2020
3016f8d
Revert branch change
cecton Jul 23, 2020
7f840ff
Adapt code to current substrate
cecton Jul 23, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
615 changes: 296 additions & 319 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions parachain-upgrade/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ cumulus-runtime = { path = "../runtime", default-features = false }
parachain = { package = "polkadot-parachain", git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false }

# Substrate dependencies
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", version = "2.0.0-dev", default-features = false }
sp-inherents = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
sp-version = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", version = "2.0.0-dev", default-features = false }
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
sp-version = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }

# Other Dependencies
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"]}
serde = { version = "1.0.101", optional = true, features = ["derive"] }

[dev-dependencies]
sp-externalities = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
sp-version = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
sp-externalities = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
sp-version = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }

[features]
default = ['std']
Expand Down
23 changes: 10 additions & 13 deletions test/parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,29 @@ cumulus-primitives = { path = "../../primitives" }

# Polkadot dependencies
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
polkadot-collator = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
polkadot-test-service = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }

[build-dependencies]
substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }

[dev-dependencies]
assert_cmd = "0.12"
nix = "0.17"
tempfile = "3.1"
jsonrpsee = "0.1"
async-std = { version = "1.2.0", features = [ "attributes" ] }
hex = "0.4"
serde_json = "1.0"
rand = "0.7.3"
tokio = { version = "0.2.13", features = ["macros"] }

# Polkadot dependencies
polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
polkadot-test-runtime = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
polkadot-test-runtime-client = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
polkadot-test-service = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }

# Substrate dependencies
substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
pallet-grandpa = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-version = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
substrate-test-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
6 changes: 0 additions & 6 deletions test/parachain/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ pub enum Subcommand {
/// Export the genesis state of the parachain.
#[structopt(name = "export-genesis-state")]
ExportGenesisState(ExportGenesisStateCommand),

/// Run Polkadot for testing purpose
Polkadot(polkadot_cli::Cli),

#[structopt(name = "validation-worker", setting = structopt::clap::AppSettings::Hidden)]
PolkadotValidationWorker(polkadot_cli::ValidationWorkerCommand),
}

/// Command for exporting the genesis state of the parachain
Expand Down
37 changes: 4 additions & 33 deletions test/parachain/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ impl SubstrateCli for PolkadotCli {
}
}

fn generate_genesis_state(para_id: ParaId) -> Result<Block> {
/// Generate the genesis block
pub fn generate_genesis_state(para_id: ParaId) -> Result<Block> {
let storage = (&chain_spec::get_chain_spec(para_id)).build_storage()?;

let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
Expand Down Expand Up @@ -156,7 +157,7 @@ pub fn run() -> Result<()> {
})
}
Some(Subcommand::ExportGenesisState(params)) => {
sc_cli::init_logger("", &<sc_cli::LogRotationOpt as structopt::StructOpt>::from_args())?;
sc_cli::init_logger("");

let block = generate_genesis_state(params.parachain_id.into())?;
let header_hex = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
Expand All @@ -169,37 +170,6 @@ pub fn run() -> Result<()> {

Ok(())
}
Some(Subcommand::Polkadot(polkadot_cli)) => {
let runner = polkadot_cli.create_runner(&polkadot_cli.run.base)?;
let authority_discovery_enabled = polkadot_cli.run.authority_discovery_enabled;
let grandpa_pause = if polkadot_cli.run.grandpa_pause.is_empty() {
None
} else {
Some((
polkadot_cli.run.grandpa_pause[0],
polkadot_cli.run.grandpa_pause[1],
))
};

runner.run_node_until_exit(|config| match config.role {
Role::Light => polkadot_service::polkadot_new_light(config).map(|r| r.0),
_ => polkadot_service::polkadot_new_full(
config,
None,
None,
authority_discovery_enabled,
6000,
grandpa_pause,
)
.map(|(s, _, _)| s),
})
}
Some(Subcommand::PolkadotValidationWorker(cmd)) => {
sc_cli::init_logger("", &<sc_cli::LogRotationOpt as structopt::StructOpt>::from_args())?;
polkadot_service::run_validation_worker(&cmd.mem_id)?;

Ok(())
}
None => {
let runner = cli.create_runner(&*cli.run)?;

Expand Down Expand Up @@ -238,6 +208,7 @@ pub fn run() -> Result<()> {
info!("Parachain genesis state: {}", genesis_state);

crate::service::run_collator(config, key, polkadot_config, id)
.map(|x| x.task_manager)
})
}
}
Expand Down
211 changes: 211 additions & 0 deletions test/parachain/src/integration_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
// Copyright 2020 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 <http://www.gnu.org/licenses/>.

use codec::Encode;
use futures::{
future::{self, FutureExt},
pin_mut, select,
};
use polkadot_primitives::parachain::{Id as ParaId, Info, Scheduling};
use polkadot_runtime_common::registrar;
use polkadot_test_runtime_client::Sr25519Keyring;
use sc_client_api::execution_extensions::ExecutionStrategies;
use sc_informant::OutputFormat;
use sc_network::{config::TransportConfig, multiaddr};
use sc_service::{
config::{
DatabaseConfig, KeystoreConfig, MultiaddrWithPeerId, NetworkConfiguration,
WasmExecutionMethod,
},
BasePath, Configuration, Error as ServiceError, Role, TaskExecutor,
};
use std::{sync::Arc, time::Duration};
use substrate_test_client::BlockchainEventsExt;
use substrate_test_runtime_client::AccountKeyring::*;
use tokio::{spawn, time::delay_for as sleep};

static INTEGRATION_TEST_ALLOWED_TIME: Option<&str> = option_env!("INTEGRATION_TEST_ALLOWED_TIME");

#[tokio::test]
#[ignore]
async fn integration_test() {
let task_executor: TaskExecutor = (|fut, _| {
spawn(fut);
})
.into();

// start alice
let mut alice =
polkadot_test_service::run_test_node(task_executor.clone(), Alice, || {}, vec![]);

// start bob
let mut bob = polkadot_test_service::run_test_node(
task_executor.clone(),
Bob,
|| {},
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 para_id = ParaId::from(100);

future::join(alice.wait_for_blocks(2), bob.wait_for_blocks(2)).await;

// export genesis state
let genesis_state = crate::command::generate_genesis_state(para_id)
.unwrap()
.encode();

// create and sign transaction
let function = polkadot_test_runtime::Call::Sudo(pallet_sudo::Call::sudo(Box::new(
polkadot_test_runtime::Call::Registrar(registrar::Call::register_para(
para_id,
Info {
scheduling: Scheduling::Always,
},
parachain_runtime::WASM_BINARY.to_vec().into(),
genesis_state.into(),
)),
)));

// register parachain
let _ = alice.call_function(function, Alice).await.unwrap();

// run cumulus charlie
let key = Arc::new(sp_core::Pair::from_seed(&[10; 32]));
let mut polkadot_config = polkadot_test_service::node_config(
|| {},
task_executor.clone(),
Charlie,
vec![alice.addr.clone(), bob.addr.clone()],
);
use std::net::{Ipv4Addr, SocketAddr};
polkadot_config.rpc_http = Some(SocketAddr::new(Ipv4Addr::LOCALHOST.into(), 27016));
polkadot_config.rpc_methods = sc_service::config::RpcMethods::Unsafe;
let parachain_config =
parachain_config(task_executor.clone(), Charlie, vec![], para_id).unwrap();
let service =
crate::service::run_collator(parachain_config, key, polkadot_config, para_id).unwrap();
sleep(Duration::from_secs(3)).await;
service.client.wait_for_blocks(4).await;

alice.task_manager.terminate();
bob.task_manager.terminate();
}
.fuse();

pin_mut!(t1, t2);

select! {
_ = t1 => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general this is something that could be moved to polkadot-test-service as helper function. Especially the generation of t1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 you mean to substrate no? I could probably make a macro to will also handle the runtime using tokio like tokio::test but substrate::test (will do async + timeout for the test)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this PR to address this: paritytech/substrate#6651

panic!("the test took too long, maybe no parachain blocks have been produced");
},
_ = t2 => {},
}
}

pub fn parachain_config(
task_executor: TaskExecutor,
key: Sr25519Keyring,
boot_nodes: Vec<MultiaddrWithPeerId>,
para_id: ParaId,
) -> Result<Configuration, ServiceError> {
let base_path = BasePath::new_temp_dir()?;
let root = base_path.path().to_path_buf();
let role = Role::Authority {
sentry_nodes: Vec::new(),
};
let key_seed = key.to_seed();
let spec = crate::chain_spec::get_chain_spec(para_id);

let mut network_config = NetworkConfiguration::new(
format!("Cumulus Test Node for: {}", key_seed),
"network/test/0.1",
Default::default(),
None,
);
let informant_output_format = OutputFormat {
enable_color: false,
prefix: format!("[{}] ", key_seed),
};

network_config.boot_nodes = boot_nodes;

network_config.allow_non_globals_in_dht = true;

network_config
.listen_addresses
.push(multiaddr::Protocol::Memory(rand::random()).into());

network_config.transport = TransportConfig::MemoryOnly;

Ok(Configuration {
impl_name: "cumulus-test-node".to_string(),
impl_version: "0.1".to_string(),
role,
task_executor,
transaction_pool: Default::default(),
network: network_config,
keystore: KeystoreConfig::Path {
path: root.join("key"),
password: None,
},
database: DatabaseConfig::RocksDb {
path: root.join("db"),
cache_size: 128,
},
state_cache_size: 16777216,
state_cache_child_ratio: None,
pruning: Default::default(),
chain_spec: Box::new(spec),
wasm_method: WasmExecutionMethod::Interpreted,
// NOTE: we enforce the use of the native runtime to make the errors more debuggable
execution_strategies: ExecutionStrategies {
syncing: sc_client_api::ExecutionStrategy::NativeWhenPossible,
importing: sc_client_api::ExecutionStrategy::NativeWhenPossible,
block_construction: sc_client_api::ExecutionStrategy::NativeWhenPossible,
offchain_worker: sc_client_api::ExecutionStrategy::NativeWhenPossible,
other: sc_client_api::ExecutionStrategy::NativeWhenPossible,
},
rpc_http: None,
rpc_ws: None,
rpc_ipc: None,
rpc_ws_max_connections: None,
rpc_cors: None,
rpc_methods: Default::default(),
prometheus_config: None,
telemetry_endpoints: None,
telemetry_external_transport: None,
default_heap_pages: None,
offchain_worker: Default::default(),
force_authoring: false,
disable_grandpa: false,
dev_key_seed: Some(key_seed),
tracing_targets: None,
tracing_receiver: Default::default(),
max_runtime_instances: 8,
announce_block: true,
base_path: Some(base_path),
informant_output_format,
})
}
2 changes: 2 additions & 0 deletions test/parachain/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ mod chain_spec;
mod service;
mod cli;
mod command;
#[cfg(test)]
mod integration_test;

fn main() -> sc_cli::Result<()> {
command::run()
Expand Down
Loading