From 0cd1242cf32ad7b280ec9b1412e80637f1778093 Mon Sep 17 00:00:00 2001 From: kylezs Date: Wed, 30 Oct 2024 16:05:51 +0100 Subject: [PATCH] chore: rename ElectoralSystemStatus -> ElectionPalletStatus --- .../pallets/cf-elections/src/benchmarking.rs | 16 +++++----- state-chain/pallets/cf-elections/src/lib.rs | 30 +++++++++---------- state-chain/pallets/cf-elections/src/tests.rs | 2 +- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/state-chain/pallets/cf-elections/src/benchmarking.rs b/state-chain/pallets/cf-elections/src/benchmarking.rs index 207b2f6aa6..079ada4f57 100644 --- a/state-chain/pallets/cf-elections/src/benchmarking.rs +++ b/state-chain/pallets/cf-elections/src/benchmarking.rs @@ -124,7 +124,7 @@ mod benchmarks { T::EpochInfo::add_authority_info_for_epoch(epoch, vec![validator_id.clone()]); - Status::::put(ElectoralSystemStatus::Running); + Status::::put(ElectionPalletStatus::Running); #[extrinsic_call] stop_ignoring_my_votes(RawOrigin::Signed(caller)); @@ -141,7 +141,7 @@ mod benchmarks { T::EpochInfo::add_authority_info_for_epoch(epoch, vec![validator_id.clone()]); - Status::::put(ElectoralSystemStatus::Running); + Status::::put(ElectionPalletStatus::Running); assert!( !ContributingAuthorities::::contains_key(validator_id.clone()), @@ -274,7 +274,7 @@ mod benchmarks { assert!(ElectoralUnsynchronisedState::::get().is_some()); assert!(ElectoralUnsynchronisedSettings::::get().is_some()); assert!(ElectoralSettings::::get(NextElectionIdentifier::::get()).is_some()); - assert_eq!(Status::::get(), Some(ElectoralSystemStatus::Running)); + assert_eq!(Status::::get(), Some(ElectionPalletStatus::Running)); } #[benchmark] @@ -403,7 +403,7 @@ mod benchmarks { // Ensure elections are paused assert_eq!( Status::::get(), - Some(ElectoralSystemStatus::Paused { detected_corrupt_storage: false }) + Some(ElectionPalletStatus::Paused { detected_corrupt_storage: false }) ); } @@ -416,7 +416,7 @@ mod benchmarks { .dispatch_bypass_filter(T::EnsureGovernance::try_successful_origin().unwrap())); assert_eq!( Status::::get(), - Some(ElectoralSystemStatus::Paused { detected_corrupt_storage: false }) + Some(ElectionPalletStatus::Paused { detected_corrupt_storage: false }) ); assert_ok!(Call::::clear_all_votes { limit: 100u32, @@ -434,7 +434,7 @@ mod benchmarks { } // Ensure elections are unpaused - assert_eq!(Status::::get(), Some(ElectoralSystemStatus::Running)); + assert_eq!(Status::::get(), Some(ElectionPalletStatus::Running)); } #[benchmark] @@ -444,7 +444,7 @@ mod benchmarks { // Pause the election, and set corrupt storage to `true` assert_ok!(Call::::pause_elections {} .dispatch_bypass_filter(T::EnsureGovernance::try_successful_origin().unwrap())); - Status::::put(ElectoralSystemStatus::Paused { detected_corrupt_storage: true }); + Status::::put(ElectionPalletStatus::Paused { detected_corrupt_storage: true }); let call = Call::::validate_storage {}; @@ -457,7 +457,7 @@ mod benchmarks { assert_eq!( Status::::get(), - Some(ElectoralSystemStatus::Paused { detected_corrupt_storage: false }) + Some(ElectionPalletStatus::Paused { detected_corrupt_storage: false }) ); } diff --git a/state-chain/pallets/cf-elections/src/lib.rs b/state-chain/pallets/cf-elections/src/lib.rs index 2f497525bf..bb8560dd33 100644 --- a/state-chain/pallets/cf-elections/src/lib.rs +++ b/state-chain/pallets/cf-elections/src/lib.rs @@ -285,7 +285,7 @@ pub mod pallet { pub use corrupt_storage_error::CorruptStorageError; #[derive(Debug, PartialEq, Eq, Clone, Encode, Decode, TypeInfo)] - pub enum ElectoralSystemStatus { + pub enum ElectionPalletStatus { Paused { detected_corrupt_storage: bool }, Running, } @@ -578,7 +578,7 @@ pub mod pallet { /// this is None, the pallet is considered uninitialized. #[pallet::storage] pub type Status, I: 'static = ()> = - StorageValue<_, ElectoralSystemStatus, OptionQuery>; + StorageValue<_, ElectionPalletStatus, OptionQuery>; // ---------------------------------------------------------------------------------------- // @@ -1493,9 +1493,9 @@ pub mod pallet { T::EnsureGovernance::ensure_origin(origin)?; match Status::::get() { None => Err(Error::::Uninitialized.into()), - Some(ElectoralSystemStatus::Paused { .. }) => Err(Error::::Paused.into()), + Some(ElectionPalletStatus::Paused { .. }) => Err(Error::::Paused.into()), Some(_) => { - Status::::put(ElectoralSystemStatus::Paused { + Status::::put(ElectionPalletStatus::Paused { detected_corrupt_storage: false, }); Ok(()) @@ -1512,9 +1512,9 @@ pub mod pallet { T::EnsureGovernance::ensure_origin(origin)?; match Status::::get() { None => Err(Error::::Uninitialized.into()), - Some(ElectoralSystemStatus::Paused { detected_corrupt_storage: true }) => + Some(ElectionPalletStatus::Paused { detected_corrupt_storage: true }) => Err(Error::::CorruptStorage.into()), - Some(ElectoralSystemStatus::Paused { .. }) => { + Some(ElectionPalletStatus::Paused { .. }) => { ensure!( !require_votes_cleared || (SharedDataReferenceCount::::iter_keys().next().is_none() && @@ -1526,7 +1526,7 @@ pub mod pallet { .is_none()), Error::::VotesNotCleared ); - Status::::put(ElectoralSystemStatus::Running); + Status::::put(ElectionPalletStatus::Running); Ok(()) }, Some(_) => Err(Error::::NotPaused.into()), @@ -1576,8 +1576,8 @@ pub mod pallet { T::EnsureGovernance::ensure_origin(origin)?; match Status::::get() { None => Err(Error::::Uninitialized.into()), - Some(ElectoralSystemStatus::Paused { .. }) => { - Status::::put(ElectoralSystemStatus::Paused { + Some(ElectionPalletStatus::Paused { .. }) => { + Status::::put(ElectionPalletStatus::Paused { detected_corrupt_storage: false, }); Ok(()) @@ -1594,11 +1594,11 @@ pub mod pallet { fn on_finalize(block_number: BlockNumberFor) { if let Some(status) = Status::::get() { match status { - ElectoralSystemStatus::Paused { detected_corrupt_storage } => + ElectionPalletStatus::Paused { detected_corrupt_storage } => if detected_corrupt_storage { Self::deposit_event(Event::::CorruptStorage); }, - ElectoralSystemStatus::Running => { + ElectionPalletStatus::Running => { let _ = Self::with_electoral_access_and_identifiers( |electoral_access, election_identifiers| { if Into::::into(block_number) % @@ -1685,7 +1685,7 @@ pub mod pallet { NextElectionIdentifier::::get(), initial_state.settings, ); - Status::::put(ElectoralSystemStatus::Running); + Status::::put(ElectionPalletStatus::Running); Ok(()) } @@ -2056,7 +2056,7 @@ pub mod pallet { let authority_index = T::EpochInfo::authority_index(epoch_index, &validator_id); ensure!(authority_index.is_some(), Error::::Unauthorised); ensure!( - matches!(Status::::get(), Some(ElectoralSystemStatus::Running)), + matches!(Status::::get(), Some(ElectionPalletStatus::Running)), Error::::Paused ); Ok((epoch_index, validator_id, authority_index.unwrap())) @@ -2070,7 +2070,7 @@ pub mod pallet { ensure!( !matches!( status, - ElectoralSystemStatus::Paused { detected_corrupt_storage: true } + ElectionPalletStatus::Paused { detected_corrupt_storage: true } ) || matches!(ignore_corrupt_storage, CorruptStorageAdherance::Ignore), Error::::CorruptStorage ); @@ -2096,7 +2096,7 @@ pub mod pallet { Ok(ok) => Ok(ok), Err(_) => { Self::deposit_event(Event::::CorruptStorage); - Status::::put(ElectoralSystemStatus::Paused { + Status::::put(ElectionPalletStatus::Paused { detected_corrupt_storage: true, }); Err(Error::::CorruptStorage) diff --git a/state-chain/pallets/cf-elections/src/tests.rs b/state-chain/pallets/cf-elections/src/tests.rs index b97f23c931..8df579c108 100644 --- a/state-chain/pallets/cf-elections/src/tests.rs +++ b/state-chain/pallets/cf-elections/src/tests.rs @@ -151,7 +151,7 @@ impl ElectoralSystemTestExt for TestRunner { .expect("New election should have an identifier.") .unique_monotonic(); - assert_eq!(Status::::get(), Some(ElectoralSystemStatus::Running)); + assert_eq!(Status::::get(), Some(ElectionPalletStatus::Running)); Pallet::::with_electoral_access(|electoral_access| { electoral_access