Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Async backing statement distribution: Candidates tests #6658

12 changes: 9 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 41 additions & 60 deletions node/core/prospective-parachains/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use super::*;
use ::polkadot_primitives_test_helpers::{dummy_candidate_receipt_bad_sig, dummy_hash};
use assert_matches::assert_matches;
use polkadot_node_subsystem::{
errors::RuntimeApiError,
Expand All @@ -27,12 +26,11 @@ use polkadot_node_subsystem::{
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_node_subsystem_types::{jaeger, ActivatedLeaf, LeafStatus};
use polkadot_primitives::{
v2::{
CandidateCommitments, HeadData, Header, PersistedValidationData, ScheduledCore,
ValidationCodeHash,
},
vstaging::{AsyncBackingParameters, Constraints, InboundHrmpLimitations},
CommittedCandidateReceipt, HeadData, Header, PersistedValidationData, ScheduledCore,
ValidationCodeHash,
};
use polkadot_primitives_test_helpers::make_candidate;
use std::sync::Arc;

const ALLOWED_ANCESTRY_LEN: u32 = 3;
Expand Down Expand Up @@ -70,42 +68,6 @@ fn dummy_constraints(
}
}

fn dummy_pvd(parent_head: HeadData, relay_parent_number: u32) -> PersistedValidationData {
PersistedValidationData {
parent_head,
relay_parent_number,
max_pov_size: MAX_POV_SIZE,
relay_parent_storage_root: dummy_hash(),
}
}

fn make_candidate(
leaf: &TestLeaf,
para_id: ParaId,
parent_head: HeadData,
head_data: HeadData,
validation_code_hash: ValidationCodeHash,
) -> (CommittedCandidateReceipt, PersistedValidationData) {
let pvd = dummy_pvd(parent_head, leaf.number);
let commitments = CandidateCommitments {
head_data,
horizontal_messages: Vec::new(),
upward_messages: Vec::new(),
new_validation_code: None,
processed_downward_messages: 0,
hrmp_watermark: leaf.number,
};

let mut candidate = dummy_candidate_receipt_bad_sig(leaf.hash, Some(Default::default()));
candidate.commitments_hash = commitments.hash();
candidate.descriptor.para_id = para_id;
candidate.descriptor.persisted_validation_data_hash = pvd.hash();
candidate.descriptor.validation_code_hash = validation_code_hash;
let candidate = CommittedCandidateReceipt { descriptor: candidate.descriptor, commitments };

(candidate, pvd)
}

struct TestState {
availability_cores: Vec<CoreState>,
validation_code_hash: ValidationCodeHash,
Expand Down Expand Up @@ -539,7 +501,8 @@ fn send_candidates_and_check_if_found() {

// Candidate A1
let (candidate_a1, pvd_a1) = make_candidate(
&leaf_a,
leaf_a.hash,
leaf_a.number,
1.into(),
HeadData(vec![1, 2, 3]),
HeadData(vec![1]),
Expand All @@ -550,7 +513,8 @@ fn send_candidates_and_check_if_found() {

// Candidate A2
let (candidate_a2, pvd_a2) = make_candidate(
&leaf_a,
leaf_a.hash,
leaf_a.number,
2.into(),
HeadData(vec![2, 3, 4]),
HeadData(vec![2]),
Expand All @@ -561,7 +525,8 @@ fn send_candidates_and_check_if_found() {

// Candidate B
let (candidate_b, pvd_b) = make_candidate(
&leaf_b,
leaf_b.hash,
leaf_b.number,
1.into(),
HeadData(vec![3, 4, 5]),
HeadData(vec![3]),
Expand All @@ -572,7 +537,8 @@ fn send_candidates_and_check_if_found() {

// Candidate C
let (candidate_c, pvd_c) = make_candidate(
&leaf_c,
leaf_c.hash,
leaf_c.number,
2.into(),
HeadData(vec![6, 7, 8]),
HeadData(vec![4]),
Expand Down Expand Up @@ -649,7 +615,8 @@ fn check_candidate_parent_leaving_view() {

// Candidate A1
let (candidate_a1, pvd_a1) = make_candidate(
&leaf_a,
leaf_a.hash,
leaf_a.number,
1.into(),
HeadData(vec![1, 2, 3]),
HeadData(vec![1]),
Expand All @@ -660,7 +627,8 @@ fn check_candidate_parent_leaving_view() {

// Candidate A2
let (candidate_a2, pvd_a2) = make_candidate(
&leaf_a,
leaf_a.hash,
leaf_a.number,
2.into(),
HeadData(vec![2, 3, 4]),
HeadData(vec![2]),
Expand All @@ -671,7 +639,8 @@ fn check_candidate_parent_leaving_view() {

// Candidate B
let (candidate_b, pvd_b) = make_candidate(
&leaf_b,
leaf_b.hash,
leaf_b.number,
1.into(),
HeadData(vec![3, 4, 5]),
HeadData(vec![3]),
Expand All @@ -682,7 +651,8 @@ fn check_candidate_parent_leaving_view() {

// Candidate C
let (candidate_c, pvd_c) = make_candidate(
&leaf_c,
leaf_c.hash,
leaf_c.number,
2.into(),
HeadData(vec![6, 7, 8]),
HeadData(vec![4]),
Expand Down Expand Up @@ -771,7 +741,8 @@ fn check_candidate_on_multiple_forks() {

// Candidate on leaf A.
let (candidate_a, pvd_a) = make_candidate(
&leaf_a,
leaf_a.hash,
leaf_a.number,
1.into(),
HeadData(vec![1, 2, 3]),
HeadData(vec![1]),
Expand All @@ -782,7 +753,8 @@ fn check_candidate_on_multiple_forks() {

// Candidate on leaf B.
let (candidate_b, pvd_b) = make_candidate(
&leaf_b,
leaf_b.hash,
leaf_b.number,
1.into(),
HeadData(vec![3, 4, 5]),
HeadData(vec![1]),
Expand All @@ -793,7 +765,8 @@ fn check_candidate_on_multiple_forks() {

// Candidate on leaf C.
let (candidate_c, pvd_c) = make_candidate(
&leaf_c,
leaf_c.hash,
leaf_c.number,
1.into(),
HeadData(vec![5, 6, 7]),
HeadData(vec![1]),
Expand Down Expand Up @@ -860,7 +833,8 @@ fn check_backable_query() {

// Candidate A
let (candidate_a, pvd_a) = make_candidate(
&leaf_a,
leaf_a.hash,
leaf_a.number,
1.into(),
HeadData(vec![1, 2, 3]),
HeadData(vec![1]),
Expand All @@ -871,7 +845,8 @@ fn check_backable_query() {

// Candidate B
let (mut candidate_b, pvd_b) = make_candidate(
&leaf_a,
leaf_a.hash,
leaf_a.number,
1.into(),
HeadData(vec![1]),
HeadData(vec![2]),
Expand Down Expand Up @@ -970,7 +945,8 @@ fn check_depth_query() {

// Candidate A.
let (candidate_a, pvd_a) = make_candidate(
&leaf_a,
leaf_a.hash,
leaf_a.number,
1.into(),
HeadData(vec![1, 2, 3]),
HeadData(vec![1]),
Expand All @@ -981,7 +957,8 @@ fn check_depth_query() {

// Candidate B.
let (candidate_b, pvd_b) = make_candidate(
&leaf_a,
leaf_a.hash,
leaf_a.number,
1.into(),
HeadData(vec![1]),
HeadData(vec![2]),
Expand All @@ -992,7 +969,8 @@ fn check_depth_query() {

// Candidate C.
let (candidate_c, pvd_c) = make_candidate(
&leaf_a,
leaf_a.hash,
leaf_a.number,
1.into(),
HeadData(vec![2]),
HeadData(vec![3]),
Expand Down Expand Up @@ -1120,7 +1098,8 @@ fn check_pvd_query() {

// Candidate A.
let (candidate_a, pvd_a) = make_candidate(
&leaf_a,
leaf_a.hash,
leaf_a.number,
1.into(),
HeadData(vec![1, 2, 3]),
HeadData(vec![1]),
Expand All @@ -1130,7 +1109,8 @@ fn check_pvd_query() {

// Candidate B.
let (candidate_b, pvd_b) = make_candidate(
&leaf_a,
leaf_a.hash,
leaf_a.number,
1.into(),
HeadData(vec![1]),
HeadData(vec![2]),
Expand All @@ -1140,7 +1120,8 @@ fn check_pvd_query() {

// Candidate C.
let (candidate_c, pvd_c) = make_candidate(
&leaf_a,
leaf_a.hash,
leaf_a.number,
1.into(),
HeadData(vec![2]),
HeadData(vec![3]),
Expand Down
2 changes: 1 addition & 1 deletion node/network/statement-distribution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ fatality = "0.0.6"
bitvec = "1"

[dev-dependencies]
polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" }
assert_matches = "1.4.0"
polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" }
sp-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down
Loading