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
9066313d
Commit
9066313d
authored
7 years ago
by
Gav
Browse files
Options
Downloads
Patches
Plain Diff
Test for tally
parent
4e19dc6e
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/demo/runtime/src/runtime/council.rs
+43
-1
43 additions, 1 deletion
substrate/demo/runtime/src/runtime/council.rs
with
43 additions
and
1 deletion
substrate/demo/runtime/src/runtime/council.rs
+
43
−
1
View file @
9066313d
...
...
@@ -231,6 +231,11 @@ pub fn approvals_of(voter: &AccountId) -> Vec<bool> {
storage
::
get_or_default
(
&
voter
.to_keyed_vec
(
APPROVALS_OF
))
}
/// Get the leaderboard if we;re in the presentation phase.
pub
fn
leaderboard
()
->
Option
<
Vec
<
(
Balance
,
AccountId
)
>>
{
storage
::
get
(
LEADERBOARD
)
}
pub
mod
public
{
use
super
::
*
;
...
...
@@ -356,7 +361,7 @@ pub mod public {
let
bad_presentation_punishment
=
present_slash_per_voter
()
*
voters
.len
()
as
Balance
;
assert!
(
b
>=
bad_presentation_punishment
);
let
mut
leaderboard
:
Vec
<
(
Balance
,
AccountId
)
>
=
storage
::
get_or_default
(
LEADERBOARD
);
let
mut
leaderboard
=
leaderboard
()
.expect
(
"leaderboard must exist while present phase active"
);
assert!
(
total
>
leaderboard
[
0
]
.0
);
let
(
registered_since
,
candidate_index
):
(
VoteIndex
,
u32
)
=
...
...
@@ -519,6 +524,7 @@ fn finalise_tally() {
}
storage
::
put
(
CANDIDATES
,
&
(
new_candidates
));
storage
::
put
(
CANDIDATE_COUNT
,
&
count
);
storage
::
put
(
VOTE_COUNT
,
&
(
vote_index
()
+
1
));
}
#[cfg(test)]
...
...
@@ -906,4 +912,40 @@ mod tests {
public
::
retract_voter
(
&
bob
,
0
);
});
}
#[test]
fn
simple_tally_should_work
()
{
let
bob
=
Keyring
::
Bob
.to_raw_public
();
let
eve
=
Keyring
::
Eve
.to_raw_public
();
let
dave
=
Keyring
::
Dave
.to_raw_public
();
let
mut
t
=
new_test_ext
();
with_externalities
(
&
mut
t
,
||
{
with_env
(|
e
|
e
.block_number
=
4
);
assert!
(
!
presentation_active
());
public
::
submit_candidacy
(
&
bob
,
0
);
public
::
submit_candidacy
(
&
eve
,
1
);
public
::
set_approvals
(
&
bob
,
&
vec!
[
true
,
false
],
0
);
public
::
set_approvals
(
&
eve
,
&
vec!
[
false
,
true
],
0
);
internal
::
end_block
();
with_env
(|
e
|
e
.block_number
=
6
);
assert!
(
presentation_active
());
public
::
present
(
&
dave
,
&
bob
,
8
,
0
);
public
::
present
(
&
dave
,
&
eve
,
38
,
0
);
assert_eq!
(
leaderboard
(),
Some
(
vec!
[(
0
,
AccountId
::
default
()),
(
0
,
AccountId
::
default
()),
(
8
,
bob
.clone
()),
(
38
,
eve
.clone
())]));
internal
::
end_block
();
assert!
(
!
presentation_active
());
assert_eq!
(
active_council
(),
vec!
[(
eve
.clone
(),
11
),
(
bob
.clone
(),
11
)]);
assert!
(
!
is_a_candidate
(
&
bob
));
assert!
(
!
is_a_candidate
(
&
eve
));
assert_eq!
(
vote_index
(),
1
);
assert_eq!
(
voter_last_active
(
&
bob
),
Some
(
0
));
assert_eq!
(
voter_last_active
(
&
eve
),
Some
(
0
));
});
}
}
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