Browse Source

referendum - current cycle id counter removal

ondratra 4 years ago
parent
commit
49eb7444c7

+ 1 - 1
runtime-modules/council/src/lib.rs

@@ -882,7 +882,7 @@ impl<T: Trait> Mutations<T> {
         let extra_winning_target_count = T::CouncilSize::get() - 1;
 
         // start referendum
-        T::Referendum::force_start(extra_winning_target_count);
+        T::Referendum::force_start(extra_winning_target_count, AnnouncementPeriodNr::get());
 
         let block_number = <system::Module<T>>::block_number();
 

+ 14 - 7
runtime-modules/council/src/mock.rs

@@ -15,8 +15,8 @@ use frame_support::{
 };
 use rand::Rng;
 use referendum::{
-    Balance as BalanceReferendum, CastVote, CurrentCycleId, OptionResult, ReferendumManager,
-    ReferendumStage, ReferendumStageRevealing,
+    Balance as BalanceReferendum, CastVote, OptionResult, ReferendumManager, ReferendumStage,
+    ReferendumStageRevealing,
 };
 use sp_core::H256;
 use sp_io;
@@ -215,7 +215,6 @@ impl referendum::Trait<ReferendumInstance> for RuntimeReferendum {
 
     fn can_unlock_vote_stake(
         vote: &CastVote<Self::Hash, BalanceReferendum<Self, ReferendumInstance>>,
-        current_voting_cycle_id: &u64,
     ) -> bool {
         // trigger fail when requested to do so
         if !IS_UNSTAKE_ENABLED.with(|value| value.borrow().0) {
@@ -224,7 +223,7 @@ impl referendum::Trait<ReferendumInstance> for RuntimeReferendum {
 
         <Module<Runtime> as ReferendumConnection<Runtime>>::can_unlock_vote_stake(
             vote,
-            current_voting_cycle_id,
+            &AnnouncementPeriodNr::get(),
         )
         .is_ok()
     }
@@ -524,10 +523,16 @@ where
         }
     }
 
-    pub fn generate_voter(index: u64, stake: Balance<T>, vote_for_index: u64) -> VoterInfo<T> {
+    pub fn generate_voter(
+        index: u64,
+        stake: Balance<T>,
+        vote_for_index: u64,
+        cycle_id: u64,
+    ) -> VoterInfo<T> {
         let account_id = VOTER_BASE_ID + index;
         let origin = OriginType::Signed(account_id.into());
-        let (commitment, salt) = Self::vote_commitment(&account_id.into(), &vote_for_index.into());
+        let (commitment, salt) =
+            Self::vote_commitment(&account_id.into(), &vote_for_index.into(), &cycle_id);
 
         Self::topup_account(account_id.into(), stake);
 
@@ -550,8 +555,8 @@ where
     pub fn vote_commitment(
         account_id: &<T as system::Trait>::AccountId,
         vote_option_index: &u64,
+        cycle_id: &u64,
     ) -> (T::Hash, Vec<u8>) {
-        let cycle_id = CurrentCycleId::<ReferendumInstance>::get();
         let salt = Self::generate_salt();
 
         (
@@ -653,6 +658,7 @@ where
                         vote_power: item.vote_power.into(),
                     })
                     .collect(),
+                current_cycle_id: AnnouncementPeriodNr::get(),
             }),
         );
 
@@ -996,6 +1002,7 @@ where
                     index as u64 + users_offset,
                     vote_stake.into(),
                     CANDIDATE_BASE_ID + votes_map[index] + users_offset,
+                    AnnouncementPeriodNr::get(),
                 )
             })
             .collect();

+ 11 - 1
runtime-modules/council/src/tests.rs

@@ -1,7 +1,8 @@
 #![cfg(test)]
 
 use super::{
-    Budget, CouncilMemberOf, CouncilMembers, CouncilStageAnnouncing, Error, Module, Trait,
+    AnnouncementPeriodNr, Budget, CouncilMemberOf, CouncilMembers, CouncilStageAnnouncing, Error,
+    Module, Trait,
 };
 use crate::mock::*;
 use crate::staking_handler::mocks::{CANDIDATE_BASE_ID, VOTER_CANDIDATE_OFFSET};
@@ -133,6 +134,7 @@ fn council_can_vote_for_yourself() {
             VOTER_CANDIDATE_OFFSET,
             vote_stake,
             self_voting_candidate_index,
+            AnnouncementPeriodNr::get(),
         );
         Mocks::vote_for_candidate(
             voter.origin.clone(),
@@ -283,6 +285,7 @@ fn council_announcement_reset_on_not_enough_winners() {
                     index as u64,
                     vote_stake,
                     CANDIDATE_BASE_ID + votes_map[index],
+                    AnnouncementPeriodNr::get(),
                 )
             })
             .collect();
@@ -374,6 +377,7 @@ fn council_two_consecutive_rounds() {
                     index as u64,
                     vote_stake,
                     CANDIDATE_BASE_ID + votes_map[index],
+                    AnnouncementPeriodNr::get(),
                 )
             })
             .collect();
@@ -399,6 +403,7 @@ fn council_two_consecutive_rounds() {
                     index as u64,
                     vote_stake,
                     CANDIDATE_BASE_ID + votes_map2[index],
+                    AnnouncementPeriodNr::get(),
                 )
             })
             .collect();
@@ -563,6 +568,7 @@ fn council_candidate_stake_can_be_unlocked() {
                     index as u64,
                     vote_stake,
                     CANDIDATE_BASE_ID + votes_map[index],
+                    AnnouncementPeriodNr::get(),
                 )
             })
             .collect();
@@ -669,6 +675,7 @@ fn council_candidate_stake_automaticly_converted() {
                     index as u64,
                     vote_stake,
                     CANDIDATE_BASE_ID + votes_map[index],
+                    AnnouncementPeriodNr::get(),
                 )
             })
             .collect();
@@ -759,6 +766,7 @@ fn council_member_stake_is_locked() {
                     index as u64,
                     vote_stake,
                     CANDIDATE_BASE_ID + votes_map[index],
+                    AnnouncementPeriodNr::get(),
                 )
             })
             .collect();
@@ -816,6 +824,7 @@ fn council_member_stake_automaticly_unlocked() {
                     index as u64,
                     vote_stake,
                     CANDIDATE_BASE_ID + votes_map2[index],
+                    AnnouncementPeriodNr::get(),
                 )
             })
             .collect();
