diff --git a/frame/safe-mode/src/mock.rs b/frame/safe-mode/src/mock.rs index d09cee0b8d094..b5eba90f1724c 100644 --- a/frame/safe-mode/src/mock.rs +++ b/frame/safe-mode/src/mock.rs @@ -20,8 +20,8 @@ use super::*; use crate as pallet_safe_mode; -use frame_support::{parameter_types, traits::{InsideBoth, SortedMembers, EitherOfDiverse, Everything}}; -use frame_system::{EnsureRoot, EnsureSignedBy}; +use frame_support::{parameter_types, traits::{InsideBoth, SortedMembers, Everything}}; +use frame_system::EnsureSignedBy; use sp_core::H256; use sp_runtime::{ testing::Header, @@ -132,10 +132,10 @@ impl Config for Test { type SafeModeFilter = MockSafeModeFilter; type EnableDuration = EnableDuration; type ExtendDuration = ExtendDuration; - type EnableOrigin = EitherOfDiverse, EnsureRoot>; // TODO should not need to explicitly define root in addition? - type ExtendOrigin = EitherOfDiverse, EnsureRoot>; // TODO should not need to explicitly define root in addition? - type DisableOrigin = EitherOfDiverse, EnsureRoot>; // TODO should not need to explicitly define root in addition? - type RepayOrigin = EitherOfDiverse, EnsureRoot>; // TODO should not need to explicitly define root in addition? + type EnableOrigin = EnsureSignedBy; + type ExtendOrigin = EnsureSignedBy; + type DisableOrigin = EnsureSignedBy; + type RepayOrigin = EnsureSignedBy; type EnableStakeAmount = EnableStakeAmount; type ExtendStakeAmount = ExtendStakeAmount; } diff --git a/frame/safe-mode/src/tests.rs b/frame/safe-mode/src/tests.rs index 50b729c82ca38..2f6a2e0c03146 100644 --- a/frame/safe-mode/src/tests.rs +++ b/frame/safe-mode/src/tests.rs @@ -66,7 +66,7 @@ fn fails_to_extend_if_not_enabled() { fn can_automatically_disable_after_timeout() { new_test_ext().execute_with(|| { let enabled_at_block = System::block_number(); - assert_ok!(SafeMode::force_enable(Origin::root())); + assert_ok!(SafeMode::force_enable(Origin::signed(mock::EnableOrigin::get()))); run_to(mock::EnableDuration::get() + enabled_at_block + 1); SafeMode::on_initialize(System::block_number()); assert_eq!(SafeMode::enabled(), None); @@ -135,7 +135,7 @@ fn fails_signed_origin_when_explicit_origin_required() { #[test] fn fails_force_disable_if_not_enabled() { new_test_ext().execute_with(|| { - assert_noop!(SafeMode::force_disable(Origin::root()), Error::::IsDisabled); + assert_noop!(SafeMode::force_disable(Origin::signed(mock::DisableOrigin::get())), Error::::IsDisabled); assert_noop!( SafeMode::force_disable(Origin::signed(mock::DisableOrigin::get())), Error::::IsDisabled @@ -250,75 +250,3 @@ fn fails_when_explicit_origin_required() { }); } - -// ROOT ORIGIN CALL TESTS --------------------- - -#[test] -fn can_force_enable_with_root() { - new_test_ext().execute_with(|| { - assert_ok!(SafeMode::force_enable(Origin::root())); - assert_eq!( - SafeMode::enabled().unwrap(), - System::block_number() + mock::EnableDuration::get() - ); - assert_noop!(SafeMode::force_enable(Origin::root()), Error::::IsEnabled); - // assert_eq!(Balances::reserved_balance(Origin::root()), 0); - // TODO: without an explicit account required... can "raw" root ever have a balance reserved? - // If so, check here and below. - }); -} - -#[test] -fn can_force_extend_with_root() { - new_test_ext().execute_with(|| { - assert_ok!(SafeMode::force_enable(Origin::root())); - assert_eq!( - SafeMode::enabled().unwrap(), - System::block_number() + mock::EnableDuration::get() - ); - assert_ok!(SafeMode::force_extend(Origin::root())); - assert_eq!( - SafeMode::enabled().unwrap(), - System::block_number() + mock::EnableDuration::get() + mock::ExtendDuration::get() - ); - }); -} - -#[test] -fn can_force_disable_with_root() { - new_test_ext().execute_with(|| { - assert_eq!(SafeMode::enabled(), None); - assert_err!(SafeMode::force_disable(Origin::root()), Error::::IsDisabled); - assert_ok!(SafeMode::force_enable(Origin::root())); - assert_ok!(SafeMode::force_disable(Origin::root())); - }); -} - -#[test] -fn can_repay_stake_with_root() { - new_test_ext().execute_with(|| { - let enabled_at_block = System::block_number(); - assert_ok!(SafeMode::enable(Origin::signed(0))); - assert_err!( - SafeMode::repay_stake(Origin::root(), 0, enabled_at_block), - Error::::IsEnabled - ); - run_to(mock::EnableDuration::get() + enabled_at_block + 1); - SafeMode::on_initialize(System::block_number()); - assert_ok!(SafeMode::repay_stake(Origin::root(), 0, enabled_at_block)); - }); -} - -#[test] -fn can_slash_stake_with_root() { - new_test_ext().execute_with(|| { - let enabled_at_block = System::block_number(); - assert_ok!(SafeMode::enable(Origin::signed(0))); - assert_err!( - SafeMode::slash_stake(Origin::root(), 0, enabled_at_block), - Error::::IsEnabled - ); - run_to(mock::EnableDuration::get() + enabled_at_block + 1); - assert_ok!(SafeMode::slash_stake(Origin::root(), 0, enabled_at_block)); - }); -}