Skip to content

Commit 51fac29

Browse files
committed
add collation-generation test
1 parent e84868f commit 51fac29

File tree

1 file changed

+87
-1
lines changed
  • polkadot/node/collation-generation/src

1 file changed

+87
-1
lines changed

polkadot/node/collation-generation/src/tests.rs

+87-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ use polkadot_node_subsystem_test_helpers::TestSubsystemContextHandle;
2828
use polkadot_node_subsystem_util::TimeoutExt;
2929
use polkadot_primitives::{
3030
node_features,
31-
vstaging::{CandidateDescriptorVersion, CoreSelector, UMPSignal, UMP_SEPARATOR},
31+
vstaging::{
32+
CandidateDescriptorVersion, ClaimQueueOffset, CoreSelector, UMPSignal, UMP_SEPARATOR,
33+
},
3234
CollatorPair, PersistedValidationData,
3335
};
3436
use polkadot_primitives_test_helpers::dummy_head_data;
@@ -573,6 +575,90 @@ fn v2_receipts_failed_core_index_check() {
573575
virtual_overseer
574576
});
575577
}
578+
579+
#[rstest]
580+
#[case(true)]
581+
#[case(false)]
582+
fn approved_peer_signal(#[case] allow_approved_peer_signals: bool) {
583+
let relay_parent = Hash::repeat_byte(0);
584+
let validation_code_hash = ValidationCodeHash::from(Hash::repeat_byte(42));
585+
let parent_head = dummy_head_data();
586+
let para_id = ParaId::from(5);
587+
let expected_pvd = PersistedValidationData {
588+
parent_head: parent_head.clone(),
589+
relay_parent_number: 10,
590+
relay_parent_storage_root: Hash::repeat_byte(1),
591+
max_pov_size: 1024,
592+
};
593+
594+
test_harness(|mut virtual_overseer| async move {
595+
virtual_overseer
596+
.send(FromOrchestra::Communication {
597+
msg: CollationGenerationMessage::Initialize(test_config_no_collator(para_id)),
598+
})
599+
.await;
600+
601+
let mut collation = test_collation();
602+
collation.upward_messages.force_push(UMP_SEPARATOR);
603+
collation
604+
.upward_messages
605+
.force_push(UMPSignal::ApprovedPeer(vec![1, 2, 3, 4, 5].try_into().unwrap()).encode());
606+
607+
virtual_overseer
608+
.send(FromOrchestra::Communication {
609+
msg: CollationGenerationMessage::SubmitCollation(SubmitCollationParams {
610+
relay_parent,
611+
collation,
612+
parent_head: dummy_head_data(),
613+
validation_code_hash,
614+
result_sender: None,
615+
core_index: CoreIndex(0),
616+
}),
617+
})
618+
.await;
619+
620+
let mut node_features = node_features_with_v2_enabled();
621+
if allow_approved_peer_signals {
622+
node_features
623+
.resize(node_features::FeatureIndex::ApprovedPeerUmpSignal as usize + 1, false);
624+
node_features
625+
.set(node_features::FeatureIndex::ApprovedPeerUmpSignal as u8 as usize, true);
626+
}
627+
628+
helpers::handle_runtime_calls_on_submit_collation(
629+
&mut virtual_overseer,
630+
relay_parent,
631+
para_id,
632+
expected_pvd.clone(),
633+
node_features,
634+
[(CoreIndex(0), [para_id].into_iter().collect())].into_iter().collect(),
635+
)
636+
.await;
637+
638+
if allow_approved_peer_signals {
639+
assert_matches!(
640+
overseer_recv(&mut virtual_overseer).await,
641+
AllMessages::CollatorProtocol(CollatorProtocolMessage::DistributeCollation {
642+
candidate_receipt,
643+
parent_head_data_hash,
644+
..
645+
}) => {
646+
let CandidateReceipt { descriptor, .. } = candidate_receipt;
647+
assert_eq!(parent_head_data_hash, parent_head.hash());
648+
assert_eq!(descriptor.persisted_validation_data_hash(), expected_pvd.hash());
649+
assert_eq!(descriptor.para_head(), dummy_head_data().hash());
650+
assert_eq!(descriptor.validation_code_hash(), validation_code_hash);
651+
assert_eq!(descriptor.version(), CandidateDescriptorVersion::V2);
652+
}
653+
);
654+
} else {
655+
// No collation is distributed.
656+
}
657+
658+
virtual_overseer
659+
});
660+
}
661+
576662
mod helpers {
577663
use super::*;
578664
use std::collections::{BTreeMap, VecDeque};

0 commit comments

Comments
 (0)