Skip to content
Snippets Groups Projects
Unverified Commit 0284e21f authored by Tsvetomir Dimitrov's avatar Tsvetomir Dimitrov Committed by GitHub
Browse files

Refactor candidates test in paras_inherent (#2004)

Splits the test in multiple cases.
parent e39253c0
No related merge requests found
Pipeline #404586 failed with stages
in 27 minutes and 48 seconds
......@@ -1205,9 +1205,17 @@ mod sanitizers {
}
}
#[test]
fn candidates() {
new_test_ext(MockGenesisConfig::default()).execute_with(|| {
mod candidates {
use super::*;
// Backed candidates and scheduled parachains used for `sanitize_backed_candidates` testing
struct TestData {
backed_candidates: Vec<BackedCandidate>,
scheduled_paras: BTreeMap<primitives::Id, CoreIndex>,
}
// Generate test data for the candidates test
fn get_test_data() -> TestData {
const RELAY_PARENT_NUM: u32 = 3;
let header = default_header();
......@@ -1233,9 +1241,6 @@ mod sanitizers {
.unwrap();
}
let has_concluded_invalid =
|_idx: usize, _backed_candidate: &BackedCandidate| -> bool { false };
let scheduled = (0_usize..2)
.into_iter()
.map(|idx| (ParaId::from(1_u32 + idx as u32), CoreIndex::from(idx as u32)))
......@@ -1278,29 +1283,54 @@ mod sanitizers {
})
.collect::<Vec<_>>();
// happy path
assert_eq!(
sanitize_backed_candidates::<Test, _>(
backed_candidates.clone(),
has_concluded_invalid,
&scheduled
),
backed_candidates
);
TestData { backed_candidates, scheduled_paras: scheduled }
}
// nothing is scheduled, so no paraids match, thus all backed candidates are skipped
{
#[test]
fn happy_path() {
new_test_ext(MockGenesisConfig::default()).execute_with(|| {
let TestData { backed_candidates, scheduled_paras: scheduled } = get_test_data();
let has_concluded_invalid =
|_idx: usize, _backed_candidate: &BackedCandidate| -> bool { false };
assert_eq!(
sanitize_backed_candidates::<Test, _>(
backed_candidates.clone(),
has_concluded_invalid,
&scheduled
),
backed_candidates
);
{}
});
}
// nothing is scheduled, so no paraids match, thus all backed candidates are skipped
#[test]
fn nothing_scheduled() {
new_test_ext(MockGenesisConfig::default()).execute_with(|| {
let TestData { backed_candidates, scheduled_paras: _ } = get_test_data();
let scheduled = &BTreeMap::new();
let has_concluded_invalid =
|_idx: usize, _backed_candidate: &BackedCandidate| -> bool { false };
assert!(sanitize_backed_candidates::<Test, _>(
backed_candidates.clone(),
has_concluded_invalid,
&scheduled
)
.is_empty());
}
});
}
// candidates that have concluded as invalid are filtered out
#[test]
fn invalid_are_filtered_out() {
new_test_ext(MockGenesisConfig::default()).execute_with(|| {
let TestData { backed_candidates, scheduled_paras: scheduled } = get_test_data();
// candidates that have concluded as invalid are filtered out
{
// mark every second one as concluded invalid
let set = {
let mut set = std::collections::HashSet::new();
......@@ -1322,7 +1352,7 @@ mod sanitizers {
.len(),
backed_candidates.len() / 2
);
}
});
});
}
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment