Simplify operational extrinsics (#810)

* Simplify operational extrinsics

* Remove old extrinsics from finality verifier
This commit is contained in:
Hernando Castano
2021-03-10 09:45:15 -05:00
committed by Bastian Köcher
parent 8f11732bb9
commit 47aa6634a2
2 changed files with 42 additions and 54 deletions
+21 -28
View File
@@ -222,26 +222,19 @@ pub mod pallet {
Ok(().into())
}
/// Halt all pallet operations. Operations may be resumed using `resume_operations` call.
/// Halt or resume all pallet operations.
///
/// May only be called either by root, or by `ModuleOwner`.
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
pub fn halt_operations(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
pub fn set_operational(origin: OriginFor<T>, operational: bool) -> DispatchResultWithPostInfo {
ensure_owner_or_root::<T>(origin)?;
<IsHalted<T>>::put(true);
log::warn!("Stopping pallet operations.");
<IsHalted<T>>::put(operational);
Ok(().into())
}
/// Resume all pallet operations. May be called even if pallet is halted.
///
/// May only be called either by root, or by `ModuleOwner`.
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
pub fn resume_operations(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
ensure_owner_or_root::<T>(origin)?;
<IsHalted<T>>::put(false);
log::info!("Resuming pallet operations.");
if operational {
log::info!("Resuming pallet operations.");
} else {
log::warn!("Stopping pallet operations.");
}
Ok(().into())
}
@@ -655,29 +648,29 @@ mod tests {
assert_ok!(Module::<TestRuntime>::set_owner(Origin::root(), Some(1)));
assert_noop!(
Module::<TestRuntime>::halt_operations(Origin::signed(2)),
Module::<TestRuntime>::set_operational(Origin::signed(2), false),
DispatchError::BadOrigin,
);
assert_ok!(Module::<TestRuntime>::halt_operations(Origin::root()));
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), false));
assert_ok!(Module::<TestRuntime>::set_owner(Origin::signed(1), None));
assert_noop!(
Module::<TestRuntime>::resume_operations(Origin::signed(1)),
Module::<TestRuntime>::set_operational(Origin::signed(1), true),
DispatchError::BadOrigin,
);
assert_noop!(
Module::<TestRuntime>::resume_operations(Origin::signed(2)),
Module::<TestRuntime>::set_operational(Origin::signed(2), true),
DispatchError::BadOrigin,
);
assert_ok!(Module::<TestRuntime>::resume_operations(Origin::root()));
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), true));
});
}
#[test]
fn pallet_may_be_halted_by_root() {
run_test(|| {
assert_ok!(Module::<TestRuntime>::halt_operations(Origin::root()));
assert_ok!(Module::<TestRuntime>::resume_operations(Origin::root()));
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), false));
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), true));
});
}
@@ -686,21 +679,21 @@ mod tests {
run_test(|| {
ModuleOwner::<TestRuntime>::put(2);
assert_ok!(Module::<TestRuntime>::halt_operations(Origin::signed(2)));
assert_ok!(Module::<TestRuntime>::resume_operations(Origin::signed(2)));
assert_ok!(Module::<TestRuntime>::set_operational(Origin::signed(2), false));
assert_ok!(Module::<TestRuntime>::set_operational(Origin::signed(2), true));
assert_noop!(
Module::<TestRuntime>::halt_operations(Origin::signed(1)),
Module::<TestRuntime>::set_operational(Origin::signed(1), false),
DispatchError::BadOrigin,
);
assert_noop!(
Module::<TestRuntime>::resume_operations(Origin::signed(1)),
Module::<TestRuntime>::set_operational(Origin::signed(1), true),
DispatchError::BadOrigin,
);
assert_ok!(Module::<TestRuntime>::halt_operations(Origin::signed(2)));
assert_ok!(Module::<TestRuntime>::set_operational(Origin::signed(2), false));
assert_noop!(
Module::<TestRuntime>::resume_operations(Origin::signed(1)),
Module::<TestRuntime>::set_operational(Origin::signed(1), true),
DispatchError::BadOrigin,
);
});