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
a079be3e
Commit
a079be3e
authored
6 years ago
by
asynchronous rob
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Update some outdated slashing tests in runtime (#565)
* fix session slashing test * fix staking slashing tests
parent
68c1fc0b
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
substrate/substrate/runtime/session/src/lib.rs
+4
-17
4 additions, 17 deletions
substrate/substrate/runtime/session/src/lib.rs
substrate/substrate/runtime/staking/src/tests.rs
+4
-4
4 additions, 4 deletions
substrate/substrate/runtime/staking/src/tests.rs
with
8 additions
and
21 deletions
substrate/substrate/runtime/session/src/lib.rs
+
4
−
17
View file @
a079be3e
...
...
@@ -232,17 +232,6 @@ impl<T: Trait> Module<T> {
let
block_number
=
<
system
::
Module
<
T
>>
::
block_number
();
length_minus_1
-
(
block_number
-
Self
::
last_length_change
()
+
length_minus_1
)
%
length
}
/// Returns `true` if the current validator set is taking took long to validate blocks.
pub
fn
broken_validation
()
->
bool
{
let
now
=
<
timestamp
::
Module
<
T
>>
::
get
();
let
block_period
=
<
timestamp
::
Module
<
T
>>
::
block_period
();
let
blocks_remaining
=
Self
::
blocks_remaining
();
let
blocks_remaining
=
<
T
::
Moment
as
As
<
T
::
BlockNumber
>>
::
sa
(
blocks_remaining
);
now
+
blocks_remaining
*
block_period
>
Self
::
current_start
()
+
Self
::
ideal_session_duration
()
*
(
T
::
Moment
::
sa
(
100
)
+
Self
::
broken_percent_late
())
/
T
::
Moment
::
sa
(
100
)
}
}
impl
<
T
:
Trait
>
Executable
for
Module
<
T
>
{
...
...
@@ -358,7 +347,7 @@ mod tests {
}
#[test]
fn
should_
identify_broken
_validat
ion
()
{
fn
should_
rotate_on_bad
_validat
ors
()
{
with_externalities
(
&
mut
new_test_ext
(),
||
{
System
::
set_block_number
(
2
);
assert_eq!
(
Session
::
blocks_remaining
(),
0
);
...
...
@@ -370,18 +359,16 @@ mod tests {
assert_eq!
(
Session
::
current_start
(),
0
);
assert_eq!
(
Session
::
ideal_session_duration
(),
15
);
// ideal end = 0 + 15 * 3 = 15
// broken_limit = 15 * 130 / 100 = 19
System
::
set_block_number
(
3
);
assert_eq!
(
Session
::
blocks_remaining
(),
2
);
Timestamp
::
set_timestamp
(
9
);
// earliest end = 9 + 2 * 5 = 19; OK.
assert!
(
!
Session
::
broken_validation
());
Timestamp
::
set_timestamp
(
9
);
// no bad validators. session not rotated.
Session
::
check_rotate_session
();
System
::
set_block_number
(
4
);
::
system
::
ExtrinsicIndex
::
<
Test
>
::
put
(
1
);
assert_eq!
(
Session
::
blocks_remaining
(),
1
);
Timestamp
::
set_timestamp
(
15
);
// another 1 second late. earliest end = 15 + 1 * 5 = 20; broken.
assert!
(
Session
::
broken_validation
());
Session
::
note_offline
(
&
0
,
vec!
[
1
])
.unwrap
();
// bad validator -> session rotate
Session
::
check_rotate_session
();
assert_eq!
(
Session
::
current_index
(),
2
);
});
...
...
This diff is collapsed.
Click to expand it.
substrate/substrate/runtime/staking/src/tests.rs
+
4
−
4
View file @
a079be3e
...
...
@@ -87,7 +87,8 @@ fn slashing_should_work() {
assert_eq!
(
Staking
::
voting_balance
(
&
10
),
21
);
System
::
set_block_number
(
7
);
Timestamp
::
set_timestamp
(
100
);
// way too late - early exit.
::
system
::
ExtrinsicIndex
::
<
Test
>
::
put
(
1
);
Session
::
note_offline
(
&
0
,
vec!
[
0
])
.unwrap
();
// val 10 reported bad.
Session
::
check_rotate_session
();
assert_eq!
(
Staking
::
current_era
(),
1
);
assert_eq!
(
Session
::
current_index
(),
3
);
...
...
@@ -310,9 +311,9 @@ fn nominating_slashes_should_work() {
assert_eq!
(
Staking
::
voting_balance
(
&
4
),
40
);
System
::
set_block_number
(
5
);
Timestamp
::
set_timestamp
(
100
);
// late
::
system
::
ExtrinsicIndex
::
<
Test
>
::
put
(
1
);
Session
::
note_offline
(
&
0
,
vec!
[
0
,
1
])
.unwrap
();
// both get reported offline.
assert_eq!
(
Session
::
blocks_remaining
(),
1
);
assert!
(
Session
::
broken_validation
());
Session
::
check_rotate_session
();
assert_eq!
(
Staking
::
current_era
(),
2
);
...
...
@@ -388,7 +389,6 @@ fn staking_eras_work() {
// Block 6: No change.
System
::
set_block_number
(
6
);
assert!
(
!
Session
::
broken_validation
());
Session
::
check_rotate_session
();
assert_eq!
(
Session
::
current_index
(),
6
);
assert_eq!
(
Staking
::
sessions_per_era
(),
3
);
...
...
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