Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed pallet::getter from pallet-sudo #3370

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)?;
gupnik marked this conversation as resolved.
Show resolved Hide resolved
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
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
Loading