pallet-scheduler: Send CallUnavailable event if the call isn't present (#1161)

The event was already send before, but it was done at the wrong
position. The pull request all changes the `execute_dispatch` signature
to highlight that there is only one error type.

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Javier Viola <javier@parity.io>
This commit is contained in:
Bastian Köcher
2023-08-29 22:42:54 +02:00
committed by GitHub
parent 1c7ef1f232
commit 844eda7626
2 changed files with 53 additions and 13 deletions
+39
View File
@@ -1878,3 +1878,42 @@ fn reschedule_named_last_task_removes_agenda() {
assert!(Agenda::<Test>::get(when).len() == 0);
});
}
/// Ensures that an unvailable call sends an event.
#[test]
fn unavailable_call_is_detected() {
use frame_support::traits::schedule::v3::Named;
new_test_ext().execute_with(|| {
let call =
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_parts(10, 0) });
let hash = <Test as frame_system::Config>::Hashing::hash_of(&call);
let len = call.using_encoded(|x| x.len()) as u32;
// Important to use here `Bounded::Lookup` to ensure that we request the hash.
let bound = Bounded::Lookup { hash, len };
let name = [1u8; 32];
// Schedule a call.
let _address = <Scheduler as Named<_, _, _>>::schedule_named(
name,
DispatchTime::At(4),
None,
127,
root(),
bound.clone(),
)
.unwrap();
// Ensure the preimage isn't available
assert!(!Preimage::have(&bound));
// Executes in block 4.
run_to_block(4);
assert_eq!(
System::events().last().unwrap().event,
crate::Event::CallUnavailable { task: (4, 0), id: Some(name) }.into()
);
});
}