mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 11:01:01 +00:00
Refactor candidates test in paras_inherent (#2004)
Splits the test in multiple cases.
This commit is contained in:
committed by
GitHub
parent
e39253c022
commit
0284e21f55
@@ -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,7 +1283,17 @@ mod sanitizers {
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// happy path
|
||||
TestData { backed_candidates, scheduled_paras: scheduled }
|
||||
}
|
||||
|
||||
#[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(),
|
||||
@@ -1288,19 +1303,34 @@ mod sanitizers {
|
||||
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();
|
||||
|
||||
// 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
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user