mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-21 07:31:03 +00:00
Fix code duplication in tests (#1575)
This commit is contained in:
committed by
GitHub
parent
756347ab24
commit
d81a2e2fa9
@@ -18,7 +18,7 @@ use self::test_helpers::mock::new_leaf;
|
|||||||
use super::*;
|
use super::*;
|
||||||
use ::test_helpers::{
|
use ::test_helpers::{
|
||||||
dummy_candidate_receipt_bad_sig, dummy_collator, dummy_collator_signature,
|
dummy_candidate_receipt_bad_sig, dummy_collator, dummy_collator_signature,
|
||||||
dummy_committed_candidate_receipt, dummy_hash,
|
dummy_committed_candidate_receipt, dummy_hash, validator_pubkeys,
|
||||||
};
|
};
|
||||||
use assert_matches::assert_matches;
|
use assert_matches::assert_matches;
|
||||||
use futures::{future, Future};
|
use futures::{future, Future};
|
||||||
@@ -48,10 +48,6 @@ mod prospective_parachains;
|
|||||||
const ASYNC_BACKING_DISABLED_ERROR: RuntimeApiError =
|
const ASYNC_BACKING_DISABLED_ERROR: RuntimeApiError =
|
||||||
RuntimeApiError::NotSupported { runtime_api_name: "test-runtime" };
|
RuntimeApiError::NotSupported { runtime_api_name: "test-runtime" };
|
||||||
|
|
||||||
fn validator_pubkeys(val_ids: &[Sr25519Keyring]) -> Vec<ValidatorId> {
|
|
||||||
val_ids.iter().map(|v| v.public().into()).collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn table_statement_to_primitive(statement: TableStatement) -> Statement {
|
fn table_statement_to_primitive(statement: TableStatement) -> Statement {
|
||||||
match statement {
|
match statement {
|
||||||
TableStatement::Seconded(committed_candidate_receipt) =>
|
TableStatement::Seconded(committed_candidate_receipt) =>
|
||||||
@@ -299,6 +295,81 @@ async fn test_startup(virtual_overseer: &mut VirtualOverseer, test_state: &TestS
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn assert_validation_requests(
|
||||||
|
virtual_overseer: &mut VirtualOverseer,
|
||||||
|
validation_code: ValidationCode,
|
||||||
|
) {
|
||||||
|
assert_matches!(
|
||||||
|
virtual_overseer.recv().await,
|
||||||
|
AllMessages::RuntimeApi(
|
||||||
|
RuntimeApiMessage::Request(_, RuntimeApiRequest::ValidationCodeByHash(hash, tx))
|
||||||
|
) if hash == validation_code.hash() => {
|
||||||
|
tx.send(Ok(Some(validation_code))).unwrap();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_matches!(
|
||||||
|
virtual_overseer.recv().await,
|
||||||
|
AllMessages::RuntimeApi(
|
||||||
|
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionIndexForChild(tx))
|
||||||
|
) => {
|
||||||
|
tx.send(Ok(1u32.into())).unwrap();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_matches!(
|
||||||
|
virtual_overseer.recv().await,
|
||||||
|
AllMessages::RuntimeApi(
|
||||||
|
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionExecutorParams(sess_idx, tx))
|
||||||
|
) if sess_idx == 1 => {
|
||||||
|
tx.send(Ok(Some(ExecutorParams::default()))).unwrap();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn assert_validate_from_exhaustive(
|
||||||
|
virtual_overseer: &mut VirtualOverseer,
|
||||||
|
pvd: &PersistedValidationData,
|
||||||
|
pov: &PoV,
|
||||||
|
validation_code: &ValidationCode,
|
||||||
|
candidate: &CommittedCandidateReceipt,
|
||||||
|
expected_head_data: &HeadData,
|
||||||
|
result_validation_data: PersistedValidationData,
|
||||||
|
) {
|
||||||
|
assert_matches!(
|
||||||
|
virtual_overseer.recv().await,
|
||||||
|
AllMessages::CandidateValidation(
|
||||||
|
CandidateValidationMessage::ValidateFromExhaustive(
|
||||||
|
_pvd,
|
||||||
|
_validation_code,
|
||||||
|
candidate_receipt,
|
||||||
|
_pov,
|
||||||
|
_,
|
||||||
|
timeout,
|
||||||
|
tx,
|
||||||
|
),
|
||||||
|
) if _pvd == *pvd &&
|
||||||
|
_validation_code == *validation_code &&
|
||||||
|
*_pov == *pov && &candidate_receipt.descriptor == candidate.descriptor() &&
|
||||||
|
timeout == PvfExecTimeoutKind::Backing &&
|
||||||
|
candidate.commitments.hash() == candidate_receipt.commitments_hash =>
|
||||||
|
{
|
||||||
|
tx.send(Ok(ValidationResult::Valid(
|
||||||
|
CandidateCommitments {
|
||||||
|
head_data: expected_head_data.clone(),
|
||||||
|
horizontal_messages: Default::default(),
|
||||||
|
upward_messages: Default::default(),
|
||||||
|
new_validation_code: None,
|
||||||
|
processed_downward_messages: 0,
|
||||||
|
hrmp_watermark: 0,
|
||||||
|
},
|
||||||
|
result_validation_data,
|
||||||
|
)))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Test that a `CandidateBackingMessage::Second` issues validation work
|
// Test that a `CandidateBackingMessage::Second` issues validation work
|
||||||
// and in case validation is successful issues a `StatementDistributionMessage`.
|
// and in case validation is successful issues a `StatementDistributionMessage`.
|
||||||
#[test]
|
#[test]
|
||||||
@@ -334,65 +405,18 @@ fn backing_second_works() {
|
|||||||
|
|
||||||
virtual_overseer.send(FromOrchestra::Communication { msg: second }).await;
|
virtual_overseer.send(FromOrchestra::Communication { msg: second }).await;
|
||||||
|
|
||||||
assert_matches!(
|
assert_validation_requests(&mut virtual_overseer, validation_code.clone()).await;
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::ValidationCodeByHash(hash, tx))
|
|
||||||
) if hash == validation_code.hash() => {
|
|
||||||
tx.send(Ok(Some(validation_code.clone()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
assert_validate_from_exhaustive(
|
||||||
virtual_overseer.recv().await,
|
&mut virtual_overseer,
|
||||||
AllMessages::RuntimeApi(
|
&pvd,
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionIndexForChild(tx))
|
&pov,
|
||||||
) => {
|
&validation_code,
|
||||||
tx.send(Ok(1u32.into())).unwrap();
|
&candidate,
|
||||||
}
|
expected_head_data,
|
||||||
);
|
test_state.validation_data.clone(),
|
||||||
|
)
|
||||||
assert_matches!(
|
.await;
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionExecutorParams(sess_idx, tx))
|
|
||||||
) if sess_idx == 1 => {
|
|
||||||
tx.send(Ok(Some(ExecutorParams::default()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::CandidateValidation(
|
|
||||||
CandidateValidationMessage::ValidateFromExhaustive(
|
|
||||||
_pvd,
|
|
||||||
_validation_code,
|
|
||||||
candidate_receipt,
|
|
||||||
_pov,
|
|
||||||
_,
|
|
||||||
timeout,
|
|
||||||
tx,
|
|
||||||
),
|
|
||||||
) if _pvd == pvd &&
|
|
||||||
_validation_code == validation_code &&
|
|
||||||
*_pov == pov && &candidate_receipt.descriptor == candidate.descriptor() &&
|
|
||||||
timeout == PvfExecTimeoutKind::Backing &&
|
|
||||||
candidate.commitments.hash() == candidate_receipt.commitments_hash =>
|
|
||||||
{
|
|
||||||
tx.send(Ok(ValidationResult::Valid(
|
|
||||||
CandidateCommitments {
|
|
||||||
head_data: expected_head_data.clone(),
|
|
||||||
horizontal_messages: Default::default(),
|
|
||||||
upward_messages: Default::default(),
|
|
||||||
new_validation_code: None,
|
|
||||||
processed_downward_messages: 0,
|
|
||||||
hrmp_watermark: 0,
|
|
||||||
},
|
|
||||||
test_state.validation_data.clone(),
|
|
||||||
)))
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
virtual_overseer.recv().await,
|
virtual_overseer.recv().await,
|
||||||
@@ -499,32 +523,7 @@ fn backing_works() {
|
|||||||
|
|
||||||
virtual_overseer.send(FromOrchestra::Communication { msg: statement }).await;
|
virtual_overseer.send(FromOrchestra::Communication { msg: statement }).await;
|
||||||
|
|
||||||
assert_matches!(
|
assert_validation_requests(&mut virtual_overseer, validation_code.clone()).await;
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::ValidationCodeByHash(hash, tx))
|
|
||||||
) if hash == validation_code.hash() => {
|
|
||||||
tx.send(Ok(Some(validation_code.clone()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionIndexForChild(tx))
|
|
||||||
) => {
|
|
||||||
tx.send(Ok(1u32.into())).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionExecutorParams(sess_idx, tx))
|
|
||||||
) if sess_idx == 1 => {
|
|
||||||
tx.send(Ok(Some(ExecutorParams::default()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Sending a `Statement::Seconded` for our assignment will start
|
// Sending a `Statement::Seconded` for our assignment will start
|
||||||
// validation process. The first thing requested is the PoV.
|
// validation process. The first thing requested is the PoV.
|
||||||
@@ -702,32 +701,7 @@ fn backing_works_while_validation_ongoing() {
|
|||||||
CandidateBackingMessage::Statement(test_state.relay_parent, signed_a.clone());
|
CandidateBackingMessage::Statement(test_state.relay_parent, signed_a.clone());
|
||||||
virtual_overseer.send(FromOrchestra::Communication { msg: statement }).await;
|
virtual_overseer.send(FromOrchestra::Communication { msg: statement }).await;
|
||||||
|
|
||||||
assert_matches!(
|
assert_validation_requests(&mut virtual_overseer, validation_code.clone()).await;
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::ValidationCodeByHash(hash, tx))
|
|
||||||
) if hash == validation_code.hash() => {
|
|
||||||
tx.send(Ok(Some(validation_code.clone()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionIndexForChild(tx))
|
|
||||||
) => {
|
|
||||||
tx.send(Ok(1u32.into())).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionExecutorParams(sess_idx, tx))
|
|
||||||
) if sess_idx == 1 => {
|
|
||||||
tx.send(Ok(Some(ExecutorParams::default()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Sending a `Statement::Seconded` for our assignment will start
|
// Sending a `Statement::Seconded` for our assignment will start
|
||||||
// validation process. The first thing requested is PoV from the
|
// validation process. The first thing requested is PoV from the
|
||||||
@@ -893,32 +867,7 @@ fn backing_misbehavior_works() {
|
|||||||
|
|
||||||
virtual_overseer.send(FromOrchestra::Communication { msg: statement }).await;
|
virtual_overseer.send(FromOrchestra::Communication { msg: statement }).await;
|
||||||
|
|
||||||
assert_matches!(
|
assert_validation_requests(&mut virtual_overseer, validation_code.clone()).await;
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::ValidationCodeByHash(hash, tx))
|
|
||||||
) if hash == validation_code.hash() => {
|
|
||||||
tx.send(Ok(Some(validation_code.clone()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionIndexForChild(tx))
|
|
||||||
) => {
|
|
||||||
tx.send(Ok(1u32.into())).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionExecutorParams(sess_idx, tx))
|
|
||||||
) if sess_idx == 1 => {
|
|
||||||
tx.send(Ok(Some(ExecutorParams::default()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
virtual_overseer.recv().await,
|
virtual_overseer.recv().await,
|
||||||
@@ -1098,32 +1047,7 @@ fn backing_dont_second_invalid() {
|
|||||||
|
|
||||||
virtual_overseer.send(FromOrchestra::Communication { msg: second }).await;
|
virtual_overseer.send(FromOrchestra::Communication { msg: second }).await;
|
||||||
|
|
||||||
assert_matches!(
|
assert_validation_requests(&mut virtual_overseer, validation_code_a.clone()).await;
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::ValidationCodeByHash(hash, tx))
|
|
||||||
) if hash == validation_code_a.hash() => {
|
|
||||||
tx.send(Ok(Some(validation_code_a.clone()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionIndexForChild(tx))
|
|
||||||
) => {
|
|
||||||
tx.send(Ok(1u32.into())).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionExecutorParams(sess_idx, tx))
|
|
||||||
) if sess_idx == 1 => {
|
|
||||||
tx.send(Ok(Some(ExecutorParams::default()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
virtual_overseer.recv().await,
|
virtual_overseer.recv().await,
|
||||||
@@ -1163,32 +1087,7 @@ fn backing_dont_second_invalid() {
|
|||||||
|
|
||||||
virtual_overseer.send(FromOrchestra::Communication { msg: second }).await;
|
virtual_overseer.send(FromOrchestra::Communication { msg: second }).await;
|
||||||
|
|
||||||
assert_matches!(
|
assert_validation_requests(&mut virtual_overseer, validation_code_b.clone()).await;
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::ValidationCodeByHash(hash, tx))
|
|
||||||
) if hash == validation_code_b.hash() => {
|
|
||||||
tx.send(Ok(Some(validation_code_b.clone()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionIndexForChild(tx))
|
|
||||||
) => {
|
|
||||||
tx.send(Ok(1u32.into())).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionExecutorParams(sess_idx, tx))
|
|
||||||
) if sess_idx == 1 => {
|
|
||||||
tx.send(Ok(Some(ExecutorParams::default()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
virtual_overseer.recv().await,
|
virtual_overseer.recv().await,
|
||||||
@@ -1300,32 +1199,7 @@ fn backing_second_after_first_fails_works() {
|
|||||||
|
|
||||||
virtual_overseer.send(FromOrchestra::Communication { msg: statement }).await;
|
virtual_overseer.send(FromOrchestra::Communication { msg: statement }).await;
|
||||||
|
|
||||||
assert_matches!(
|
assert_validation_requests(&mut virtual_overseer, validation_code.clone()).await;
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::ValidationCodeByHash(hash, tx))
|
|
||||||
) if hash == validation_code.hash() => {
|
|
||||||
tx.send(Ok(Some(validation_code.clone()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionIndexForChild(tx))
|
|
||||||
) => {
|
|
||||||
tx.send(Ok(1u32.into())).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionExecutorParams(sess_idx, tx))
|
|
||||||
) if sess_idx == 1 => {
|
|
||||||
tx.send(Ok(Some(ExecutorParams::default()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Subsystem requests PoV and requests validation.
|
// Subsystem requests PoV and requests validation.
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
@@ -1408,32 +1282,7 @@ fn backing_second_after_first_fails_works() {
|
|||||||
// triggered on the prev step.
|
// triggered on the prev step.
|
||||||
virtual_overseer.send(FromOrchestra::Communication { msg: second }).await;
|
virtual_overseer.send(FromOrchestra::Communication { msg: second }).await;
|
||||||
|
|
||||||
assert_matches!(
|
assert_validation_requests(&mut virtual_overseer, validation_code_to_second.clone()).await;
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::ValidationCodeByHash(hash, tx))
|
|
||||||
) if hash == validation_code_to_second.hash() => {
|
|
||||||
tx.send(Ok(Some(validation_code_to_second.clone()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionIndexForChild(tx))
|
|
||||||
) => {
|
|
||||||
tx.send(Ok(1u32.into())).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionExecutorParams(sess_idx, tx))
|
|
||||||
) if sess_idx == 1 => {
|
|
||||||
tx.send(Ok(Some(ExecutorParams::default()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
virtual_overseer.recv().await,
|
virtual_overseer.recv().await,
|
||||||
@@ -1494,32 +1343,7 @@ fn backing_works_after_failed_validation() {
|
|||||||
|
|
||||||
virtual_overseer.send(FromOrchestra::Communication { msg: statement }).await;
|
virtual_overseer.send(FromOrchestra::Communication { msg: statement }).await;
|
||||||
|
|
||||||
assert_matches!(
|
assert_validation_requests(&mut virtual_overseer, validation_code.clone()).await;
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::ValidationCodeByHash(hash, tx))
|
|
||||||
) if hash == validation_code.hash() => {
|
|
||||||
tx.send(Ok(Some(validation_code.clone()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionIndexForChild(tx))
|
|
||||||
) => {
|
|
||||||
tx.send(Ok(1u32.into())).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionExecutorParams(sess_idx, tx))
|
|
||||||
) if sess_idx == 1 => {
|
|
||||||
tx.send(Ok(Some(ExecutorParams::default()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Subsystem requests PoV and requests validation.
|
// Subsystem requests PoV and requests validation.
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
@@ -1722,32 +1546,7 @@ fn retry_works() {
|
|||||||
CandidateBackingMessage::Statement(test_state.relay_parent, signed_a.clone());
|
CandidateBackingMessage::Statement(test_state.relay_parent, signed_a.clone());
|
||||||
virtual_overseer.send(FromOrchestra::Communication { msg: statement }).await;
|
virtual_overseer.send(FromOrchestra::Communication { msg: statement }).await;
|
||||||
|
|
||||||
assert_matches!(
|
assert_validation_requests(&mut virtual_overseer, validation_code.clone()).await;
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::ValidationCodeByHash(hash, tx))
|
|
||||||
) if hash == validation_code.hash() => {
|
|
||||||
tx.send(Ok(Some(validation_code.clone()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionIndexForChild(tx))
|
|
||||||
) => {
|
|
||||||
tx.send(Ok(1u32.into())).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionExecutorParams(sess_idx, tx))
|
|
||||||
) if sess_idx == 1 => {
|
|
||||||
tx.send(Ok(Some(ExecutorParams::default()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Subsystem requests PoV and requests validation.
|
// Subsystem requests PoV and requests validation.
|
||||||
// We cancel - should mean retry on next backing statement.
|
// We cancel - should mean retry on next backing statement.
|
||||||
@@ -1810,32 +1609,7 @@ fn retry_works() {
|
|||||||
CandidateBackingMessage::Statement(test_state.relay_parent, signed_c.clone());
|
CandidateBackingMessage::Statement(test_state.relay_parent, signed_c.clone());
|
||||||
virtual_overseer.send(FromOrchestra::Communication { msg: statement }).await;
|
virtual_overseer.send(FromOrchestra::Communication { msg: statement }).await;
|
||||||
|
|
||||||
assert_matches!(
|
assert_validation_requests(&mut virtual_overseer, validation_code.clone()).await;
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::ValidationCodeByHash(hash, tx))
|
|
||||||
) if hash == validation_code.hash() => {
|
|
||||||
tx.send(Ok(Some(validation_code.clone()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionIndexForChild(tx))
|
|
||||||
) => {
|
|
||||||
tx.send(Ok(1u32.into())).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionExecutorParams(sess_idx, tx))
|
|
||||||
) if sess_idx == 1 => {
|
|
||||||
tx.send(Ok(Some(ExecutorParams::default()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
virtual_overseer.recv().await,
|
virtual_overseer.recv().await,
|
||||||
@@ -2026,65 +1800,18 @@ fn cannot_second_multiple_candidates_per_parent() {
|
|||||||
|
|
||||||
virtual_overseer.send(FromOrchestra::Communication { msg: second }).await;
|
virtual_overseer.send(FromOrchestra::Communication { msg: second }).await;
|
||||||
|
|
||||||
assert_matches!(
|
assert_validation_requests(&mut virtual_overseer, validation_code.clone()).await;
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::ValidationCodeByHash(hash, tx))
|
|
||||||
) if hash == validation_code.hash() => {
|
|
||||||
tx.send(Ok(Some(validation_code.clone()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
assert_validate_from_exhaustive(
|
||||||
virtual_overseer.recv().await,
|
&mut virtual_overseer,
|
||||||
AllMessages::RuntimeApi(
|
&pvd,
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionIndexForChild(tx))
|
&pov,
|
||||||
) => {
|
&validation_code,
|
||||||
tx.send(Ok(1u32.into())).unwrap();
|
&candidate,
|
||||||
}
|
expected_head_data,
|
||||||
);
|
test_state.validation_data.clone(),
|
||||||
|
)
|
||||||
assert_matches!(
|
.await;
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionExecutorParams(sess_idx, tx))
|
|
||||||
) if sess_idx == 1 => {
|
|
||||||
tx.send(Ok(Some(ExecutorParams::default()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::CandidateValidation(
|
|
||||||
CandidateValidationMessage::ValidateFromExhaustive(
|
|
||||||
_pvd,
|
|
||||||
_validation_code,
|
|
||||||
candidate_receipt,
|
|
||||||
_pov,
|
|
||||||
_,
|
|
||||||
timeout,
|
|
||||||
tx,
|
|
||||||
),
|
|
||||||
) if _pvd == pvd &&
|
|
||||||
_validation_code == validation_code &&
|
|
||||||
*_pov == pov && &candidate_receipt.descriptor == candidate.descriptor() &&
|
|
||||||
timeout == PvfExecTimeoutKind::Backing &&
|
|
||||||
candidate.commitments.hash() == candidate_receipt.commitments_hash =>
|
|
||||||
{
|
|
||||||
tx.send(Ok(ValidationResult::Valid(
|
|
||||||
CandidateCommitments {
|
|
||||||
head_data: expected_head_data.clone(),
|
|
||||||
horizontal_messages: Default::default(),
|
|
||||||
upward_messages: Default::default(),
|
|
||||||
new_validation_code: None,
|
|
||||||
processed_downward_messages: 0,
|
|
||||||
hrmp_watermark: 0,
|
|
||||||
},
|
|
||||||
test_state.validation_data.clone(),
|
|
||||||
)))
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
virtual_overseer.recv().await,
|
virtual_overseer.recv().await,
|
||||||
@@ -2131,32 +1858,7 @@ fn cannot_second_multiple_candidates_per_parent() {
|
|||||||
virtual_overseer.send(FromOrchestra::Communication { msg: second }).await;
|
virtual_overseer.send(FromOrchestra::Communication { msg: second }).await;
|
||||||
|
|
||||||
// The validation is still requested.
|
// The validation is still requested.
|
||||||
assert_matches!(
|
assert_validation_requests(&mut virtual_overseer, validation_code.clone()).await;
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::ValidationCodeByHash(hash, tx))
|
|
||||||
) if hash == validation_code.hash() => {
|
|
||||||
tx.send(Ok(Some(validation_code.clone()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionIndexForChild(tx))
|
|
||||||
) => {
|
|
||||||
tx.send(Ok(1u32.into())).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionExecutorParams(sess_idx, tx))
|
|
||||||
) if sess_idx == 1 => {
|
|
||||||
tx.send(Ok(Some(ExecutorParams::default()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
virtual_overseer.recv().await,
|
virtual_overseer.recv().await,
|
||||||
|
|||||||
@@ -208,32 +208,7 @@ async fn assert_validate_seconded_candidate(
|
|||||||
expected_head_data: &HeadData,
|
expected_head_data: &HeadData,
|
||||||
fetch_pov: bool,
|
fetch_pov: bool,
|
||||||
) {
|
) {
|
||||||
assert_matches!(
|
assert_validation_requests(virtual_overseer, validation_code.clone()).await;
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(parent, RuntimeApiRequest::ValidationCodeByHash(hash, tx))
|
|
||||||
) if parent == relay_parent && hash == validation_code.hash() => {
|
|
||||||
tx.send(Ok(Some(validation_code.clone()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionIndexForChild(tx))
|
|
||||||
) => {
|
|
||||||
tx.send(Ok(1u32.into())).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
virtual_overseer.recv().await,
|
|
||||||
AllMessages::RuntimeApi(
|
|
||||||
RuntimeApiMessage::Request(_, RuntimeApiRequest::SessionExecutorParams(sess_idx, tx))
|
|
||||||
) if sess_idx == 1 => {
|
|
||||||
tx.send(Ok(Some(ExecutorParams::default()))).unwrap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if fetch_pov {
|
if fetch_pov {
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use ::test_helpers::{dummy_digest, dummy_hash};
|
use ::test_helpers::{dummy_digest, dummy_hash, validator_pubkeys};
|
||||||
use futures::{channel::oneshot, future::BoxFuture, prelude::*};
|
use futures::{channel::oneshot, future::BoxFuture, prelude::*};
|
||||||
use polkadot_node_subsystem::{
|
use polkadot_node_subsystem::{
|
||||||
messages::{
|
messages::{
|
||||||
@@ -94,10 +94,6 @@ struct TestState {
|
|||||||
|
|
||||||
const OUR_VALIDATOR: Sr25519Keyring = Sr25519Keyring::Alice;
|
const OUR_VALIDATOR: Sr25519Keyring = Sr25519Keyring::Alice;
|
||||||
|
|
||||||
fn validator_pubkeys(val_ids: &[Sr25519Keyring]) -> Vec<ValidatorId> {
|
|
||||||
val_ids.iter().map(|v| v.public().into()).collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TestState {
|
impl TestState {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
// Initialize the default session 1. No validators are present there.
|
// Initialize the default session 1. No validators are present there.
|
||||||
|
|||||||
@@ -159,6 +159,11 @@ pub fn dummy_pvd(parent_head: HeadData, relay_parent_number: u32) -> PersistedVa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a meaningless signature
|
||||||
|
pub fn dummy_signature() -> polkadot_primitives::ValidatorSignature {
|
||||||
|
sp_core::crypto::UncheckedFrom::unchecked_from([1u8; 64])
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a meaningless candidate, returning its receipt and PVD.
|
/// Create a meaningless candidate, returning its receipt and PVD.
|
||||||
pub fn make_candidate(
|
pub fn make_candidate(
|
||||||
relay_parent_hash: Hash,
|
relay_parent_hash: Hash,
|
||||||
@@ -244,6 +249,11 @@ pub fn resign_candidate_descriptor_with_collator<H: AsRef<[u8]>>(
|
|||||||
descriptor.signature = signature;
|
descriptor.signature = signature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Extracts validators's public keus (`ValidatorId`) from `Sr25519Keyring`
|
||||||
|
pub fn validator_pubkeys(val_ids: &[Sr25519Keyring]) -> Vec<ValidatorId> {
|
||||||
|
val_ids.iter().map(|v| v.public().into()).collect()
|
||||||
|
}
|
||||||
|
|
||||||
/// Builder for `CandidateReceipt`.
|
/// Builder for `CandidateReceipt`.
|
||||||
pub struct TestCandidateBuilder {
|
pub struct TestCandidateBuilder {
|
||||||
pub para_id: ParaId,
|
pub para_id: ParaId,
|
||||||
@@ -298,7 +308,3 @@ impl rand::RngCore for AlwaysZeroRng {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dummy_signature() -> polkadot_primitives::ValidatorSignature {
|
|
||||||
sp_core::crypto::UncheckedFrom::unchecked_from([1u8; 64])
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -17,11 +17,11 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use frame_support::{assert_err, assert_ok, assert_storage_noop};
|
use frame_support::{assert_err, assert_ok, assert_storage_noop};
|
||||||
use keyring::Sr25519Keyring;
|
use keyring::Sr25519Keyring;
|
||||||
use primitives::{BlockNumber, ValidatorId, PARACHAIN_KEY_TYPE_ID};
|
use primitives::{BlockNumber, PARACHAIN_KEY_TYPE_ID};
|
||||||
use sc_keystore::LocalKeystore;
|
use sc_keystore::LocalKeystore;
|
||||||
use sp_keystore::{Keystore, KeystorePtr};
|
use sp_keystore::{Keystore, KeystorePtr};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use test_helpers::{dummy_head_data, dummy_validation_code};
|
use test_helpers::{dummy_head_data, dummy_validation_code, validator_pubkeys};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
configuration::HostConfiguration,
|
configuration::HostConfiguration,
|
||||||
@@ -39,10 +39,6 @@ static VALIDATORS: &[Sr25519Keyring] = &[
|
|||||||
Sr25519Keyring::Ferdie,
|
Sr25519Keyring::Ferdie,
|
||||||
];
|
];
|
||||||
|
|
||||||
fn validator_pubkeys(val_ids: &[Sr25519Keyring]) -> Vec<ValidatorId> {
|
|
||||||
val_ids.iter().map(|v| v.public().into()).collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sign_and_include_pvf_check_statement(stmt: PvfCheckStatement) {
|
fn sign_and_include_pvf_check_statement(stmt: PvfCheckStatement) {
|
||||||
let validators = &[
|
let validators = &[
|
||||||
Sr25519Keyring::Alice,
|
Sr25519Keyring::Alice,
|
||||||
|
|||||||
@@ -22,10 +22,7 @@ use crate::{
|
|||||||
use assert_matches::assert_matches;
|
use assert_matches::assert_matches;
|
||||||
use keyring::Sr25519Keyring;
|
use keyring::Sr25519Keyring;
|
||||||
use primitives::Hash;
|
use primitives::Hash;
|
||||||
|
use test_helpers::validator_pubkeys;
|
||||||
fn validator_pubkeys(val_ids: &[Sr25519Keyring]) -> Vec<ValidatorId> {
|
|
||||||
val_ids.iter().map(|v| v.public().into()).collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn tracker_earliest_block_number() {
|
fn tracker_earliest_block_number() {
|
||||||
|
|||||||
Reference in New Issue
Block a user