@@ -897,6 +906,7 @@ fn council_candidacy_set_note() {
                     index as u64,
                     vote_stake,
                     CANDIDATE_BASE_ID + votes_map[index],
+                    AnnouncementPeriodNr::get(),
                 )
             })
             .collect();

+ 51 - 45
runtime-modules/referendum/src/lib.rs

@@ -73,6 +73,7 @@ impl<BlockNumber, VotePower: Encode + Decode> Default for ReferendumStage<BlockN
 pub struct ReferendumStageVoting<BlockNumber> {
     pub started: BlockNumber,      // block in which referendum started
     pub winning_target_count: u64, // target number of winners
+    pub current_cycle_id: u64,     // index of current election
 }
 
 /// Representation for revealing stage state.
@@ -81,6 +82,7 @@ pub struct ReferendumStageRevealing<BlockNumber, VotePower> {
     pub started: BlockNumber,      // block in which referendum started
     pub winning_target_count: u64, // target number of winners
     pub intermediate_winners: Vec<OptionResult<VotePower>>, // intermediate winning options
+    pub current_cycle_id: u64,     // index of current election
 }
 
 #[derive(Encode, Decode, PartialEq, Eq, Debug, Default, Clone)]
@@ -136,11 +138,15 @@ pub trait ReferendumManager<Origin, AccountId, Hash> {
     type Currency: LockableCurrency<AccountId>;
 
     /// Start a new referendum.
-    fn start_referendum(origin: Origin, extra_winning_target_count: u64) -> Result<(), ()>;
+    fn start_referendum(
+        origin: Origin,
+        extra_winning_target_count: u64,
+        cycle_id: u64,
+    ) -> Result<(), ()>;
 
     /// Start referendum independent of the current state.
     /// If an election is running before calling this function, it will be discontinued without any winners selected.
-    fn force_start(extra_winning_target_count: u64);
+    fn force_start(extra_winning_target_count: u64, cycle_id: u64);
 
     /// Calculate commitment for a vote.
     fn calculate_commitment(
@@ -194,10 +200,7 @@ pub trait Trait<I: Instance>: system::Trait {
 
     /// Checks if user can unlock his stake from the given vote.
     /// Gives runtime an ability to penalize user for not revealing stake, etc.
-    fn can_unlock_vote_stake(
-        vote: &CastVote<Self::Hash, Balance<Self, I>>,
-        current_voting_cycle_id: &u64,
-    ) -> bool;
+    fn can_unlock_vote_stake(vote: &CastVote<Self::Hash, Balance<Self, I>>) -> bool;
 
     /// Gives runtime an ability to react on referendum result.
     fn process_results(winners: &[OptionResult<Self::VotePower>]);
@@ -222,9 +225,6 @@ decl_storage! {
         /// A record is finally removed when the user unstakes, which can happen during a voting stage or after the current cycle ends.
         /// A stake for a vote can be reused in future referendum cycles.
         pub Votes get(fn votes) config(): map hasher(blake2_128_concat) T::AccountId => CastVoteOf<T, I>;
-
-        /// Index of the current referendum cycle. It is incremented everytime referendum ends.
-        pub CurrentCycleId get(fn current_cycle_id) config(): u64;
     }
 }
 
@@ -335,14 +335,14 @@ decl_module! {
         #[weight = 10_000_000]
         pub fn vote(origin, commitment: T::Hash, stake: Balance<T, I>) -> Result<(), Error<T, I>> {
             // ensure action can be started
-            let account_id = EnsureChecks::<T, I>::can_vote(origin, &stake)?;
+            let (current_cycle_id, account_id) = EnsureChecks::<T, I>::can_vote(origin, &stake)?;
 
             //
             // == MUTATION SAFE ==
             //
 
             // start revealing phase - it can return error when stake fails to lock
-            Mutations::<T, I>::vote(&account_id, &commitment, &stake)?;
+            Mutations::<T, I>::vote(&account_id, &commitment, &stake, &current_cycle_id)?;
 
             // emit event
             Self::deposit_event(RawEvent::VoteCast(account_id, commitment, stake));
@@ -439,7 +439,11 @@ impl<T: Trait<I>, I: Instance> ReferendumManager<T::Origin, T::AccountId, T::Has
     type Currency = T::Currency;
 
     /// Start new referendum run.
-    fn start_referendum(origin: T::Origin, extra_winning_target_count: u64) -> Result<(), ()> {
+    fn start_referendum(
+        origin: T::Origin,
+        extra_winning_target_count: u64,
+        cycle_id: u64,
+    ) -> Result<(), ()> {
         let winning_target_count = extra_winning_target_count + 1;
 
         // ensure action can be started
@@ -450,7 +454,7 @@ impl<T: Trait<I>, I: Instance> ReferendumManager<T::Origin, T::AccountId, T::Has
         //
 
         // update state
-        Mutations::<T, I>::start_voting_period(&winning_target_count);
+        Mutations::<T, I>::start_voting_period(&winning_target_count, &cycle_id);
 
         // emit event
         Self::deposit_event(RawEvent::ReferendumStarted(winning_target_count));
@@ -460,20 +464,17 @@ impl<T: Trait<I>, I: Instance> ReferendumManager<T::Origin, T::AccountId, T::Has
 
     /// Start referendum independent of the current state.
     /// If an election is running before calling this function, it will be discontinued without any winners selected.
-    fn force_start(extra_winning_target_count: u64) {
+    fn force_start(extra_winning_target_count: u64, cycle_id: u64) {
         let winning_target_count = extra_winning_target_count + 1;
 
         // remember if referendum is running
         let referendum_running = !matches!(Stage::<T, I>::get(), ReferendumStage::Inactive);
 
         // update state
-        Mutations::<T, I>::start_voting_period(&winning_target_count);
+        Mutations::<T, I>::start_voting_period(&winning_target_count, &cycle_id);
 
         // emit event
         if referendum_running {
-            // distinguish between new and old cycles
-            Mutations::<T, I>::increase_cycle_id();
-
             Self::deposit_event(RawEvent::ReferendumStartedForcefully(winning_target_count));
         } else {
             Self::deposit_event(RawEvent::ReferendumStarted(winning_target_count));
@@ -508,13 +509,14 @@ struct Mutations<T: Trait<I>, I: Instance> {
 
 impl<T: Trait<I>, I: Instance> Mutations<T, I> {
     /// Change the referendum stage from inactive to voting stage.
-    fn start_voting_period(winning_target_count: &u64) {
+    fn start_voting_period(winning_target_count: &u64, cycle_id: &u64) {
         // change referendum state
         Stage::<T, I>::put(ReferendumStage::Voting(ReferendumStageVoting::<
             T::BlockNumber,
         > {
             started: <system::Module<T>>::block_number() + 1.into(),
             winning_target_count: *winning_target_count,
+            current_cycle_id: *cycle_id,
         }));
     }
 
@@ -528,6 +530,7 @@ impl<T: Trait<I>, I: Instance> Mutations<T, I> {
             started: <system::Module<T>>::block_number() + 1.into(),
             winning_target_count: old_stage.winning_target_count,
             intermediate_winners: vec![],
+            current_cycle_id: old_stage.current_cycle_id,
         }));
     }
 
@@ -537,22 +540,17 @@ impl<T: Trait<I>, I: Instance> Mutations<T, I> {
     ) -> Vec<OptionResult<<T as Trait<I>>::VotePower>> {
         // reset referendum state
         Stage::<T, I>::put(ReferendumStage::Inactive);
-        Self::increase_cycle_id();
 
         // return winning option
         revealing_stage.intermediate_winners
     }
 
-    /// Increase the cycle councter.
-    fn increase_cycle_id() {
-        CurrentCycleId::<I>::put(CurrentCycleId::<I>::get() + 1);
-    }
-
     /// Cast a user's sealed vote for the current referendum cycle.
     fn vote(
         account_id: &<T as system::Trait>::AccountId,
         commitment: &T::Hash,
         stake: &Balance<T, I>,
+        current_cycle_id: &u64,
     ) -> Result<(), Error<T, I>> {
         // lock stake amount
         T::Currency::set_lock(
@@ -568,7 +566,7 @@ impl<T: Trait<I>, I: Instance> Mutations<T, I> {
             CastVote {
                 commitment: *commitment,
                 stake: *stake,
-                cycle_id: CurrentCycleId::<I>::get(),
+                cycle_id: *current_cycle_id,
                 vote_for: None,
             },
         );
@@ -737,8 +735,12 @@ impl<T: Trait<I>, I: Instance> EnsureChecks<T, I> {
         Ok(())
     }
 
-    fn can_vote(origin: T::Origin, stake: &Balance<T, I>) -> Result<T::AccountId, Error<T, I>> {
+    fn can_vote(
+        origin: T::Origin,
+        stake: &Balance<T, I>,
+    ) -> Result<(u64, T::AccountId), Error<T, I>> {
         fn prevent_repeated_vote<T: Trait<I>, I: Instance>(
+            cycle_id: &u64,
             account_id: &T::AccountId,
         ) -> Result<(), Error<T, I>> {
             if !Votes::<T, I>::contains_key(&account_id) {
@@ -748,7 +750,7 @@ impl<T: Trait<I>, I: Instance> EnsureChecks<T, I> {
             let existing_vote = Votes::<T, I>::get(&account_id);
 
             // don't allow repeated vote
-            if existing_vote.cycle_id == CurrentCycleId::<I>::get() {
+            if existing_vote.cycle_id == *cycle_id {
                 return Err(Error::<T, I>::AlreadyVotedThisCycle);
             }
 
@@ -758,16 +760,14 @@ impl<T: Trait<I>, I: Instance> EnsureChecks<T, I> {
         // ensure superuser requested action
         let account_id = Self::ensure_regular_user(origin)?;
 
-        let stage = Stage::<T, I>::get();
-
         // ensure referendum is running
-        match stage {
-            ReferendumStage::Voting(_) => (),
+        let current_cycle_id = match Stage::<T, I>::get() {
+            ReferendumStage::Voting(tmp_stage_data) => tmp_stage_data.current_cycle_id,
             _ => return Err(Error::ReferendumNotRunning),
         };
 
         // prevent repeated vote
-        prevent_repeated_vote::<T, I>(&account_id)?;
+        prevent_repeated_vote::<T, I>(&current_cycle_id, &account_id)?;
 
         // ensure stake is enough for voting
         if stake < &T::MinimumStake::get() {
@@ -779,7 +779,7 @@ impl<T: Trait<I>, I: Instance> EnsureChecks<T, I> {
             return Err(Error::InsufficientBalanceToStakeCurrency);
         }
 
-        Ok(account_id)
+        Ok((current_cycle_id, account_id))
     }
 
     fn can_reveal_vote<R: ReferendumManager<T::Origin, T::AccountId, T::Hash>>(
@@ -787,15 +787,11 @@ impl<T: Trait<I>, I: Instance> EnsureChecks<T, I> {
         salt: &[u8],
         vote_option_id: &u64,
     ) -> Result<CanRevealResult<T, I>, Error<T, I>> {
-        let cycle_id = CurrentCycleId::<I>::get();
-
         // ensure superuser requested action
         let account_id = Self::ensure_regular_user(origin)?;
 
-        let stage = Stage::<T, I>::get();
-
         // ensure referendum is running
-        let stage_data = match stage {
+        let stage_data = match Stage::<T, I>::get() {
             ReferendumStage::Revealing(tmp_stage_data) => tmp_stage_data,
             _ => return Err(Error::RevealingNotInProgress),
         };
@@ -808,7 +804,7 @@ impl<T: Trait<I>, I: Instance> EnsureChecks<T, I> {
         }
 
         // ensure vote was cast for the running referendum
-        if cycle_id != cast_vote.cycle_id {
+        if stage_data.current_cycle_id != cast_vote.cycle_id {
             return Err(Error::InvalidVote);
         }
 
@@ -818,7 +814,12 @@ impl<T: Trait<I>, I: Instance> EnsureChecks<T, I> {
         }
 
         // ensure commitment corresponds to salt and vote option
-        let commitment = R::calculate_commitment(&account_id, salt, &cycle_id, vote_option_id);
+        let commitment = R::calculate_commitment(
+            &account_id,
+            salt,
+            &stage_data.current_cycle_id,
+            vote_option_id,
+        );
         if commitment != cast_vote.commitment {
             return Err(Error::InvalidReveal);
         }
@@ -827,20 +828,25 @@ impl<T: Trait<I>, I: Instance> EnsureChecks<T, I> {
     }
 
     fn can_release_vote_stake(origin: T::Origin) -> Result<T::AccountId, Error<T, I>> {
-        let cycle_id = CurrentCycleId::<I>::get();
-
         // ensure superuser requested action
         let account_id = Self::ensure_regular_user(origin)?;
 
         let cast_vote = Self::ensure_vote_exists(&account_id)?;
 
+        // get current cycle id
+        let current_cycle_id = match Stage::<T, I>::get() {
+            ReferendumStage::Voting(stage_data) => Some(stage_data.current_cycle_id),
+            ReferendumStage::Revealing(stage_data) => Some(stage_data.current_cycle_id),
+            _ => None,
+        };
+
         // allow release only for past cycles
-        if cycle_id == cast_vote.cycle_id {
+        if current_cycle_id == Some(cast_vote.cycle_id) {
             return Err(Error::UnstakingVoteInSameCycle);
         }
 
         // ask runtime if stake can be released
-        if !T::can_unlock_vote_stake(&cast_vote, &cycle_id) {
+        if !T::can_unlock_vote_stake(&cast_vote) {
             return Err(Error::UnstakingForbidden);
         }
 

+ 21 - 15
runtime-modules/referendum/src/mock.rs

@@ -2,9 +2,8 @@
 
 /////////////////// Configuration //////////////////////////////////////////////
 use crate::{
-    Balance, CastVote, CurrentCycleId, Error, Instance, Module, OptionResult, RawEvent,
-    ReferendumManager, ReferendumStage, ReferendumStageRevealing, ReferendumStageVoting, Stage,
-    Trait, Votes,
+    Balance, CastVote, Error, Instance, Module, OptionResult, RawEvent, ReferendumManager,
+    ReferendumStage, ReferendumStageRevealing, ReferendumStageVoting, Stage, Trait, Votes,
 };
 
 use frame_support::traits::{Currency, LockIdentifier, OnFinalize};
@@ -91,10 +90,7 @@ impl Trait<Instance0> for Runtime {
         stake
     }
 
-    fn can_unlock_vote_stake(
-        _vote: &CastVote<Self::Hash, Balance<Self, Instance0>>,
-        _current_voting_cycle_id: &u64,
-    ) -> bool {
+    fn can_unlock_vote_stake(_vote: &CastVote<Self::Hash, Balance<Self, Instance0>>) -> bool {
         // trigger fail when requested to do so
         if !IS_UNSTAKE_ENABLED.with(|value| value.borrow().0) {
             return false;
@@ -237,7 +233,6 @@ pub fn default_genesis_config() -> GenesisConfig<Runtime, Instance0> {
     GenesisConfig::<Runtime, Instance0> {
         stage: ReferendumStage::default(),
         votes: vec![],
-        current_cycle_id: 0,
     }
 }
 
@@ -318,8 +313,8 @@ where
     pub fn calculate_commitment(
         account_id: &<T as system::Trait>::AccountId,
         vote_option_index: &u64,
+        cycle_id: &u64,
     ) -> (T::Hash, Vec<u8>) {
-        let cycle_id = CurrentCycleId::<I>::get();
         Self::calculate_commitment_for_cycle(account_id, &cycle_id, vote_option_index, None)
     }
 
@@ -327,8 +322,8 @@ where
         account_id: &<T as system::Trait>::AccountId,
         vote_option_index: &u64,
         custom_salt: &[u8],
+        cycle_id: &u64,
     ) -> (T::Hash, Vec<u8>) {
-        let cycle_id = CurrentCycleId::<I>::get();
         Self::calculate_commitment_for_cycle(
             account_id,
             &cycle_id,
@@ -386,6 +381,7 @@ impl InstanceMocks<Runtime, Instance0> {
     pub fn start_referendum_extrinsic(
         origin: OriginType<<Runtime as system::Trait>::AccountId>,
         winning_target_count: u64,
+        cycle_id: u64,
         expected_result: Result<(), ()>,
     ) -> () {
         let extra_winning_target_count = winning_target_count - 1;
@@ -395,15 +391,17 @@ impl InstanceMocks<Runtime, Instance0> {
             Module::<Runtime, Instance0>::start_referendum(
                 InstanceMockUtils::<Runtime, Instance0>::mock_origin(origin),
                 extra_winning_target_count,
+                cycle_id,
             ),
             expected_result,
         );
 
-        Self::start_referendum_inner(extra_winning_target_count, expected_result)
+        Self::start_referendum_inner(extra_winning_target_count, cycle_id, expected_result)
     }
 
     pub fn start_referendum_manager(
         winning_target_count: u64,
+        cycle_id: u64,
         expected_result: Result<(), ()>,
     ) -> () {
         let extra_winning_target_count = winning_target_count - 1;
@@ -417,15 +415,20 @@ impl InstanceMocks<Runtime, Instance0> {
             >>::start_referendum(
                 InstanceMockUtils::<Runtime, Instance0>::mock_origin(OriginType::Root),
                 extra_winning_target_count,
+                cycle_id,
             )
             .is_ok(),
             expected_result.is_ok(),
         );
 
-        Self::start_referendum_inner(extra_winning_target_count, expected_result)
+        Self::start_referendum_inner(extra_winning_target_count, cycle_id, expected_result)
     }
 
-    fn start_referendum_inner(extra_winning_target_count: u64, expected_result: Result<(), ()>) {
+    fn start_referendum_inner(
+        extra_winning_target_count: u64,
+        cycle_id: u64,
+        expected_result: Result<(), ()>,
+    ) {
         if expected_result.is_err() {
             return;
         }
@@ -438,6 +441,7 @@ impl InstanceMocks<Runtime, Instance0> {
             ReferendumStage::Voting(ReferendumStageVoting {
                 started: block_number + 1, // actual voting starts in the next block (thats why +1)
                 winning_target_count,
+                current_cycle_id: cycle_id,
             }),
         );
 
@@ -449,7 +453,7 @@ impl InstanceMocks<Runtime, Instance0> {
         );
     }
 
-    pub fn check_voting_finished(winning_target_count: u64) {
+    pub fn check_voting_finished(winning_target_count: u64, cycle_id: u64) {
         let block_number = system::Module::<Runtime>::block_number();
 
         assert_eq!(
@@ -458,6 +462,7 @@ impl InstanceMocks<Runtime, Instance0> {
                 started: block_number,
                 winning_target_count,
                 intermediate_winners: vec![],
+                current_cycle_id: cycle_id,
             }),
         );
 
@@ -491,6 +496,7 @@ impl InstanceMocks<Runtime, Instance0> {
         account_id: <Runtime as system::Trait>::AccountId,
         commitment: <Runtime as system::Trait>::Hash,
         stake: Balance<Runtime, Instance0>,
+        cycle_id: u64,
         expected_result: Result<(), Error<Runtime, Instance0>>,
     ) -> () {
         // check method returns expected result
@@ -511,7 +517,7 @@ impl InstanceMocks<Runtime, Instance0> {
             Votes::<Runtime, Instance0>::get(account_id),
             CastVote {
                 commitment,
-                cycle_id: CurrentCycleId::<Instance0>::get(),
+                cycle_id: cycle_id.clone(),
                 stake,
                 vote_for: None,
             },

+ 265 - 65
runtime-modules/referendum/src/tests.rs

@@ -13,8 +13,9 @@ type MockUtils = InstanceMockUtils<Runtime, Instance0>;
 fn referendum_start() {
     MockUtils::origin_access(USER_ADMIN, |origin| {
         let winning_target_count = 1;
+        let cycle_id = 1;
 
-        Mocks::start_referendum_extrinsic(origin, winning_target_count, Ok(()));
+        Mocks::start_referendum_extrinsic(origin, winning_target_count, cycle_id, Ok(()));
     });
 }
 
@@ -25,8 +26,14 @@ fn referendum_start_access_restricted() {
 
     build_test_externalities(config).execute_with(|| {
         let winning_target_count = 1;
+        let cycle_id = 1;
 
-        Mocks::start_referendum_extrinsic(OriginType::None, winning_target_count, Err(()));
+        Mocks::start_referendum_extrinsic(
+            OriginType::None,
+            winning_target_count,
+            cycle_id,
+            Err(()),
+        );
     });
 }
 
@@ -39,9 +46,15 @@ fn referendum_start_forbidden_after_start() {
         let origin = OriginType::Signed(USER_ADMIN);
         let options = 1;
         let winning_target_count = 1;
+        let cycle_id = 1;
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count.clone(), Ok(()));
-        Mocks::start_referendum_extrinsic(origin.clone(), options.clone(), Err(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count.clone(),
+            cycle_id,
+            Ok(()),
+        );
+        Mocks::start_referendum_extrinsic(origin.clone(), options.clone(), cycle_id, Err(()));
     });
 }
 
@@ -55,15 +68,29 @@ fn voting() {
     build_test_externalities(config).execute_with(|| {
         let account_id = USER_ADMIN;
         let origin = OriginType::Signed(account_id);
+        let cycle_id = 1;
 
         let winning_target_count = 1;
         let option_to_vote_for = 0;
         let stake = <Runtime as Trait<Instance0>>::MinimumStake::get();
-        let (commitment, _) = MockUtils::calculate_commitment(&account_id, &option_to_vote_for);
+        let (commitment, _) =
+            MockUtils::calculate_commitment(&account_id, &option_to_vote_for, &cycle_id);
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count, Ok(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count,
+            cycle_id.clone(),
+            Ok(()),
+        );
 
-        Mocks::vote(origin.clone(), account_id, commitment, stake, Ok(()));
+        Mocks::vote(
+            origin.clone(),
+            account_id,
+            commitment,
+            stake,
+            cycle_id.clone(),
+            Ok(()),
+        );
     });
 }
 
@@ -75,11 +102,13 @@ fn voting_referendum_not_running() {
     build_test_externalities(config).execute_with(|| {
         let account_id = USER_ADMIN;
         let origin = OriginType::Signed(account_id);
+        let cycle_id = 1;
 
         let winning_target_count = 1;
         let option_to_vote_for = 0;
         let stake = <Runtime as Trait<Instance0>>::MinimumStake::get();
-        let (commitment, _) = MockUtils::calculate_commitment(&account_id, &option_to_vote_for);
+        let (commitment, _) =
+            MockUtils::calculate_commitment(&account_id, &option_to_vote_for, &cycle_id);
 
         // try to vote before referendum starts
         Mocks::vote(
@@ -87,10 +116,16 @@ fn voting_referendum_not_running() {
             account_id,
             commitment,
             stake,
+            cycle_id.clone(),
             Err(Error::ReferendumNotRunning),
         );
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count, Ok(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count,
+            cycle_id.clone(),
+            Ok(()),
+        );
 
         let voting_stage_duration = <Runtime as Trait<Instance0>>::VoteStageDuration::get();
         MockUtils::increase_block_number(voting_stage_duration + 1);
@@ -101,6 +136,7 @@ fn voting_referendum_not_running() {
             account_id,
             commitment,
             stake,
+            cycle_id.clone(),
             Err(Error::ReferendumNotRunning),
         );
     });
@@ -114,18 +150,26 @@ fn voting_stake_too_low() {
     build_test_externalities(config).execute_with(|| {
         let account_id = USER_ADMIN;
         let origin = OriginType::Signed(account_id);
+        let cycle_id = 1;
 
         let winning_target_count = 1;
         let option_to_vote_for = 0;
         let stake = <Runtime as Trait<Instance0>>::MinimumStake::get() - 1;
-        let (commitment, _) = MockUtils::calculate_commitment(&account_id, &option_to_vote_for);
+        let (commitment, _) =
+            MockUtils::calculate_commitment(&account_id, &option_to_vote_for, &cycle_id);
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count, Ok(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count,
+            cycle_id.clone(),
+            Ok(()),
+        );
         Mocks::vote(
             origin.clone(),
             account_id,
             commitment,
             stake,
+            cycle_id.clone(),
             Err(Error::InsufficientStake),
         );
     });
@@ -139,19 +183,27 @@ fn voting_user_repeated_vote() {
     build_test_externalities(config).execute_with(|| {
         let account_id = USER_ADMIN;
         let origin = OriginType::Signed(account_id);
+        let cycle_id = 1;
 
         let winning_target_count = 1;
         let option_to_vote_for = 0;
         let stake = <Runtime as Trait<Instance0>>::MinimumStake::get();
         let different_stake = stake * 2;
-        let (commitment, _) = MockUtils::calculate_commitment(&account_id, &option_to_vote_for);
+        let (commitment, _) =
+            MockUtils::calculate_commitment(&account_id, &option_to_vote_for, &cycle_id);
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count, Ok(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count,
+            cycle_id.clone(),
+            Ok(()),
+        );
         Mocks::vote(
             origin.clone(),
             account_id,
             commitment,
             stake.clone(),
+            cycle_id.clone(),
             Ok(()),
         );
 
@@ -160,6 +212,7 @@ fn voting_user_repeated_vote() {
             account_id,
             commitment,
             different_stake.clone(),
+            cycle_id.clone(),
             Err(Error::AlreadyVotedThisCycle),
         );
     });
@@ -172,14 +225,20 @@ fn voting_user_repeated_vote() {
 fn finish_voting() {
     MockUtils::origin_access(USER_ADMIN, |origin| {
         let winning_target_count = 1;
+        let cycle_id = 1;
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count, Ok(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count,
+            cycle_id.clone(),
+            Ok(()),
+        );
 
         let voting_stage_duration = <Runtime as Trait<Instance0>>::VoteStageDuration::get();
 
         MockUtils::increase_block_number(voting_stage_duration);
 
-        Mocks::check_voting_finished(winning_target_count);
+        Mocks::check_voting_finished(winning_target_count, cycle_id.clone());
     });
 }
 
@@ -194,17 +253,31 @@ fn reveal() {
         let voting_stage_duration = <Runtime as Trait<Instance0>>::VoteStageDuration::get();
         let account_id = USER_ADMIN;
         let origin = OriginType::Signed(account_id);
+        let cycle_id = 1;
         let winning_target_count = 1;
 
         let option_to_vote_for = 1;
         let stake = <Runtime as Trait<Instance0>>::MinimumStake::get();
-        let (commitment, salt) = MockUtils::calculate_commitment(&account_id, &option_to_vote_for);
+        let (commitment, salt) =
+            MockUtils::calculate_commitment(&account_id, &option_to_vote_for, &cycle_id);
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count.clone(), Ok(()));
-        Mocks::vote(origin.clone(), account_id, commitment, stake, Ok(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count.clone(),
+            cycle_id,
+            Ok(()),
+        );
+        Mocks::vote(
+            origin.clone(),
+            account_id,
+            commitment,
+            stake,
+            cycle_id.clone(),
+            Ok(()),
+        );
         MockUtils::increase_block_number(voting_stage_duration);
 
-        Mocks::check_voting_finished(winning_target_count);
+        Mocks::check_voting_finished(winning_target_count, cycle_id);
         Mocks::reveal_vote(
             origin.clone(),
             account_id,
@@ -225,13 +298,20 @@ fn reveal_reveal_stage_not_running() {
         let reveal_stage_duration = <Runtime as Trait<Instance0>>::RevealStageDuration::get();
         let account_id = USER_ADMIN;
         let origin = OriginType::Signed(account_id);
+        let cycle_id = 1;
         let winning_target_count = 1;
 
         let option_to_vote_for = 1;
         let stake = <Runtime as Trait<Instance0>>::MinimumStake::get();
-        let (commitment, salt) = MockUtils::calculate_commitment(&account_id, &option_to_vote_for);
+        let (commitment, salt) =
+            MockUtils::calculate_commitment(&account_id, &option_to_vote_for, &cycle_id);
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count.clone(), Ok(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count.clone(),
+            cycle_id,
+            Ok(()),
+        );
 
         Mocks::reveal_vote(
             origin.clone(),
@@ -241,10 +321,17 @@ fn reveal_reveal_stage_not_running() {
             Err(Error::RevealingNotInProgress),
         );
 
-        Mocks::vote(origin.clone(), account_id, commitment, stake, Ok(()));
+        Mocks::vote(
+            origin.clone(),
+            account_id,
+            commitment,
+            stake,
+            cycle_id.clone(),
+            Ok(()),
+        );
         MockUtils::increase_block_number(voting_stage_duration);
 
-        Mocks::check_voting_finished(winning_target_count);
+        Mocks::check_voting_finished(winning_target_count, cycle_id);
         MockUtils::increase_block_number(reveal_stage_duration);
         Mocks::check_revealing_finished(vec![], MockUtils::transform_results(vec![]));
 
@@ -268,12 +355,18 @@ fn reveal_no_vote() {
         let reveal_stage_duration = <Runtime as Trait<Instance0>>::RevealStageDuration::get();
         let account_id = USER_ADMIN;
         let origin = OriginType::Signed(account_id);
+        let cycle_id = 1;
         let winning_target_count = 1;
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count.clone(), Ok(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count.clone(),
+            cycle_id,
+            Ok(()),
+        );
         MockUtils::increase_block_number(voting_stage_duration);
 
-        Mocks::check_voting_finished(winning_target_count);
+        Mocks::check_voting_finished(winning_target_count, cycle_id);
         MockUtils::increase_block_number(reveal_stage_duration);
 
         Mocks::check_revealing_finished(vec![], MockUtils::transform_results(vec![]));
@@ -290,6 +383,7 @@ fn reveal_salt_too_long() {
         let voting_stage_duration = <Runtime as Trait<Instance0>>::VoteStageDuration::get();
         let account_id = USER_ADMIN;
         let origin = OriginType::Signed(account_id);
+        let cycle_id = 1;
         let winning_target_count = 1;
 
         let mut salt = vec![];
@@ -299,14 +393,30 @@ fn reveal_salt_too_long() {
 
         let option_to_vote_for = 1;
         let stake = <Runtime as Trait<Instance0>>::MinimumStake::get();
-        let (commitment, _) =
-            MockUtils::calculate_commitment_custom_salt(&account_id, &option_to_vote_for, &salt);
+        let (commitment, _) = MockUtils::calculate_commitment_custom_salt(
+            &account_id,
+            &option_to_vote_for,
+            &salt,
+            &cycle_id,
+        );
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count.clone(), Ok(()));
-        Mocks::vote(origin.clone(), account_id, commitment, stake, Ok(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count.clone(),
+            cycle_id,
+            Ok(()),
+        );
+        Mocks::vote(
+            origin.clone(),
+            account_id,
+            commitment,
+            stake,
+            cycle_id.clone(),
+            Ok(()),
+        );
         MockUtils::increase_block_number(voting_stage_duration);
 
-        Mocks::check_voting_finished(winning_target_count);
+        Mocks::check_voting_finished(winning_target_count, cycle_id);
         Mocks::reveal_vote(
             origin.clone(),
             account_id,
@@ -326,20 +436,34 @@ fn reveal_invalid_vote() {
         let voting_stage_duration = <Runtime as Trait<Instance0>>::VoteStageDuration::get();
         let account_id = USER_ADMIN;
         let origin = OriginType::Signed(account_id);
+        let cycle_id = 1;
         let winning_target_count = 1;
 
         let invalid_option = 1000;
         let option_to_vote_for = 1;
         let stake = <Runtime as Trait<Instance0>>::MinimumStake::get();
-        let (commitment, salt) = MockUtils::calculate_commitment(&account_id, &option_to_vote_for);
+        let (commitment, salt) =
+            MockUtils::calculate_commitment(&account_id, &option_to_vote_for, &cycle_id);
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count.clone(), Ok(()));
-        Mocks::vote(origin.clone(), account_id, commitment, stake, Ok(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count.clone(),
+            cycle_id,
+            Ok(()),
+        );
+        Mocks::vote(
+            origin.clone(),
+            account_id,
+            commitment,
+            stake,
+            cycle_id.clone(),
+            Ok(()),
+        );
         MockUtils::increase_block_number(voting_stage_duration);
 
         Runtime::feature_option_id_valid(false);
 
-        Mocks::check_voting_finished(winning_target_count);
+        Mocks::check_voting_finished(winning_target_count, cycle_id);
         Mocks::reveal_vote(
             origin.clone(),
             account_id,
@@ -359,18 +483,32 @@ fn reveal_invalid_commitment_proof() {
         let voting_stage_duration = <Runtime as Trait<Instance0>>::VoteStageDuration::get();
         let account_id = USER_ADMIN;
         let origin = OriginType::Signed(account_id);
+        let cycle_id = 1;
         let winning_target_count = 1;
 
         let option_to_vote_for = 0;
         let invalid_option = option_to_vote_for + 1;
         let stake = <Runtime as Trait<Instance0>>::MinimumStake::get();
-        let (commitment, salt) = MockUtils::calculate_commitment(&account_id, &option_to_vote_for);
+        let (commitment, salt) =
+            MockUtils::calculate_commitment(&account_id, &option_to_vote_for, &cycle_id);
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count.clone(), Ok(()));
-        Mocks::vote(origin.clone(), account_id, commitment, stake, Ok(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count.clone(),
+            cycle_id,
+            Ok(()),
+        );
+        Mocks::vote(
+            origin.clone(),
+            account_id,
+            commitment,
+            stake,
+            cycle_id.clone(),
+            Ok(()),
+        );
         MockUtils::increase_block_number(voting_stage_duration);
 
-        Mocks::check_voting_finished(winning_target_count);
+        Mocks::check_voting_finished(winning_target_count, cycle_id);
         Mocks::reveal_vote(
             origin.clone(),
             account_id,
@@ -393,17 +531,31 @@ fn finish_revealing_period() {
         let reveal_stage_duration = <Runtime as Trait<Instance0>>::RevealStageDuration::get();
         let account_id = USER_ADMIN;
         let origin = OriginType::Signed(account_id);
+        let cycle_id = 1;
         let winning_target_count = 1;
 
         let option_to_vote_for = 0;
         let stake = <Runtime as Trait<Instance0>>::MinimumStake::get();
-        let (commitment, salt) = MockUtils::calculate_commitment(&account_id, &option_to_vote_for);
+        let (commitment, salt) =
+            MockUtils::calculate_commitment(&account_id, &option_to_vote_for, &cycle_id);
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count.clone(), Ok(()));
-        Mocks::vote(origin.clone(), account_id, commitment, stake, Ok(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count.clone(),
+            cycle_id,
+            Ok(()),
+        );
+        Mocks::vote(
+            origin.clone(),
+            account_id,
+            commitment,
+            stake,
+            cycle_id.clone(),
+            Ok(()),
+        );
         MockUtils::increase_block_number(voting_stage_duration);
 
-        Mocks::check_voting_finished(winning_target_count);
+        Mocks::check_voting_finished(winning_target_count, cycle_id);
         Mocks::reveal_vote(
             origin.clone(),
             account_id,
@@ -437,6 +589,7 @@ fn finish_revealing_period_vote_power() {
         let origin = OriginType::Signed(account_superuser);
         let origin_voter1 = OriginType::Signed(account_id1);
         let origin_voter2 = OriginType::Signed(account_id2);
+        let cycle_id = 1;
         let winning_target_count = 1;
 
         let option_to_vote_for1 = 0;
@@ -444,16 +597,22 @@ fn finish_revealing_period_vote_power() {
         let stake_bigger = <Runtime as Trait<Instance0>>::MinimumStake::get() * 2;
         let stake_smaller = <Runtime as Trait<Instance0>>::MinimumStake::get();
         let (commitment1, salt1) =
-            MockUtils::calculate_commitment(&account_id1, &option_to_vote_for1);
+            MockUtils::calculate_commitment(&account_id1, &option_to_vote_for1, &cycle_id);
         let (commitment2, salt2) =
-            MockUtils::calculate_commitment(&account_id2, &option_to_vote_for2);
+            MockUtils::calculate_commitment(&account_id2, &option_to_vote_for2, &cycle_id);
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count.clone(), Ok(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count.clone(),
+            cycle_id,
+            Ok(()),
+        );
         Mocks::vote(
             origin_voter1.clone(),
             account_id1,
             commitment1,
             stake_bigger,
+            cycle_id.clone(),
             Ok(()),
         ); // vote for first option by regular user
         Mocks::vote(
@@ -461,11 +620,12 @@ fn finish_revealing_period_vote_power() {
             account_id2,
             commitment2,
             stake_smaller,
+            cycle_id.clone(),
             Ok(()),
         ); // vote for second option by prominent user
         MockUtils::increase_block_number(voting_stage_duration);
 
-        Mocks::check_voting_finished(winning_target_count);
+        Mocks::check_voting_finished(winning_target_count, cycle_id);
         Mocks::reveal_vote(
             origin_voter1.clone(),
             account_id1,
@@ -508,11 +668,12 @@ fn winners_no_vote_revealed() {
         let voting_stage_duration = <Runtime as Trait<Instance0>>::VoteStageDuration::get();
         let reveal_stage_duration = <Runtime as Trait<Instance0>>::RevealStageDuration::get();
         let origin = OriginType::Signed(USER_ADMIN);
+        let cycle_id = 1;
         let winning_target_count = 1;
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count, Ok(()));
+        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count, cycle_id, Ok(()));
         MockUtils::increase_block_number(voting_stage_duration);
-        Mocks::check_voting_finished(winning_target_count);
+        Mocks::check_voting_finished(winning_target_count, cycle_id);
         MockUtils::increase_block_number(reveal_stage_duration);
         Mocks::check_revealing_finished(vec![], MockUtils::transform_results(vec![]));
     });
@@ -534,24 +695,31 @@ fn winners_multiple_winners() {
         let origin_voter1 = OriginType::Signed(account_id1);
         let origin_voter2 = OriginType::Signed(account_id2);
         let origin_voter3 = OriginType::Signed(account_id3);
+        let cycle_id = 1;
         let winning_target_count = 2;
 
         let option_to_vote_for1 = 0;
         let option_to_vote_for2 = 1;
         let stake = <Runtime as Trait<Instance0>>::MinimumStake::get();
         let (commitment1, salt1) =
-            MockUtils::calculate_commitment(&account_id1, &option_to_vote_for1);
+            MockUtils::calculate_commitment(&account_id1, &option_to_vote_for1, &cycle_id);
         let (commitment2, salt2) =
-            MockUtils::calculate_commitment(&account_id2, &option_to_vote_for1);
+            MockUtils::calculate_commitment(&account_id2, &option_to_vote_for1, &cycle_id);
         let (commitment3, salt3) =
-            MockUtils::calculate_commitment(&account_id3, &option_to_vote_for2);
+            MockUtils::calculate_commitment(&account_id3, &option_to_vote_for2, &cycle_id);
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count.clone(), Ok(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count.clone(),
+            cycle_id,
+            Ok(()),
+        );
         Mocks::vote(
             origin_voter1.clone(),
             account_id1,
             commitment1,
             stake,
+            cycle_id.clone(),
             Ok(()),
         );
         Mocks::vote(
@@ -559,6 +727,7 @@ fn winners_multiple_winners() {
             account_id2,
             commitment2,
             stake,
+            cycle_id.clone(),
             Ok(()),
         );
         Mocks::vote(
@@ -566,11 +735,12 @@ fn winners_multiple_winners() {
             account_id3,
             commitment3,
             stake,
+            cycle_id.clone(),
             Ok(()),
         );
         MockUtils::increase_block_number(voting_stage_duration);
 
-        Mocks::check_voting_finished(winning_target_count);
+        Mocks::check_voting_finished(winning_target_count, cycle_id);
 
         Mocks::reveal_vote(
             origin_voter1.clone(),
@@ -626,22 +796,29 @@ fn winners_multiple_winners_extra() {
         let origin = OriginType::Signed(account_superuser);
         let origin_voter1 = OriginType::Signed(account_id1);
         let origin_voter2 = OriginType::Signed(account_id2);
+        let cycle_id = 1;
         let winning_target_count = 1;
 
         let option_to_vote_for1 = 0;
         let option_to_vote_for2 = 1;
         let stake = <Runtime as Trait<Instance0>>::MinimumStake::get();
         let (commitment1, salt1) =
-            MockUtils::calculate_commitment(&account_id1, &option_to_vote_for1);
+            MockUtils::calculate_commitment(&account_id1, &option_to_vote_for1, &cycle_id);
         let (commitment2, salt2) =
-            MockUtils::calculate_commitment(&account_id2, &option_to_vote_for2);
+            MockUtils::calculate_commitment(&account_id2, &option_to_vote_for2, &cycle_id);
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count.clone(), Ok(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count.clone(),
+            cycle_id,
+            Ok(()),
+        );
         Mocks::vote(
             origin_voter1.clone(),
             account_id1,
             commitment1,
             stake,
+            cycle_id.clone(),
             Ok(()),
         );
         Mocks::vote(
@@ -649,11 +826,12 @@ fn winners_multiple_winners_extra() {
             account_id2,
             commitment2,
             stake,
+            cycle_id.clone(),
             Ok(()),
         );
         MockUtils::increase_block_number(voting_stage_duration);
 
-        Mocks::check_voting_finished(winning_target_count);
+        Mocks::check_voting_finished(winning_target_count, cycle_id);
         Mocks::reveal_vote(
             origin_voter1.clone(),
             account_id1,
@@ -694,24 +872,31 @@ fn winners_multiple_not_enough() {
         let account_id1 = USER_REGULAR;
         let origin = OriginType::Signed(account_superuser);
         let origin_voter1 = OriginType::Signed(account_id1);
+        let cycle_id = 1;
         let winning_target_count = 3;
 
         let option_to_vote_for = 0;
         let stake = <Runtime as Trait<Instance0>>::MinimumStake::get();
         let (commitment1, salt1) =
-            MockUtils::calculate_commitment(&account_id1, &option_to_vote_for);
+            MockUtils::calculate_commitment(&account_id1, &option_to_vote_for, &cycle_id);
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count.clone(), Ok(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count.clone(),
+            cycle_id,
+            Ok(()),
+        );
         Mocks::vote(
             origin_voter1.clone(),
             account_id1,
             commitment1,
             stake,
+            cycle_id.clone(),
             Ok(()),
         );
         MockUtils::increase_block_number(voting_stage_duration);
 
-        Mocks::check_voting_finished(winning_target_count);
+        Mocks::check_voting_finished(winning_target_count, cycle_id);
         Mocks::reveal_vote(
             origin_voter1.clone(),
             account_id1,
@@ -745,23 +930,32 @@ fn referendum_release_stake() {
         let reveal_stage_duration = <Runtime as Trait<Instance0>>::RevealStageDuration::get();
         let account_id = USER_ADMIN;
         let origin = OriginType::Signed(account_id);
+        let cycle_id1 = 1;
+        let cycle_id2 = 2;
         let winning_target_count = 1;
 
         let option_to_vote_for = 0;
         let stake = <Runtime as Trait<Instance0>>::MinimumStake::get();
-        let (commitment, salt) = MockUtils::calculate_commitment(&account_id, &option_to_vote_for);
+        let (commitment, salt) =
+            MockUtils::calculate_commitment(&account_id, &option_to_vote_for, &cycle_id1);
 
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count.clone(), Ok(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count.clone(),
+            cycle_id1,
+            Ok(()),
+        );
         Mocks::vote(
             origin.clone(),
             account_id,
             commitment,
             stake.clone(),
+            cycle_id1.clone(),
             Ok(()),
         );
         MockUtils::increase_block_number(voting_stage_duration);
 
-        Mocks::check_voting_finished(winning_target_count);
+        Mocks::check_voting_finished(winning_target_count, cycle_id1);
         Mocks::reveal_vote(
             origin.clone(),
             account_id,
@@ -784,7 +978,12 @@ fn referendum_release_stake() {
         Runtime::feature_stack_lock(true);
 
         // since `account_id` voted for the winner, he can unlock stake only after inactive stage ends
-        Mocks::start_referendum_extrinsic(origin.clone(), winning_target_count.clone(), Ok(()));
+        Mocks::start_referendum_extrinsic(
+            origin.clone(),
+            winning_target_count.clone(),
+            cycle_id2,
+            Ok(()),
+        );
 
         Mocks::release_stake(origin.clone(), account_id, Ok(()));
     });
@@ -799,7 +998,8 @@ fn referendum_manager_referendum_start() {
 
     build_test_externalities(config).execute_with(|| {
         let winning_target_count = 1;
+        let cycle_id = 1;
 
-        Mocks::start_referendum_manager(winning_target_count, Ok(()));
+        Mocks::start_referendum_manager(winning_target_count, cycle_id, Ok(()));
     });
 }