Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
0284e21f
Unverified
Commit
0284e21f
authored
1 year ago
by
Tsvetomir Dimitrov
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Refactor candidates test in paras_inherent (#2004)
Splits the test in multiple cases.
parent
e39253c0
Branches
gh-readonly-queue/master/pr-5442-b3c2a25b73bb4854f26204068f0aec3e8577196c
Branches containing commit
No related merge requests found
Pipeline
#404586
failed with stages
in 27 minutes and 48 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
polkadot/runtime/parachains/src/paras_inherent/tests.rs
+52
-22
52 additions, 22 deletions
polkadot/runtime/parachains/src/paras_inherent/tests.rs
with
52 additions
and
22 deletions
polkadot/runtime/parachains/src/paras_inherent/tests.rs
+
52
−
22
View file @
0284e21f
...
...
@@ -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
);
}
}
);
}
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment