From dda6042820bbe93b3d8ade0d410322fa01d85faf Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 10 Jan 2020 13:59:41 +0100 Subject: [PATCH 1/3] fix is_runner() --- frame/elections-phragmen/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index 18b010295c307..3dbed0dc4fdce 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -161,8 +161,8 @@ decl_storage! { /// Locked stake of a voter. pub StakeOf get(fn stake_of): map T::AccountId => BalanceOf; - /// The present candidate list. Sorted based on account id. A current member can never enter - /// this vector and is always implicitly assumed to be a candidate. + /// The present candidate list. Sorted based on account-id. A current member or a runner can + /// never enter this vector and is always implicitly assumed to be a candidate. pub Candidates get(fn candidates): Vec; } } @@ -535,7 +535,7 @@ impl Module { /// /// Limited number of runners-up. Binary search. Constant time factor. O(1) fn is_runner(who: &T::AccountId) -> bool { - Self::runners_up().binary_search_by(|(a, _b)| a.cmp(who)).is_ok() + Self::runners_up().iter().position(|(a, _b)| a == who).is_some() } /// Returns number of desired members. From b02b7c7be9b9e01e1246fc67c8bc8d68e8265503 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 10 Jan 2020 14:27:07 +0100 Subject: [PATCH 2/3] add a test --- frame/elections-phragmen/src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index 3dbed0dc4fdce..078c659509dcd 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -2080,4 +2080,23 @@ mod tests { ); }) } + + #[test] + fn behavior_with_dupe_candidate() { + ExtBuilder::default().desired_runners_up(2).build().execute_with(|| { + >::put(vec![1, 1, 2, 3, 4]); + + assert_ok!(Elections::vote(Origin::signed(5), vec![1], 50)); + assert_ok!(Elections::vote(Origin::signed(4), vec![4], 40)); + assert_ok!(Elections::vote(Origin::signed(3), vec![3], 30)); + assert_ok!(Elections::vote(Origin::signed(2), vec![2], 20)); + + System::set_block_number(5); + assert_ok!(Elections::end_block(System::block_number())); + + assert_eq!(Elections::members_ids(), vec![1, 1]); + assert_eq!(Elections::runners_up_ids(), vec![4, 3]); + assert_eq!(Elections::candidates(), vec![]); + }) + } } From f12954dccb354016c5e60b910f241be7542fd291 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 10 Jan 2020 14:29:48 +0100 Subject: [PATCH 3/3] Bump --- bin/node/runtime/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index b277ac843863e..b3ff8b16283ca 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -80,8 +80,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to equal spec_version. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 201, - impl_version: 201, + spec_version: 202, + impl_version: 202, apis: RUNTIME_API_VERSIONS, };