Skip to content

Commit

Permalink
removed pallet::getter from pallet-sudo (#3370)
Browse files Browse the repository at this point in the history
part of #3326 

@ggwpez @kianenigma @shawntabrizi

---------

Signed-off-by: Matteo Muraca <mmuraca247@gmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
  • Loading branch information
muraca and kianenigma authored Feb 19, 2024
1 parent 197c6cf commit 435e339
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions substrate/frame/sudo/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::{Config, Pallet};
use crate::{Config, Key};
use codec::{Decode, Encode};
use frame_support::{dispatch::DispatchInfo, ensure};
use scale_info::TypeInfo;
Expand Down Expand Up @@ -86,7 +86,7 @@ where
info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
let sudo_key: T::AccountId = <Pallet<T>>::key().ok_or(UnknownTransaction::CannotLookup)?;
let sudo_key: T::AccountId = Key::<T>::get().ok_or(UnknownTransaction::CannotLookup)?;
ensure!(*who == sudo_key, InvalidTransaction::BadSigner);

Ok(ValidTransaction {
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/sudo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ pub mod pallet {

/// The `AccountId` of the sudo key.
#[pallet::storage]
#[pallet::getter(fn key)]
pub(super) type Key<T: Config> = StorageValue<_, T::AccountId, OptionQuery>;

#[pallet::genesis_config]
Expand All @@ -352,7 +351,7 @@ pub mod pallet {
let sender = ensure_signed_or_root(origin)?;

if let Some(sender) = sender {
if Self::key().map_or(false, |k| k == sender) {
if Key::<T>::get().map_or(false, |k| k == sender) {
Ok(())
} else {
Err(Error::<T>::RequireSudo.into())
Expand Down
10 changes: 5 additions & 5 deletions substrate/frame/sudo/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use mock::{
fn test_setup_works() {
// Environment setup, logger storage, and sudo `key` retrieval should work as expected.
new_test_ext(1).execute_with(|| {
assert_eq!(Sudo::key(), Some(1u64));
assert_eq!(Key::<Test>::get(), Some(1u64));
assert!(Logger::i32_log().is_empty());
assert!(Logger::account_log().is_empty());
});
Expand Down Expand Up @@ -135,7 +135,7 @@ fn set_key_basics() {
new_test_ext(1).execute_with(|| {
// A root `key` can change the root `key`
assert_ok!(Sudo::set_key(RuntimeOrigin::signed(1), 2));
assert_eq!(Sudo::key(), Some(2u64));
assert_eq!(Key::<Test>::get(), Some(2u64));
});

new_test_ext(1).execute_with(|| {
Expand All @@ -161,7 +161,7 @@ fn set_key_emits_events_correctly() {
fn remove_key_works() {
new_test_ext(1).execute_with(|| {
assert_ok!(Sudo::remove_key(RuntimeOrigin::signed(1)));
assert!(Sudo::key().is_none());
assert!(Key::<Test>::get().is_none());
System::assert_has_event(TestEvent::Sudo(Event::KeyRemoved {}));

assert_noop!(Sudo::remove_key(RuntimeOrigin::signed(1)), Error::<Test>::RequireSudo);
Expand All @@ -173,11 +173,11 @@ fn remove_key_works() {
fn using_root_origin_works() {
new_test_ext(1).execute_with(|| {
assert_ok!(Sudo::remove_key(RuntimeOrigin::root()));
assert!(Sudo::key().is_none());
assert!(Key::<Test>::get().is_none());
System::assert_has_event(TestEvent::Sudo(Event::KeyRemoved {}));

assert_ok!(Sudo::set_key(RuntimeOrigin::root(), 1));
assert_eq!(Some(1), Sudo::key());
assert_eq!(Some(1), Key::<Test>::get());
});
}

Expand Down

0 comments on commit 435e339

Please sign in to comment.