rustfmt ghost sudo and fix typos
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
parent
eb3b4f2651
commit
792e70c988
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ghost-sudo"
|
||||
version = "0.0.1"
|
||||
version = "0.0.2"
|
||||
description = "Port of the sudo pallet because of dependencies issue"
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
|
@ -23,7 +23,10 @@ mod benchmarks {
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Signed(caller.clone()), new_sudoer_lookup);
|
||||
|
||||
assert_last_event::<T>(Event::KeyChanged { old: Some(caller), new: new_sudoer });
|
||||
assert_last_event::<T>(Event::KeyChanged {
|
||||
old: Some(caller),
|
||||
new: new_sudoer,
|
||||
});
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
@ -36,7 +39,9 @@ mod benchmarks {
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Signed(caller), Box::new(call));
|
||||
|
||||
assert_last_event::<T>(Event::Sudid { sudo_result: Ok(()) })
|
||||
assert_last_event::<T>(Event::Sudid {
|
||||
sudo_result: Ok(()),
|
||||
})
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
@ -52,7 +57,9 @@ mod benchmarks {
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Signed(caller), who_lookup, Box::new(call));
|
||||
|
||||
assert_last_event::<T>(Event::SudoAsDone { sudo_result: Ok(()) })
|
||||
assert_last_event::<T>(Event::SudoAsDone {
|
||||
sudo_result: Ok(()),
|
||||
})
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
|
@ -78,7 +78,9 @@ pub mod pallet {
|
||||
Self::ensure_sudo(origin)?;
|
||||
|
||||
let res = call.dispatch_bypass_filter(RawOrigin::Root.into());
|
||||
Self::deposit_event(Event::Sudid { sudo_result: res.map(|_| ()).map_err(|e| e.error) });
|
||||
Self::deposit_event(Event::Sudid {
|
||||
sudo_result: res.map(|_| ()).map_err(|e| e.error),
|
||||
});
|
||||
|
||||
Ok(Pays::No.into())
|
||||
}
|
||||
@ -94,7 +96,9 @@ pub mod pallet {
|
||||
let _ = weight;
|
||||
|
||||
let res = call.dispatch_bypass_filter(RawOrigin::Root.into());
|
||||
Self::deposit_event(Event::Sudid { sudo_result: res.map(|_| ()).map_err(|e| e.error) });
|
||||
Self::deposit_event(Event::Sudid {
|
||||
sudo_result: res.map(|_| ()).map_err(|e| e.error),
|
||||
});
|
||||
|
||||
Ok(Pays::No.into())
|
||||
}
|
||||
@ -108,7 +112,10 @@ pub mod pallet {
|
||||
Self::ensure_sudo(origin)?;
|
||||
|
||||
let new = T::Lookup::lookup(new)?;
|
||||
Self::deposit_event(Event::KeyChanged { old: Key::<T>::get(), new: new.clone() });
|
||||
Self::deposit_event(Event::KeyChanged {
|
||||
old: Key::<T>::get(),
|
||||
new: new.clone(),
|
||||
});
|
||||
Key::<T>::put(new);
|
||||
|
||||
Ok(Pays::No.into())
|
||||
@ -161,7 +168,9 @@ pub mod pallet {
|
||||
new: T::AccountId,
|
||||
},
|
||||
KeyRemoved,
|
||||
SudoAsDone { sudo_result: DispatchResult },
|
||||
SudoAsDone {
|
||||
sudo_result: DispatchResult,
|
||||
},
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
|
@ -42,7 +42,11 @@ pub mod logger {
|
||||
let sender = ensure_signed(origin)?;
|
||||
<I32Log<T>>::try_append(i).map_err(|_| "could not append")?;
|
||||
<AccountLog<T>>::try_append(sender.clone()).map_err(|_| "could not append")?;
|
||||
Self::deposit_event(Event::AppendI32AndAccount { sender, value: i, weight });
|
||||
Self::deposit_event(Event::AppendI32AndAccount {
|
||||
sender,
|
||||
value: i,
|
||||
weight,
|
||||
});
|
||||
Ok(().into())
|
||||
}
|
||||
}
|
||||
@ -50,8 +54,15 @@ pub mod logger {
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
AppendI32 { value: i32, weight: Weight },
|
||||
AppendI32AndAccount { sender: T::AccountId, value: i32, weight: Weight },
|
||||
AppendI32 {
|
||||
value: i32,
|
||||
weight: Weight,
|
||||
},
|
||||
AppendI32AndAccount {
|
||||
sender: T::AccountId,
|
||||
value: i32,
|
||||
weight: Weight,
|
||||
},
|
||||
}
|
||||
|
||||
#[pallet::storage]
|
||||
@ -94,8 +105,12 @@ pub type SudoCall = sudo::Call<Test>;
|
||||
pub type LoggerCall = logger::Call<Test>;
|
||||
|
||||
pub fn new_test_ext(root_key: u64) -> sp_io::TestExternalities {
|
||||
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
sudo::GenesisConfig::<Test> { key: Some(root_key) }
|
||||
let mut t = frame_system::GenesisConfig::<Test>::default()
|
||||
.build_storage()
|
||||
.unwrap();
|
||||
sudo::GenesisConfig::<Test> {
|
||||
key: Some(root_key),
|
||||
}
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
let mut ext: sp_io::TestExternalities = t.into();
|
||||
@ -105,5 +120,8 @@ pub fn new_test_ext(root_key: u64) -> sp_io::TestExternalities {
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
pub fn new_bench_ext() -> sp_io::TestExternalities {
|
||||
frame_system::GenesisConfig::<Test>::default().build_storage().unwrap().into()
|
||||
frame_system::GenesisConfig::<Test>::default()
|
||||
.build_storage()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
|
@ -29,7 +29,10 @@ fn sudo_basics() {
|
||||
i: 42,
|
||||
weight: Weight::from_parts(1_000, 0),
|
||||
}));
|
||||
assert_noop!(Sudo::sudo(RuntimeOrigin::signed(2), call), Error::<Test>::RequireSudo);
|
||||
assert_noop!(
|
||||
Sudo::sudo(RuntimeOrigin::signed(2), call),
|
||||
Error::<Test>::RequireSudo
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@ -41,7 +44,9 @@ fn sudo_emits_events_correctly() {
|
||||
weight: Weight::from_parts(1, 0),
|
||||
}));
|
||||
assert_ok!(Sudo::sudo(RuntimeOrigin::signed(1), call));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::Sudid { sudo_result: Ok(()) }));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::Sudid {
|
||||
sudo_result: Ok(()),
|
||||
}));
|
||||
})
|
||||
}
|
||||
|
||||
@ -77,8 +82,10 @@ fn sudo_unchecked_weight_basics() {
|
||||
i: 42,
|
||||
weight: Weight::from_parts(1, 0),
|
||||
}));
|
||||
let sudo_unchecked_weight_call =
|
||||
SudoCall::sudo_unchecked_weight { call, weight: Weight::from_parts(1_000, 0) };
|
||||
let sudo_unchecked_weight_call = SudoCall::sudo_unchecked_weight {
|
||||
call,
|
||||
weight: Weight::from_parts(1_000, 0),
|
||||
};
|
||||
let info = sudo_unchecked_weight_call.get_dispatch_info();
|
||||
assert_eq!(info.weight, Weight::from_parts(1_000, 0));
|
||||
});
|
||||
@ -96,7 +103,9 @@ fn sudo_unchecked_weight_emits_events_correctly() {
|
||||
call,
|
||||
Weight::from_parts(1_000, 0)
|
||||
));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::Sudid { sudo_result: Ok(()) }));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::Sudid {
|
||||
sudo_result: Ok(()),
|
||||
}));
|
||||
})
|
||||
}
|
||||
|
||||
@ -109,7 +118,10 @@ fn set_key_basics() {
|
||||
});
|
||||
|
||||
new_test_ext(1).execute_with(|| {
|
||||
assert_noop!(Sudo::set_key(RuntimeOrigin::signed(2), 3), Error::<Test>::RequireSudo);
|
||||
assert_noop!(
|
||||
Sudo::set_key(RuntimeOrigin::signed(2), 3),
|
||||
Error::<Test>::RequireSudo
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@ -117,9 +129,15 @@ fn set_key_basics() {
|
||||
fn set_key_emits_events_correctly() {
|
||||
new_test_ext(1).execute_with(|| {
|
||||
assert_ok!(Sudo::set_key(RuntimeOrigin::signed(1), 2));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::KeyChanged { old: Some(1), new: 2 }));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::KeyChanged {
|
||||
old: Some(1),
|
||||
new: 2,
|
||||
}));
|
||||
assert_ok!(Sudo::set_key(RuntimeOrigin::signed(2), 4));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::KeyChanged { old: Some(2), new: 4 }));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::KeyChanged {
|
||||
old: Some(2),
|
||||
new: 4,
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
@ -130,8 +148,14 @@ fn remove_key_works() {
|
||||
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);
|
||||
assert_noop!(Sudo::set_key(RuntimeOrigin::signed(1), 1), Error::<Test>::RequireSudo);
|
||||
assert_noop!(
|
||||
Sudo::remove_key(RuntimeOrigin::signed(1)),
|
||||
Error::<Test>::RequireSudo
|
||||
);
|
||||
assert_noop!(
|
||||
Sudo::set_key(RuntimeOrigin::signed(1), 1),
|
||||
Error::<Test>::RequireSudo
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@ -162,7 +186,10 @@ fn sudo_as_basics() {
|
||||
i: 42,
|
||||
weight: Weight::from_parts(1, 0),
|
||||
}));
|
||||
assert_noop!(Sudo::sudo_as(RuntimeOrigin::signed(3), 2, call), Error::<Test>::RequireSudo);
|
||||
assert_noop!(
|
||||
Sudo::sudo_as(RuntimeOrigin::signed(3), 2, call),
|
||||
Error::<Test>::RequireSudo
|
||||
);
|
||||
|
||||
let call = Box::new(RuntimeCall::Logger(LoggerCall::non_privileged_log {
|
||||
i: 42,
|
||||
@ -183,6 +210,8 @@ fn sudo_as_emits_events_correctly() {
|
||||
weight: Weight::from_parts(1, 0),
|
||||
}));
|
||||
assert_ok!(Sudo::sudo_as(RuntimeOrigin::signed(1), 2, call));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::SudoAsDone { sudo_result: Ok(()) }));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::SudoAsDone {
|
||||
sudo_result: Ok(()),
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user