mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-20 18:35:41 +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:
@@ -21,13 +21,15 @@ use cumulus_test_client::{
|
||||
runtime::{
|
||||
self as test_runtime, Block, Hash, Header, TestPalletCall, UncheckedExtrinsic, WASM_BINARY,
|
||||
},
|
||||
transfer, BlockData, BlockOrigin, BuildParachainBlockData, Client, ClientBlockImportExt,
|
||||
DefaultTestClientBuilderExt, HeadData, InitBlockBuilder, TestClientBuilder,
|
||||
TestClientBuilderExt, ValidationParams,
|
||||
seal_block, transfer, BlockData, BlockOrigin, BuildParachainBlockData, Client,
|
||||
ClientBlockImportExt, DefaultTestClientBuilderExt, HeadData, InitBlockBuilder,
|
||||
Sr25519Keyring::{Alice, Bob, Charlie},
|
||||
TestClientBuilder, TestClientBuilderExt, ValidationParams,
|
||||
};
|
||||
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
|
||||
use sp_keyring::AccountKeyring::*;
|
||||
use sp_consensus_slots::Slot;
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
|
||||
|
||||
use std::{env, process::Command};
|
||||
|
||||
use crate::validate_block::MemoryOptimizedValidationParams;
|
||||
@@ -73,6 +75,7 @@ fn create_test_client() -> (Client, Header) {
|
||||
struct TestBlockData {
|
||||
block: ParachainBlockData<Block>,
|
||||
validation_data: PersistedValidationData,
|
||||
slot: Slot,
|
||||
}
|
||||
|
||||
fn build_block_with_witness(
|
||||
@@ -83,21 +86,24 @@ fn build_block_with_witness(
|
||||
) -> TestBlockData {
|
||||
sproof_builder.para_id = test_runtime::PARACHAIN_ID.into();
|
||||
sproof_builder.included_para_head = Some(HeadData(parent_head.encode()));
|
||||
let (relay_parent_storage_root, _) = sproof_builder.clone().into_state_root_and_proof();
|
||||
let mut validation_data = PersistedValidationData {
|
||||
|
||||
let validation_data = PersistedValidationData {
|
||||
relay_parent_number: 1,
|
||||
parent_head: parent_head.encode().into(),
|
||||
..Default::default()
|
||||
};
|
||||
let mut builder = client.init_block_builder(Some(validation_data.clone()), sproof_builder);
|
||||
|
||||
validation_data.relay_parent_storage_root = relay_parent_storage_root;
|
||||
let cumulus_test_client::BlockBuilderAndSupportData {
|
||||
mut block_builder,
|
||||
persisted_validation_data,
|
||||
slot,
|
||||
} = client.init_block_builder(Some(validation_data), sproof_builder);
|
||||
|
||||
extra_extrinsics.into_iter().for_each(|e| builder.push(e).unwrap());
|
||||
extra_extrinsics.into_iter().for_each(|e| block_builder.push(e).unwrap());
|
||||
|
||||
let block = builder.build_parachain_block(*parent_head.state_root());
|
||||
let block = block_builder.build_parachain_block(*parent_head.state_root());
|
||||
|
||||
TestBlockData { block, validation_data }
|
||||
TestBlockData { block, validation_data: persisted_validation_data, slot }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -105,10 +111,11 @@ fn validate_block_works() {
|
||||
sp_tracing::try_init_simple();
|
||||
|
||||
let (client, parent_head) = create_test_client();
|
||||
let TestBlockData { block, validation_data } =
|
||||
let TestBlockData { block, validation_data, slot } =
|
||||
build_block_with_witness(&client, Vec::new(), parent_head.clone(), Default::default());
|
||||
let header = block.header().clone();
|
||||
|
||||
let block = seal_block(block, slot, &client);
|
||||
let header = block.header().clone();
|
||||
let res_header =
|
||||
call_validate_block(parent_head, block, validation_data.relay_parent_storage_root)
|
||||
.expect("Calls `validate_block`");
|
||||
@@ -126,12 +133,13 @@ fn validate_block_with_extra_extrinsics() {
|
||||
transfer(&client, Charlie, Alice, 500),
|
||||
];
|
||||
|
||||
let TestBlockData { block, validation_data } = build_block_with_witness(
|
||||
let TestBlockData { block, validation_data, slot } = build_block_with_witness(
|
||||
&client,
|
||||
extra_extrinsics,
|
||||
parent_head.clone(),
|
||||
Default::default(),
|
||||
);
|
||||
let block = seal_block(block, slot, &client);
|
||||
let header = block.header().clone();
|
||||
|
||||
let res_header =
|
||||
@@ -159,7 +167,7 @@ fn validate_block_returns_custom_head_data() {
|
||||
transfer(&client, Bob, Charlie, 100),
|
||||
];
|
||||
|
||||
let TestBlockData { block, validation_data } = build_block_with_witness(
|
||||
let TestBlockData { block, validation_data, slot } = build_block_with_witness(
|
||||
&client,
|
||||
extra_extrinsics,
|
||||
parent_head.clone(),
|
||||
@@ -168,6 +176,7 @@ fn validate_block_returns_custom_head_data() {
|
||||
let header = block.header().clone();
|
||||
assert_ne!(expected_header, header.encode());
|
||||
|
||||
let block = seal_block(block, slot, &client);
|
||||
let res_header = call_validate_block_encoded_header(
|
||||
parent_head,
|
||||
block,
|
||||
@@ -183,7 +192,7 @@ fn validate_block_invalid_parent_hash() {
|
||||
|
||||
if env::var("RUN_TEST").is_ok() {
|
||||
let (client, parent_head) = create_test_client();
|
||||
let TestBlockData { block, validation_data } =
|
||||
let TestBlockData { block, validation_data, .. } =
|
||||
build_block_with_witness(&client, Vec::new(), parent_head.clone(), Default::default());
|
||||
let (mut header, extrinsics, witness) = block.deconstruct();
|
||||
header.set_parent_hash(Hash::from_low_u64_be(1));
|
||||
@@ -233,7 +242,7 @@ fn check_inherents_are_unsigned_and_before_all_other_extrinsics() {
|
||||
if env::var("RUN_TEST").is_ok() {
|
||||
let (client, parent_head) = create_test_client();
|
||||
|
||||
let TestBlockData { block, validation_data } =
|
||||
let TestBlockData { block, validation_data, .. } =
|
||||
build_block_with_witness(&client, Vec::new(), parent_head.clone(), Default::default());
|
||||
|
||||
let (header, mut extrinsics, proof) = block.deconstruct();
|
||||
@@ -316,15 +325,15 @@ fn validate_block_works_with_child_tries() {
|
||||
|
||||
let parent_head = block.header().clone();
|
||||
|
||||
let TestBlockData { block, validation_data } = build_block_with_witness(
|
||||
let TestBlockData { block, validation_data, slot } = build_block_with_witness(
|
||||
&client,
|
||||
vec![generate_extrinsic(&client, Alice, TestPalletCall::read_and_write_child_tries {})],
|
||||
parent_head.clone(),
|
||||
Default::default(),
|
||||
);
|
||||
|
||||
let block = seal_block(block, slot, &client);
|
||||
let header = block.header().clone();
|
||||
|
||||
let res_header =
|
||||
call_validate_block(parent_head, block, validation_data.relay_parent_storage_root)
|
||||
.expect("Calls `validate_block`");
|
||||
|
||||
Reference in New Issue
Block a user