mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 12:51:02 +00:00
Adds integration test based on adder collator (#1928)
* Adds integration test based on adder collator This adds an integration test for parachains that uses the adder collator. The test will start two relay chain nodes and one collator and waits until 4 blocks are build and enacted by the parachain. * Make sure the integration test is run in CI * Fix wasm compilation * Update parachain/test-parachains/adder/collator/src/lib.rs Co-authored-by: Sergei Shulepov <sergei@parity.io> * Update cli/src/command.rs Co-authored-by: Sergei Shulepov <sergei@parity.io>
This commit is contained in:
@@ -16,12 +16,14 @@
|
||||
|
||||
//! Collator for the adder test parachain.
|
||||
|
||||
use std::{pin::Pin, sync::{Arc, Mutex}, collections::HashMap};
|
||||
use std::{pin::Pin, sync::{Arc, Mutex}, collections::HashMap, time::Duration};
|
||||
use test_parachain_adder::{hash_state, BlockData, HeadData, execute};
|
||||
use futures::{Future, FutureExt};
|
||||
use polkadot_primitives::v1::{ValidationData, PoV, Hash};
|
||||
use futures_timer::Delay;
|
||||
use polkadot_primitives::v1::{ValidationData, PoV, Hash, CollatorId, CollatorPair};
|
||||
use polkadot_node_primitives::Collation;
|
||||
use codec::{Encode, Decode};
|
||||
use sp_core::Pair;
|
||||
|
||||
/// The amount we add when producing a new block.
|
||||
///
|
||||
@@ -32,6 +34,8 @@ const ADD: u64 = 2;
|
||||
struct State {
|
||||
head_to_state: HashMap<Arc<HeadData>, u64>,
|
||||
number_to_head: HashMap<u64, Arc<HeadData>>,
|
||||
/// Block number of the best block.
|
||||
best_block: u64,
|
||||
}
|
||||
|
||||
impl State {
|
||||
@@ -46,6 +50,7 @@ impl State {
|
||||
Self {
|
||||
head_to_state: vec![(genesis_state.clone(), 0)].into_iter().collect(),
|
||||
number_to_head: vec![(0, genesis_state)].into_iter().collect(),
|
||||
best_block: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +58,8 @@ impl State {
|
||||
///
|
||||
/// Returns the new [`BlockData`] and the new [`HeadData`].
|
||||
fn advance(&mut self, parent_head: HeadData) -> (BlockData, HeadData) {
|
||||
self.best_block = parent_head.number;
|
||||
|
||||
let block = BlockData {
|
||||
state: *self.head_to_state.get(&parent_head).expect("Getting state using parent head"),
|
||||
add: ADD,
|
||||
@@ -72,6 +79,7 @@ impl State {
|
||||
/// The collator of the adder parachain.
|
||||
pub struct Collator {
|
||||
state: Arc<Mutex<State>>,
|
||||
key: CollatorPair,
|
||||
}
|
||||
|
||||
impl Collator {
|
||||
@@ -79,6 +87,7 @@ impl Collator {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
state: Arc::new(Mutex::new(State::genesis())),
|
||||
key: CollatorPair::generate().0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +101,16 @@ impl Collator {
|
||||
test_parachain_adder::wasm_binary_unwrap()
|
||||
}
|
||||
|
||||
/// Get the collator key.
|
||||
pub fn collator_key(&self) -> CollatorPair {
|
||||
self.key.clone()
|
||||
}
|
||||
|
||||
/// Get the collator id.
|
||||
pub fn collator_id(&self) -> CollatorId {
|
||||
self.key.public()
|
||||
}
|
||||
|
||||
/// Create the collation function.
|
||||
///
|
||||
/// This collation function can be plugged into the overseer to generate collations for the adder parachain.
|
||||
@@ -125,6 +144,20 @@ impl Collator {
|
||||
async move { Some(collation) }.boxed()
|
||||
})
|
||||
}
|
||||
|
||||
/// Wait until `blocks` are built and enacted.
|
||||
pub async fn wait_for_blocks(&self, blocks: u64) {
|
||||
let start_block = self.state.lock().unwrap().best_block;
|
||||
loop {
|
||||
Delay::new(Duration::from_secs(1)).await;
|
||||
|
||||
let current_block = self.state.lock().unwrap().best_block;
|
||||
|
||||
if start_block + blocks <= current_block {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -20,9 +20,9 @@ use sc_cli::{Result, Role, SubstrateCli};
|
||||
use polkadot_cli::Cli;
|
||||
use polkadot_node_subsystem::messages::{CollatorProtocolMessage, CollationGenerationMessage};
|
||||
use polkadot_node_primitives::CollationGenerationConfig;
|
||||
use polkadot_primitives::v1::{CollatorPair, Id as ParaId};
|
||||
use polkadot_primitives::v1::Id as ParaId;
|
||||
use test_parachain_adder_collator::Collator;
|
||||
use sp_core::{Pair, hexdisplay::HexDisplay};
|
||||
use sp_core::hexdisplay::HexDisplay;
|
||||
use std::time::Duration;
|
||||
|
||||
const PARA_ID: ParaId = ParaId::new(100);
|
||||
@@ -42,11 +42,11 @@ fn main() -> Result<()> {
|
||||
match role {
|
||||
Role::Light => Err("Light client not supported".into()),
|
||||
_ => {
|
||||
let collator_key = CollatorPair::generate().0;
|
||||
let collator = Collator::new();
|
||||
|
||||
let full_node = polkadot_service::build_full(
|
||||
config,
|
||||
polkadot_service::IsCollator::Yes(collator_key.public()),
|
||||
polkadot_service::IsCollator::Yes(collator.collator_id()),
|
||||
None,
|
||||
Some(sc_authority_discovery::WorkerConfig {
|
||||
query_interval: Duration::from_secs(1),
|
||||
@@ -57,7 +57,6 @@ fn main() -> Result<()> {
|
||||
let mut overseer_handler = full_node.overseer_handler
|
||||
.expect("Overseer handler should be initialized for collators");
|
||||
|
||||
let collator = Collator::new();
|
||||
let genesis_head_hex = format!("0x{:?}", HexDisplay::from(&collator.genesis_head()));
|
||||
let validation_code_hex = format!("0x{:?}", HexDisplay::from(&collator.validation_code()));
|
||||
|
||||
@@ -66,7 +65,7 @@ fn main() -> Result<()> {
|
||||
log::info!("Validation code: {}", validation_code_hex);
|
||||
|
||||
let config = CollationGenerationConfig {
|
||||
key: collator_key,
|
||||
key: collator.collator_key(),
|
||||
collator: collator.create_collation_function(),
|
||||
para_id: PARA_ID,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user