mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 18:31:05 +00:00
Move cumulus zombienet tests to aura & async backing (#3568)
Cumulus test-parachain node and test runtime were still using relay chain consensus and 12s blocktimes. With async backing around the corner on the major chains we should switch our tests too. Also needed to nicely test the changes coming to collators in #3168. ### Changes Overview - Followed the [migration guide](https://wiki.polkadot.network/docs/maintain-guides-async-backing) for async backing for the cumulus-test-runtime - Adjusted the cumulus-test-service to use the correct import-queue, lookahead collator etc. - The block validation function now uses the Aura Ext Executor so that the seal of the block is validated - Previous point requires that we seal block before calling into `validate_block`, I introduced a helper function for that - Test client adjusted to provide a slot to the relay chain proof and the aura pre-digest
This commit is contained in:
@@ -17,24 +17,30 @@
|
||||
//! A Cumulus test client.
|
||||
|
||||
mod block_builder;
|
||||
pub use block_builder::*;
|
||||
use codec::{Decode, Encode};
|
||||
pub use cumulus_test_runtime as runtime;
|
||||
use cumulus_test_runtime::AuraId;
|
||||
pub use polkadot_parachain_primitives::primitives::{
|
||||
BlockData, HeadData, ValidationParams, ValidationResult,
|
||||
};
|
||||
use runtime::{
|
||||
Balance, Block, BlockHashCount, Runtime, RuntimeCall, Signature, SignedExtra, SignedPayload,
|
||||
UncheckedExtrinsic, VERSION,
|
||||
};
|
||||
use sc_consensus_aura::standalone::{seal, slot_author};
|
||||
pub use sc_executor::error::Result as ExecutorResult;
|
||||
use sc_executor::HeapAllocStrategy;
|
||||
use sc_executor_common::runtime_blob::RuntimeBlob;
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use sp_application_crypto::AppCrypto;
|
||||
use sp_blockchain::HeaderBackend;
|
||||
use sp_consensus_aura::{AuraApi, Slot};
|
||||
use sp_core::Pair;
|
||||
use sp_io::TestExternalities;
|
||||
use sp_runtime::{generic::Era, BuildStorage, SaturatedConversion};
|
||||
|
||||
pub use block_builder::*;
|
||||
pub use cumulus_test_runtime as runtime;
|
||||
pub use polkadot_parachain_primitives::primitives::{
|
||||
BlockData, HeadData, ValidationParams, ValidationResult,
|
||||
};
|
||||
pub use sc_executor::error::Result as ExecutorResult;
|
||||
use sp_keystore::testing::MemoryKeystore;
|
||||
use sp_runtime::{generic::Era, traits::Header, BuildStorage, SaturatedConversion};
|
||||
use std::sync::Arc;
|
||||
pub use substrate_test_client::*;
|
||||
|
||||
pub type ParachainBlockData = cumulus_primitives_core::ParachainBlockData<Block>;
|
||||
@@ -225,3 +231,40 @@ pub fn validate_block(
|
||||
)
|
||||
.map(|v| ValidationResult::decode(&mut &v[..]).expect("Decode `ValidationResult`."))
|
||||
}
|
||||
|
||||
fn get_keystore() -> sp_keystore::KeystorePtr {
|
||||
let keystore = MemoryKeystore::new();
|
||||
sp_keyring::Sr25519Keyring::iter().for_each(|key| {
|
||||
keystore
|
||||
.sr25519_generate_new(
|
||||
sp_consensus_aura::sr25519::AuthorityPair::ID,
|
||||
Some(&key.to_seed()),
|
||||
)
|
||||
.expect("Key should be created");
|
||||
});
|
||||
Arc::new(keystore)
|
||||
}
|
||||
|
||||
/// Given parachain block data and a slot, seal the block with an aura seal. Assumes that the
|
||||
/// authorities of the test runtime are present in the keyring.
|
||||
pub fn seal_block(
|
||||
block: ParachainBlockData,
|
||||
parachain_slot: Slot,
|
||||
client: &Client,
|
||||
) -> ParachainBlockData {
|
||||
let parent_hash = block.header().parent_hash;
|
||||
let authorities = client.runtime_api().authorities(parent_hash).unwrap();
|
||||
let expected_author = slot_author::<<AuraId as AppCrypto>::Pair>(parachain_slot, &authorities)
|
||||
.expect("Should be able to find author");
|
||||
|
||||
let (mut header, extrinsics, proof) = block.deconstruct();
|
||||
let keystore = get_keystore();
|
||||
let seal_digest = seal::<_, sp_consensus_aura::sr25519::AuthorityPair>(
|
||||
&header.hash(),
|
||||
expected_author,
|
||||
&keystore,
|
||||
)
|
||||
.expect("Should be able to create seal");
|
||||
header.digest_mut().push(seal_digest);
|
||||
ParachainBlockData::new(header, extrinsics, proof)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user